Class: Rpremote::DeployCommand
- Inherits:
-
Object
- Object
- Rpremote::DeployCommand
- Defined in:
- lib/rpremote/deploy_command.rb,
sig/rpremote.rbs
Defined Under Namespace
Classes: Error
Constant Summary collapse
- SHELL_READY_TIMEOUT =
2.0- RETRY_INTERVAL =
0.25
Class Method Summary collapse
-
.run(args, defaults:, output: $stdout, error: $stderr, services: {}) ⇒ Object
The command intentionally keeps the six deployment stages visible in execution order.
Class Method Details
.run(args, defaults:, output: $stdout, error: $stderr, services: {}) ⇒ Object
The command intentionally keeps the six deployment stages visible in execution order. rubocop:disable Metrics/AbcSize, Metrics/MethodLength
16 17 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 |
# File 'lib/rpremote/deploy_command.rb', line 16 def self.run(args, defaults:, output: $stdout, error: $stderr, services: {}) = (args, defaults) raise ArgumentError, "usage: rpremote deploy PATH [options]" unless args.length == 1 project = File.(args.first) library, remote_library, source = project_files(project) Language.validate!([:language]) builder = services.fetch(:builder) { Builder.new } flasher = services.fetch(:flasher, Flasher) serial = services.fetch(:serial, Serial) device = services.fetch(:device, Device) runner = services.fetch(:runner, Runner) = .slice(:language, :language_version, :board, :cache_dir, :firmware) firmware_path = Target.new(**).firmware_path(root: Dir.pwd) output.puts("deploy build: #{firmware_path}") builder.build( **, mrbgems: [:mrbgems], output: output, error: error ) flash_service = flasher.new(timeout: [:timeout]) bootsel_mount = resolve_bootsel_mount(, flash_service, output, services) mount = [:mount] || "an automatically detected RP2350 BOOTSEL volume" output.puts("deploy flash: #{firmware_path} to #{mount}; this replaces persistent board firmware") result = flash_service.flash( firmware_path, mount: bootsel_mount, port: [:port] ) = .merge(port: result.port) output.puts("deploy connect: waiting for R2P2 Shell on #{result.port}") wait_for_shell( port: result.port, baud: [:baud], timeout: [:timeout], serial: serial, shell: services.fetch(:shell, Shell), sleeper: services.fetch(:sleeper) { ->(seconds) { sleep(seconds) } }, clock: services.fetch(:clock) { -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) } } ) output.puts("deploy connect: ready on #{result.port}") if File.directory?(library) output.puts("deploy push: #{library} -> :#{remote_library}") recursive_copy = services.fetch(:recursive_copy) do RecursiveCopy.new(output: output, serial: serial, device: device) end recursive_copy.call(library, ":#{remote_library}", ) else output.puts("deploy push: skipped; directory not found: #{library}") end output.puts("deploy run: #{source} on #{result.port}") source_data = prepend_mrbgem_requires(File.binread(source), [:mrbgems]) run_output = serial.open(result.port, baud: [:baud]) do |port| runner.new(port, timeout: [:timeout]).run( source_data, output: output, cleanup: false, remote_path: Runner::DEPLOY_REMOTE_PATH ) end output.puts("deploy run: completed; output bytes: #{run_output.to_s.bytesize}") rescue Errno::ENOENT => e raise ArgumentError, e. end |