class Bootsnap::CLI
def precompile_command(*sources)
def precompile_command(*sources) require "bootsnap/compile_cache/iseq" require "bootsnap/compile_cache/yaml" require "bootsnap/compile_cache/json" fix_default_encoding do Bootsnap::CompileCache::ISeq.cache_dir = cache_dir Bootsnap::CompileCache::YAML.init! Bootsnap::CompileCache::YAML.cache_dir = cache_dir Bootsnap::CompileCache::JSON.init! Bootsnap::CompileCache::JSON.cache_dir = cache_dir @work_pool = WorkerPool.create(size: jobs, jobs: { ruby: method(:precompile_ruby), yaml: method(:precompile_yaml), json: method(:precompile_json), }) @work_pool.spawn main_sources = sources.map { |d| File.expand_path(d) } precompile_ruby_files(main_sources) precompile_yaml_files(main_sources) precompile_json_files(main_sources) if compile_gemfile # Some gems embed their tests, they're very unlikely to be loaded, so not worth precompiling. gem_exclude = Regexp.union([exclude, "/spec/", "/test/"].compact) precompile_ruby_files($LOAD_PATH.map { |d| File.expand_path(d) }, exclude: gem_exclude) # Gems that include JSON or YAML files usually don't put them in `lib/`. # So we look at the gem root. gem_pattern = %r{^#{Regexp.escape(Bundler.bundle_path.to_s)}/?(?:bundler/)?gems\/[^/]+} gem_paths = $LOAD_PATH.map { |p| p[gem_pattern] }.compact.uniq precompile_yaml_files(gem_paths, exclude: gem_exclude) precompile_json_files(gem_paths, exclude: gem_exclude) end if (exitstatus = @work_pool.shutdown) exit(exitstatus) end end 0 end