Class: RubyWasm::BuildExecutor
- Inherits:
-
Object
- Object
- RubyWasm::BuildExecutor
- Defined in:
- lib/ruby_wasm/build/executor.rb
Overview
Build executor to run the actual build commands.
Instance Attribute Summary collapse
-
#process_count ⇒ Object
readonly
Returns the value of attribute process_count.
Instance Method Summary collapse
- #begin_section(klass, name, note) ⇒ Object
- #cp_r(src, dest) ⇒ Object
- #end_section(klass, name) ⇒ Object
-
#initialize(verbose: false, process_count: nil) ⇒ BuildExecutor
constructor
A new instance of BuildExecutor.
- #ln_s(src, dest) ⇒ Object
- #mkdir_p(list) ⇒ Object
- #mv(src, dest) ⇒ Object
- #rm_f(list) ⇒ Object
- #rm_rf(list) ⇒ Object
- #system(*args, chdir: nil, env: nil) ⇒ Object
- #write(path, data) ⇒ Object
Constructor Details
#initialize(verbose: false, process_count: nil) ⇒ BuildExecutor
Returns a new instance of BuildExecutor.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ruby_wasm/build/executor.rb', line 6 def initialize(verbose: false, process_count: nil) @verbose = verbose @github_actions_markup = ENV["ENABLE_GITHUB_ACTIONS_MARKUP"] != nil __skip__ = begin require "etc" @process_count = process_count || Etc.nprocessors rescue LoadError @process_count = process_count || 1 end end |
Instance Attribute Details
#process_count ⇒ Object (readonly)
Returns the value of attribute process_count.
4 5 6 |
# File 'lib/ruby_wasm/build/executor.rb', line 4 def process_count @process_count end |
Instance Method Details
#begin_section(klass, name, note) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ruby_wasm/build/executor.rb', line 90 def begin_section(klass, name, note) = "\e[1;36m==>\e[0m \e[1m#{klass}(#{name}) -- #{note}\e[0m" if @github_actions_markup puts "::group::#{}" else puts end # Record the start time @start_times ||= Hash.new @start_times[[klass, name]] = Time.now $stdout.flush end |
#cp_r(src, dest) ⇒ Object
119 120 121 |
# File 'lib/ruby_wasm/build/executor.rb', line 119 def cp_r(src, dest) FileUtils.cp_r(src, dest) end |
#end_section(klass, name) ⇒ Object
105 106 107 108 109 |
# File 'lib/ruby_wasm/build/executor.rb', line 105 def end_section(klass, name) took = Time.now - @start_times[[klass, name]] puts "::endgroup::" if @github_actions_markup puts "\e[1;36m==>\e[0m \e[1m#{klass}(#{name}) -- done in #{took.round(2)}s\e[0m" end |
#ln_s(src, dest) ⇒ Object
131 132 133 |
# File 'lib/ruby_wasm/build/executor.rb', line 131 def ln_s(src, dest) FileUtils.ln_s(src, dest) end |
#mkdir_p(list) ⇒ Object
127 128 129 |
# File 'lib/ruby_wasm/build/executor.rb', line 127 def mkdir_p(list) FileUtils.mkdir_p(list) end |
#mv(src, dest) ⇒ Object
123 124 125 |
# File 'lib/ruby_wasm/build/executor.rb', line 123 def mv(src, dest) FileUtils.mv(src, dest) end |
#rm_f(list) ⇒ Object
115 116 117 |
# File 'lib/ruby_wasm/build/executor.rb', line 115 def rm_f(list) FileUtils.rm_f(list) end |
#rm_rf(list) ⇒ Object
111 112 113 |
# File 'lib/ruby_wasm/build/executor.rb', line 111 def rm_rf(list) FileUtils.rm_rf(list) end |
#system(*args, chdir: nil, env: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ruby_wasm/build/executor.rb', line 18 def system(*args, chdir: nil, env: nil) require "open3" _print_command(args, env) # @type var kwargs: Hash[Symbol, untyped] kwargs = {} kwargs[:chdir] = chdir if chdir args = args.to_a.map(&:to_s) # TODO: Remove __skip__ once we have open3 RBS definitions. __skip__ = if @verbose || !$stdout.tty? kwargs[:exception] = true if env Kernel.system(env, *args, **kwargs) else Kernel.system(*args, **kwargs) end else printer = StatusPrinter.new block = proc do |stdin, stdout, stderr, wait_thr| mux = Mutex.new out = String.new err = String.new readers = [ [stdout, :stdout, out], [stderr, :stderr, err] ].map do |io, name, str| reader = Thread.new do while (line = io.gets) mux.synchronize do printer.send(name, line) str << line end end end reader.report_on_exception = false reader end readers.each(&:join) [out, err, wait_thr.value] end begin stdout, stderr, status = if env Open3.popen3(env, *args, **kwargs, &block) else Open3.popen3(*args, **kwargs, &block) end unless status.success? $stderr.puts stdout $stderr.puts stderr cmd_to_print = args.map { |a| "'#{a}'" }.join(" ") raise "Command failed with status (#{status.exitstatus}): #{cmd_to_print}" end ensure printer.done end end return rescue => e $stdout.flush $stderr.puts "Try running with `rake --verbose` for more complete output." raise e end |
#write(path, data) ⇒ Object
135 136 137 |
# File 'lib/ruby_wasm/build/executor.rb', line 135 def write(path, data) File.write(path, data) end |