Class: Rpremote::Builder
- Inherits:
-
Object
- Object
- Rpremote::Builder
- Defined in:
- lib/rpremote/builder.rb,
sig/rpremote.rbs
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #build(output: $stdout, error: $stderr, **options) ⇒ Object
- #clean(output: $stdout) ⇒ void
-
#initialize(root: Dir.pwd, runner: nil, mrbgems_class: Mrbgems, source_patcher: nil) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(root: Dir.pwd, runner: nil, mrbgems_class: Mrbgems, source_patcher: nil) ⇒ Builder
Returns a new instance of Builder.
13 14 15 16 17 18 |
# File 'lib/rpremote/builder.rb', line 13 def initialize(root: Dir.pwd, runner: nil, mrbgems_class: Mrbgems, source_patcher: nil) @root = File.(root) @runner = runner || method(:run_command) @mrbgems_class = mrbgems_class @source_patcher = source_patcher || method(:patch_source) end |
Instance Method Details
#build(output: $stdout, error: $stderr, **options) ⇒ Object
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 |
# File 'lib/rpremote/builder.rb', line 20 def build(output: $stdout, error: $stderr, **) target = Target.new(**.slice(:language, :language_version, :board, :cache_dir, :firmware)) script = File.("../../tasks/firmware_build.rb", __dir__) raise Error, "rpremote installation has no firmware build script: #{script}" unless File.file?(script) Language.validate!(target.language) source_dir = source_for(target) source_patcher.call(source_dir, target.language_version) environment = { "RPREMOTE_LANGUAGE" => target.language, "RPREMOTE_LANGUAGE_VERSION" => target.language_version, "RPREMOTE_BOARD" => target.board, "RPREMOTE_ROOT" => root, "PICORUBY_DIR" => source_dir } = .merge( language: target.language, language_version: target.language_version, board: target.board ) add_mrbgems_environment!(environment, , source_dir, output) environment["RPREMOTE_FIRMWARE"] = target.firmware_path(root: root) success = runner.call( environment, RbConfig.ruby, script, chdir: root, out: output, err: error ) raise Error, "custom firmware build failed" unless success end |
#clean(output: $stdout) ⇒ void
This method returns an undefined value.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rpremote/builder.rb', line 54 def clean(output: $stdout) directory = File.join(root, "build") unless File.directory?(directory) output.puts("no build files: #{directory}") return end FileUtils.rm_rf(directory) output.puts("removed build files: #{directory}") end |