Class: Bootsnap::CLI
- Inherits:
-
Object
- Object
- Bootsnap::CLI
- Defined in:
- lib/bootsnap/cli.rb,
lib/bootsnap/cli/worker_pool.rb
Defined Under Namespace
Modules: RegexpMatchBackport Classes: WorkerPool
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#cache_dir ⇒ Object
readonly
Returns the value of attribute cache_dir.
-
#compile_gemfile ⇒ Object
Returns the value of attribute compile_gemfile.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#iseq ⇒ Object
Returns the value of attribute iseq.
-
#jobs ⇒ Object
Returns the value of attribute jobs.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#yaml ⇒ Object
Returns the value of attribute yaml.
Instance Method Summary collapse
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #list_files(path, pattern) ⇒ Object
- #precompile_command(*sources) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bootsnap/cli.rb', line 26 def initialize(argv) @argv = argv self.cache_dir = ENV.fetch('BOOTSNAP_CACHE_DIR', 'tmp/cache') self.compile_gemfile = false self.exclude = nil self.verbose = false self.jobs = Etc.nprocessors self.iseq = true self.yaml = true end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
22 23 24 |
# File 'lib/bootsnap/cli.rb', line 22 def argv @argv end |
#cache_dir ⇒ Object
Returns the value of attribute cache_dir.
22 23 24 |
# File 'lib/bootsnap/cli.rb', line 22 def cache_dir @cache_dir end |
#compile_gemfile ⇒ Object
Returns the value of attribute compile_gemfile.
24 25 26 |
# File 'lib/bootsnap/cli.rb', line 24 def compile_gemfile @compile_gemfile end |
#exclude ⇒ Object
Returns the value of attribute exclude.
24 25 26 |
# File 'lib/bootsnap/cli.rb', line 24 def exclude @exclude end |
#iseq ⇒ Object
Returns the value of attribute iseq.
24 25 26 |
# File 'lib/bootsnap/cli.rb', line 24 def iseq @iseq end |
#jobs ⇒ Object
Returns the value of attribute jobs.
24 25 26 |
# File 'lib/bootsnap/cli.rb', line 24 def jobs @jobs end |
#verbose ⇒ Object
Returns the value of attribute verbose.
24 25 26 |
# File 'lib/bootsnap/cli.rb', line 24 def verbose @verbose end |
#yaml ⇒ Object
Returns the value of attribute yaml.
24 25 26 |
# File 'lib/bootsnap/cli.rb', line 24 def yaml @yaml end |
Instance Method Details
#list_files(path, pattern) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/bootsnap/cli.rb', line 83 def list_files(path, pattern) if File.directory?(path) Dir[File.join(path, pattern), sort: false] elsif File.exist?(path) [path] else [] end end |
#precompile_command(*sources) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/bootsnap/cli.rb', line 37 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.(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.(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/)?gem\/[^/]+} 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 |
#run ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/bootsnap/cli.rb', line 104 def run parser.parse!(argv) command = argv.shift method = "#{command}_command" if respond_to?(method) public_send(method, *argv) else invalid_usage!("Unknown command: #{command}") end end |