| 
									
										
										
										
											2024-09-04 02:35:40 +01:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2021-01-21 12:34:04 +00:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-19 16:08:05 +01:00
										 |  |  | homebrew_bootsnap_enabled = HOMEBREW_USING_PORTABLE_RUBY && | 
					
						
							|  |  |  |                             ENV["HOMEBREW_NO_BOOTSNAP"].nil? && | 
					
						
							|  |  |  |                             !ENV["HOMEBREW_BOOTSNAP"].nil? | 
					
						
							| 
									
										
										
										
											2021-02-24 16:49:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-04 02:35:40 +01:00
										 |  |  | module Homebrew | 
					
						
							|  |  |  |   def self.bootsnap_key | 
					
						
							|  |  |  |     @bootsnap_key ||= begin | 
					
						
							|  |  |  |       require "digest/sha2" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       checksum = Digest::SHA256.new | 
					
						
							| 
									
										
										
										
											2024-09-04 14:54:15 +01:00
										 |  |  |       checksum << RUBY_VERSION | 
					
						
							|  |  |  |       checksum << RUBY_PLATFORM | 
					
						
							|  |  |  |       checksum << Dir.children(File.join(Gem.paths.path, "gems")).join(",") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       checksum.hexdigest | 
					
						
							| 
									
										
										
										
											2024-09-04 02:35:40 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-25 15:59:17 +00:00
										 |  |  | if homebrew_bootsnap_enabled | 
					
						
							| 
									
										
										
										
											2024-06-19 16:08:05 +01:00
										 |  |  |   require "bootsnap" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cache = ENV.fetch("HOMEBREW_CACHE", nil) || ENV.fetch("HOMEBREW_DEFAULT_CACHE", nil) | 
					
						
							|  |  |  |   raise "Needs HOMEBREW_CACHE or HOMEBREW_DEFAULT_CACHE!" if cache.nil? || cache.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-04 02:35:40 +01:00
										 |  |  |   cache = File.join(cache, "bootsnap", Homebrew.bootsnap_key) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-19 16:08:05 +01:00
										 |  |  |   # We never do `require "vendor/bundle/ruby/..."` or `require "vendor/portable-ruby/..."`, | 
					
						
							|  |  |  |   # so let's slim the cache a bit by excluding them. | 
					
						
							|  |  |  |   # Note that gems within `bundle/ruby` will still be cached - these are when directory walking down from above. | 
					
						
							|  |  |  |   ignore_directories = [ | 
					
						
							|  |  |  |     (HOMEBREW_LIBRARY_PATH/"vendor/bundle/ruby").to_s, | 
					
						
							|  |  |  |     (HOMEBREW_LIBRARY_PATH/"vendor/portable-ruby").to_s, | 
					
						
							|  |  |  |   ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Bootsnap.setup( | 
					
						
							|  |  |  |     cache_dir:          cache, | 
					
						
							|  |  |  |     ignore_directories:, | 
					
						
							|  |  |  |     load_path_cache:    true, | 
					
						
							|  |  |  |     compile_cache_iseq: true, | 
					
						
							|  |  |  |     compile_cache_yaml: true, | 
					
						
							|  |  |  |   ) | 
					
						
							| 
									
										
										
										
											2021-02-02 11:50:44 +00:00
										 |  |  | end |