Class: Beni::Vendor::Toolchain
- Inherits:
-
Object
- Object
- Beni::Vendor::Toolchain
- Defined in:
- lib/beni/vendor/toolchain.rb
Overview
Declarative value object describing a tarball-style vendored toolchain. Captures the (remote, cache, unpacked) triple anchored on vendor_dir, and exposes the three pipeline stages (#fetch, #verify, #install) that Beni::Tasks wires into file / task declarations.
Adding a new tarball-based vendor artifact is a single factory method in Beni::Vendor; the rake DSL loop in Beni::Tasks picks it up automatically.
Fields:
* +name+ — display name; also the basename of the unpacked
tree under +vendor_dir+ and the base for the
+setup:<name>+ task identifier.
* +version_label+ — version string; printed in the download log and
stamped into +final_dir+ as the idempotency key
that detects a bump and forces a re-extract.
* +base_url+ — remote URL prefix; resolved through
+Beni::Vendor.base_url_for+ so test fixtures
can override via +BENI_VENDOR_BASE_URL+.
* +tarball_name+ — filename joined to both +base_url+ (download)
and the +.cache+ directory (cache location).
* +top_level_dir+ — the single top-level directory produced when
the tarball is extracted; passed through to
+Tarball#prepare+ under the same name.
* +vendor_dir+ — root of the vendor tree; anchors +final_dir+
and +tarball_path+.
* +expected_sha256+ — the toolchain's selected checksum (resolved
by +Beni::Vendor+ from the built-in pair or a
consumer override); +nil+ falls to TOFU
sidecar pinning in +Checksum#verify_or_pin+.
Instance Method Summary collapse
-
#fetch ⇒ Object
Download the tarball into
tarball_pathand verify its SHA256. -
#final_dir ⇒ Object
Destination under
vendor_dirwhere the unpacked tree is moved. -
#install ⇒ Object
Verify the cached tarball, then unpack it into
final_dirvia Tarball#prepare. -
#tarball_path ⇒ Object
Local cache path for the downloaded tarball.
-
#task_name ⇒ Object
Symbol used to identify the setup:<task_name> rake task.
-
#url ⇒ Object
Resolved download URL.
-
#verify ⇒ Object
Recompute the cached tarball’s SHA256 and check it against
expected_sha256(or pin via TOFU sidecar).
Instance Method Details
#fetch ⇒ Object
Download the tarball into tarball_path and verify its SHA256. Intended as the body of the file tarball_path rake task; the task’s mtime-based caching avoids re-downloading on a cache hit. A tarball failing verification deliberately stays cached: a checksum mismatch is an abort condition, never a re-download trigger, and the cache-hit path re-fails it the same way.
70 71 72 73 74 |
# File 'lib/beni/vendor/toolchain.rb', line 70 def fetch puts "[beni] downloading #{name} #{version_label} from #{url}" downloader.download verify end |
#final_dir ⇒ Object
Destination under vendor_dir where the unpacked tree is moved.
54 55 56 |
# File 'lib/beni/vendor/toolchain.rb', line 54 def final_dir File.join(vendor_dir, name) end |
#install ⇒ Object
Verify the cached tarball, then unpack it into final_dir via Tarball#prepare. A no-op when the version stamped under final_dir already matches version_label.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/beni/vendor/toolchain.rb', line 87 def install verify Tarball.new( tarball: tarball_path, top_level_dir: top_level_dir, final_dir: final_dir, version: version_label ).prepare puts "[beni] #{name} ready at #{final_dir}" end |
#tarball_path ⇒ Object
Local cache path for the downloaded tarball. Lives under vendor_dir/.cache (the cache moves with the vendor tree).
60 61 62 |
# File 'lib/beni/vendor/toolchain.rb', line 60 def tarball_path File.join(vendor_dir, ".cache", tarball_name) end |
#task_name ⇒ Object
Symbol used to identify the setup:<task_name> rake task. Dashes in name are not valid in rake task identifiers, so we map them to underscores at this single seam.
42 43 44 |
# File 'lib/beni/vendor/toolchain.rb', line 42 def task_name name.tr("-", "_").to_sym end |
#url ⇒ Object
Resolved download URL. Honours the BENI_VENDOR_BASE_URL test fixture override at call time (not at construction time), so a test can flip the env var after the Toolchain is built.
49 50 51 |
# File 'lib/beni/vendor/toolchain.rb', line 49 def url "#{Vendor.base_url_for(base_url)}/#{tarball_name}" end |
#verify ⇒ Object
Recompute the cached tarball’s SHA256 and check it against expected_sha256 (or pin via TOFU sidecar). Idempotent — safe to call from both file and setup task bodies when the latter depends on the former.
80 81 82 |
# File 'lib/beni/vendor/toolchain.rb', line 80 def verify Checksum.new(tarball_path, expected_sha256).verify_or_pin end |