module Bootsnap

def default_setup

def default_setup
  env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || ENV["ENV"]
  development_mode = ["", nil, "development"].include?(env)
  unless ENV["DISABLE_BOOTSNAP"]
    cache_dir = ENV["BOOTSNAP_CACHE_DIR"]
    unless cache_dir
      config_dir_frame = caller.detect do |line|
        line.include?("/config/")
      end
      unless config_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")
      end
      path = config_dir_frame.split(/:\d+:/).first
      path = File.dirname(path) until File.basename(path) == "config"
      app_root = File.dirname(path)
      cache_dir = File.join(app_root, "tmp", "cache")
    end
    setup(
      cache_dir: cache_dir,
      development_mode: development_mode,
      load_path_cache: !ENV["DISABLE_BOOTSNAP_LOAD_PATH_CACHE"],
      compile_cache_iseq: !ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"] && iseq_cache_supported?,
      compile_cache_yaml: !ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"],
      compile_cache_json: !ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"],
    )
    if ENV["BOOTSNAP_LOG"]
      log!
    end
  end
end