Class: Beni::Vendor::Toolchain

Inherits:
Object
  • Object
show all
Defined in:
lib/beni/vendor/toolchain.rb,
sig/beni/vendor/toolchain.rbs

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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeToolchain

Returns a new instance of Toolchain.

Parameters:

  • name: (String)
  • version_label: (String)
  • base_url: (String)
  • tarball_name: (String)
  • top_level_dir: (String)
  • vendor_dir: (String)
  • expected_sha256: (String, nil)


12
# File 'sig/beni/vendor/toolchain.rbs', line 12

def initialize: (name: String, version_label: String, base_url: String, tarball_name: String, top_level_dir: String, vendor_dir: String, expected_sha256: String?) -> void

Instance Attribute Details

#base_urlString (readonly)

Returns the value of attribute base_url.

Returns:

  • (String)


6
7
8
# File 'sig/beni/vendor/toolchain.rbs', line 6

def base_url
  @base_url
end

#expected_sha256String? (readonly)

Returns the value of attribute expected_sha256.

Returns:

  • (String, nil)


10
11
12
# File 'sig/beni/vendor/toolchain.rbs', line 10

def expected_sha256
  @expected_sha256
end

#nameString (readonly)

Returns the value of attribute name.

Returns:

  • (String)


4
5
6
# File 'sig/beni/vendor/toolchain.rbs', line 4

def name
  @name
end

#tarball_nameString (readonly)

Returns the value of attribute tarball_name.

Returns:

  • (String)


7
8
9
# File 'sig/beni/vendor/toolchain.rbs', line 7

def tarball_name
  @tarball_name
end

#top_level_dirString (readonly)

Returns the value of attribute top_level_dir.

Returns:

  • (String)


8
9
10
# File 'sig/beni/vendor/toolchain.rbs', line 8

def top_level_dir
  @top_level_dir
end

#vendor_dirString (readonly)

Returns the value of attribute vendor_dir.

Returns:

  • (String)


9
10
11
# File 'sig/beni/vendor/toolchain.rbs', line 9

def vendor_dir
  @vendor_dir
end

#version_labelString (readonly)

Returns the value of attribute version_label.

Returns:

  • (String)


5
6
7
# File 'sig/beni/vendor/toolchain.rbs', line 5

def version_label
  @version_label
end

Instance Method Details

#downloaderDownloader

The network boundary — tests override this to script the download without opening a connection.

Returns:



102
103
104
# File 'lib/beni/vendor/toolchain.rb', line 102

def downloader
  Downloader.new(url, tarball_path)
end

#fetchString

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.

Returns:

  • (String)


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_dirString

Destination under vendor_dir where the unpacked tree is moved.

Returns:

  • (String)


54
55
56
# File 'lib/beni/vendor/toolchain.rb', line 54

def final_dir
  File.join(vendor_dir, name)
end

#installvoid

This method returns an undefined value.

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_pathString

Local cache path for the downloaded tarball. Lives under vendor_dir/.cache (the cache moves with the vendor tree).

Returns:

  • (String)


60
61
62
# File 'lib/beni/vendor/toolchain.rb', line 60

def tarball_path
  File.join(vendor_dir, ".cache", tarball_name)
end

#task_nameSymbol

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.

Returns:

  • (Symbol)


42
43
44
# File 'lib/beni/vendor/toolchain.rb', line 42

def task_name
  name.tr("-", "_").to_sym
end

#urlString

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.

Returns:

  • (String)


49
50
51
# File 'lib/beni/vendor/toolchain.rb', line 49

def url
  "#{Vendor.base_url_for(base_url)}/#{tarball_name}"
end

#verifyString

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.

Returns:

  • (String)


80
81
82
# File 'lib/beni/vendor/toolchain.rb', line 80

def verify
  Checksum.new(tarball_path, expected_sha256).verify_or_pin
end