# frozen_string_literal: truerequire_relative"bootsnap/version"require_relative"bootsnap/bundler"moduleBootsnapInvalidConfiguration=Class.new(StandardError)class<<selfattr_reader:cache_dir,:loggerdeflog_stats!stats={hit: 0,revalidated: 0,miss: 0,stale: 0}self.instrumentation=->(event,_path){stats[event]+=1}Kernel.at_exitdostats.eachdo|event,count|$stderr.puts"bootsnap #{event}: #{count}"endendenddeflog!self.logger=$stderr.method(:puts)enddeflogger=(logger)@logger=loggerself.instrumentation=iflogger.respond_to?(:debug)->(event,path){@logger.debug("[Bootsnap] #{event}#{path}")unlessevent==:hit}else->(event,path){@logger.call("[Bootsnap] #{event}#{path}")unlessevent==:hit}endenddefinstrumentation=(callback)@instrumentation=callbackifrespond_to?(:instrumentation_enabled=,true)self.instrumentation_enabled=!!callbackendenddef_instrument(event,path)@instrumentation.call(event,path)enddefsetup(cache_dir:,development_mode: true,load_path_cache: true,ignore_directories: nil,readonly: false,revalidation: false,compile_cache_iseq: true,compile_cache_yaml: true,compile_cache_json: (compile_cache_json_unset=true))unlesscompile_cache_json_unsetwarn("Bootsnap.setup `compile_cache_json` argument is deprecated and has no effect")end@cache_dir="#{cache_dir}/bootsnap"ifload_path_cacheBootsnap::LoadPathCache.setup(cache_path: "#{@cache_dir}/load-path-cache",development_mode: development_mode,ignore_directories: ignore_directories,readonly: readonly,)endBootsnap::CompileCache.setup(cache_dir: "#{@cache_dir}/compile-cache",iseq: compile_cache_iseq,yaml: compile_cache_yaml,readonly: readonly,revalidation: revalidation,)enddefunload_cache!LoadPathCache.unload!enddefdefault_setupenv=ENV["RAILS_ENV"]||ENV["RACK_ENV"]||ENV["ENV"]development_mode=["",nil,"development"].include?(env)ifenabled?("BOOTSNAP")cache_dir=ENV["BOOTSNAP_CACHE_DIR"]unlesscache_dirconfig_dir_frame=caller.detectdo|line|line.include?("/config/")endunlessconfig_dir_frame$stderr.puts("[bootsnap/setup] couldn't infer cache directory! Either:")$stderr.puts("[bootsnap/setup] 1. require bootsnap/setup from your application's config directory; or")$stderr.puts("[bootsnap/setup] 2. Define the environment variable BOOTSNAP_CACHE_DIR")raise("couldn't infer bootsnap cache directory")endpath=config_dir_frame.split(/:\d+:/).firstpath=File.dirname(path)untilFile.basename(path)=="config"app_root=File.dirname(path)cache_dir=File.join(app_root,"tmp","cache")endignore_directories=ifENV.key?("BOOTSNAP_IGNORE_DIRECTORIES")ENV["BOOTSNAP_IGNORE_DIRECTORIES"].split(",")endsetup(cache_dir: cache_dir,development_mode: development_mode,load_path_cache: enabled?("BOOTSNAP_LOAD_PATH_CACHE"),compile_cache_iseq: enabled?("BOOTSNAP_COMPILE_CACHE"),compile_cache_yaml: enabled?("BOOTSNAP_COMPILE_CACHE"),readonly: bool_env("BOOTSNAP_READONLY"),revalidation: bool_env("BOOTSNAP_REVALIDATE"),ignore_directories: ignore_directories,)ifENV["BOOTSNAP_LOG"]log!elsifENV["BOOTSNAP_STATS"]log_stats!endendendifRbConfig::CONFIG["host_os"]=~/mswin|mingw|cygwin/defabsolute_path?(path)path[1]==":"endelsedefabsolute_path?(path)path.start_with?("/")endend# This is a semi-accurate ruby implementation of the native `rb_get_path(VALUE)` function.# The native version is very intricate and may behave differently on windows etc.# But we only use it for non-MRI platform.defrb_get_path(fname)path_path=fname.respond_to?(:to_path)?fname.to_path:fnameString.try_convert(path_path)||raise(TypeError,"no implicit conversion of #{path_path.class} into String")end# Allow the C extension to redefine `rb_get_path` without warning.alias_method:rb_get_path,:rb_get_pathprivatedefenabled?(key)!ENV["DISABLE_#{key}"]enddefbool_env(key,default: false)value=ENV.fetch(key){default}!["0","false",false].include?(value)endendendrequire_relative"bootsnap/compile_cache"require_relative"bootsnap/load_path_cache"