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.
-
#json ⇒ Object
Returns the value of attribute json.
-
#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 36 |
# 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 self.json = 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 |
#json ⇒ Object
Returns the value of attribute json.
24 25 26 |
# File 'lib/bootsnap/cli.rb', line 24 def json @json 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
92 93 94 95 96 97 98 99 100 |
# File 'lib/bootsnap/cli.rb', line 92 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
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 74 75 76 77 78 79 80 81 82 |
# File 'lib/bootsnap/cli.rb', line 38 def precompile_command(*sources) require "bootsnap/compile_cache" fix_default_encoding do Bootsnap::CompileCache.setup( cache_dir: cache_dir, iseq: iseq, yaml: yaml, json: json, revalidation: true, ) @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.(d) } precompile_ruby_files(main_sources) precompile_yaml_files(main_sources) precompile_json_files(main_sources) if compile_gemfile # Gems that include JSON or YAML files usually don't put them in `lib/`. # So we look at the gem root. # Similarly, gems that include Rails engines generally file Ruby files in `app/`. # However some gems embed their tests, they're very unlikely to be loaded, so not worth precompiling. gem_exclude = Regexp.union([exclude, "/spec/", "/test/", "/features/"].compact) gem_pattern = %r{^#{Regexp.escape(Bundler.bundle_path.to_s)}/?(?:bundler/)?gems/[^/]+} gem_paths = $LOAD_PATH.map { |p| p[gem_pattern] || p }.uniq precompile_ruby_files(gem_paths, exclude: gem_exclude) 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 |
#run ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/bootsnap/cli.rb', line 113 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 |