class Bootsnap::CLI
def precompile_command(*sources)
def precompile_command(*sources) require 'bootsnap/compile_cache/iseq' require 'bootsnap/compile_cache/yaml' fix_default_encoding do Bootsnap::CompileCache::ISeq.cache_dir = self.cache_dir Bootsnap::CompileCache::YAML.init! Bootsnap::CompileCache::YAML.cache_dir = self.cache_dir @work_pool = WorkerPool.create(size: jobs, jobs: { ruby: method(:precompile_ruby), yaml: method(:precompile_yaml), }) @work_pool.spawn main_sources = sources.map { |d| File.expand_path(d) } precompile_ruby_files(main_sources) precompile_yaml_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 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) end if exitstatus = @work_pool.shutdown exit(exitstatus) end end 0 end