Module: Plushie::CargoPlushie
- Defined in:
- lib/plushie/cargo_plushie.rb
Overview
Resolves the command that invokes cargo-plushie.
The native widget build pipeline shells out to cargo-plushie to
generate the renderer workspace and drive cargo build. This
module decides how that shell-out happens:
- If +PLUSHIE_RUST_SOURCE_PATH+ points at a plushie-rust checkout, run the workspace copy with +cargo run -p cargo-plushie+. This is the dev path (no install required, always matches the checkout).
- Otherwise, if a +cargo-plushie+ binary is on +PATH+ and its +--version+ matches +PLUSHIE_RUST_VERSION+, use it directly.
- Otherwise, raise with guidance on how to install the matching version.
Class Method Summary collapse
-
.check_path_version ⇒ :match, ...
Probe +cargo-plushie --version+ and compare against +PLUSHIE_RUST_VERSION+.
-
.extract_version(output) ⇒ String?
Pull the version token out of a +cargo-plushie --version+ line.
- .mismatch_message ⇒ String
- .missing_message ⇒ String
-
.resolve ⇒ Array(String, Array<String>)
Resolve an executable command for invoking cargo-plushie.
- .resolve_via_source(source) ⇒ Array(String, Array<String>)
-
.source_path ⇒ String?
Exposed for testing.
Class Method Details
.check_path_version ⇒ :match, ...
Probe +cargo-plushie --version+ and compare against +PLUSHIE_RUST_VERSION+.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/plushie/cargo_plushie.rb', line 68 def check_path_version stdout, _stderr, status = Open3.capture3("cargo-plushie", "--version") rescue Errno::ENOENT :missing else return :missing unless status.success? installed = extract_version(stdout) return :missing unless installed (installed == Plushie::PLUSHIE_RUST_VERSION) ? :match : :mismatch end |
.extract_version(output) ⇒ String?
Pull the version token out of a +cargo-plushie --version+ line. Typical output: +"cargo-plushie 0.7.1\n"+.
86 87 88 89 90 91 |
# File 'lib/plushie/cargo_plushie.rb', line 86 def extract_version(output) output.to_s.split(/\s+/).find do |token| token.match?(/\A\d+\.\d+\.\d+(?:-[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)(?:\+[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?\z/) || token.match?(/\A\d+\.\d+\.\d+(?:\+[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?\z/) end end |
.mismatch_message ⇒ String
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/plushie/cargo_plushie.rb', line 94 def expected = Plushie::PLUSHIE_RUST_VERSION <<~MSG.chomp cargo-plushie on PATH is not version #{expected}. Install the matching version: cargo install cargo-plushie --version #{expected} --locked Or point at a plushie-rust checkout: export PLUSHIE_RUST_SOURCE_PATH=/path/to/plushie-rust MSG end |
.missing_message ⇒ String
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/plushie/cargo_plushie.rb', line 108 def expected = Plushie::PLUSHIE_RUST_VERSION <<~MSG.chomp cargo-plushie not found on PATH. Install it: cargo install cargo-plushie --version #{expected} --locked Or point at a plushie-rust checkout: export PLUSHIE_RUST_SOURCE_PATH=/path/to/plushie-rust MSG end |
.resolve ⇒ Array(String, Array<String>)
Resolve an executable command for invoking cargo-plushie.
Returns a tuple +[program, preamble_args]+ that the caller uses to build a shell command: +[program, *preamble_args, *user_args]+.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/plushie/cargo_plushie.rb', line 30 def resolve if (source = source_path) && File.directory?(source) return resolve_via_source(source) end case check_path_version when :match ["cargo-plushie", []] when :mismatch raise Error, when :missing raise Error, end end |
.resolve_via_source(source) ⇒ Array(String, Array<String>)
56 57 58 59 60 61 62 |
# File 'lib/plushie/cargo_plushie.rb', line 56 def resolve_via_source(source) manifest = File.join(source, "Cargo.toml") ["cargo", ["run", "--manifest-path", manifest, "-p", "cargo-plushie", "--release", "--quiet", "--"]] end |
.source_path ⇒ String?
Exposed for testing. In production, reads +PLUSHIE_RUST_SOURCE_PATH+ first, falling back to +Plushie.configuration.source_path+.
50 51 52 |
# File 'lib/plushie/cargo_plushie.rb', line 50 def source_path ENV["PLUSHIE_RUST_SOURCE_PATH"] || Plushie.configuration.source_path end |