Class: Beni::DSL::Context
- Inherits:
-
Object
- Object
- Beni::DSL::Context
- Defined in:
- lib/beni/dsl/context.rb,
sig/beni/dsl/context.rbs
Overview
Top-level vocabulary of the Beni::Tasks.new block. Collects the
scalar settings, target declarations, and toolchain definitions —
validating each declaration eagerly — and resolves them into the
Configuration the task-definition phase consumes.
Instance Method Summary collapse
- #build_config(path) ⇒ void
-
#configuration ⇒ Configuration
Resolve the collected declarations (SPEC.md Behaviors: selection is reference-driven; defaults fall to the built-in pairs).
- #declare_scalar(key, value) ⇒ void
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #mruby_version ⇒ String
- #resolved_build_config ⇒ String?
- #resolved_targets ⇒ Array[String]
- #resolved_vendor_dir ⇒ String
-
#selected_names ⇒ Array[String]
References plus their transitive dependencies;
mrubyis always selected and leads the set so it stages first. - #selected_toolchain(name) ⇒ SelectedToolchain
-
#target(name, &block) ⇒ void
A
target <name>declaration; the optional block holds the target's toolchain references. -
#toolchain(name, &block) ⇒ void
A top-level
toolchain <name>— always a definition, so the block is part of the grammar andmrubyis never definable. - #vendor_dir(path) ⇒ void
- #version(value) ⇒ void
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
10 11 12 13 14 |
# File 'lib/beni/dsl/context.rb', line 10 def initialize @settings = {} @targets = {} @definitions = {} end |
Instance Method Details
#build_config(path) ⇒ void
This method returns an undefined value.
20 21 22 |
# File 'lib/beni/dsl/context.rb', line 20 def build_config(path) declare_scalar(:build_config, path) end |
#configuration ⇒ Configuration
Resolve the collected declarations (SPEC.md Behaviors: selection is reference-driven; defaults fall to the built-in pairs).
56 57 58 59 60 61 62 63 |
# File 'lib/beni/dsl/context.rb', line 56 def configuration Configuration.new( vendor_dir: resolved_vendor_dir, build_config: resolved_build_config, targets: resolved_targets, toolchains: selected_names.map { |name| selected_toolchain(name) } ) end |
#declare_scalar(key, value) ⇒ void
This method returns an undefined value.
67 68 69 70 71 |
# File 'lib/beni/dsl/context.rb', line 67 def declare_scalar(key, value) raise Error, "duplicate `#{key}` declaration" if @settings.key?(key) @settings[key] = value end |
#mruby_version ⇒ String
104 105 106 |
# File 'lib/beni/dsl/context.rb', line 104 def mruby_version @settings[:version] || Vendor::BUILT_IN_PAIRS.fetch("mruby").fetch(:version) end |
#resolved_build_config ⇒ String?
77 78 79 80 |
# File 'lib/beni/dsl/context.rb', line 77 def resolved_build_config path = @settings[:build_config] path && File.(path) end |
#resolved_targets ⇒ Array[String]
82 83 84 85 86 |
# File 'lib/beni/dsl/context.rb', line 82 def resolved_targets return Builder::DEFAULT_TARGETS.dup if @targets.empty? @targets.keys end |
#resolved_vendor_dir ⇒ String
73 74 75 |
# File 'lib/beni/dsl/context.rb', line 73 def resolved_vendor_dir File.(@settings[:vendor_dir] || ENV.fetch("BENI_VENDOR_DIR", nil) || "vendor") end |
#selected_names ⇒ Array[String]
References plus their transitive dependencies; mruby is always
selected and leads the set so it stages first.
90 91 92 93 94 |
# File 'lib/beni/dsl/context.rb', line 90 def selected_names references = @targets.values.flat_map(&:references) dependencies = references.flat_map { |name| Vendor::DEPENDENCIES.fetch(name, []) } (%w[mruby] + references + dependencies).uniq end |
#selected_toolchain(name) ⇒ SelectedToolchain
96 97 98 99 100 101 102 |
# File 'lib/beni/dsl/context.rb', line 96 def selected_toolchain(name) definition = @definitions[name] return SelectedToolchain.new(name: name, version: definition.version, sha256: definition.sha256) if definition version = name == "mruby" ? mruby_version : Vendor::BUILT_IN_PAIRS.fetch(name).fetch(:version) SelectedToolchain.new(name: name, version: version, sha256: Vendor.built_in_sha256(name, version)) end |
#target(name, &block) ⇒ void
This method returns an undefined value.
A target <name> declaration; the optional block holds the
target's toolchain references.
30 31 32 33 34 35 36 37 |
# File 'lib/beni/dsl/context.rb', line 30 def target(name, &block) key = name.to_s raise Error, "duplicate `target` declaration #{key.inspect}" if @targets.key?(key) # @type var references: Array[String] references = block ? TargetContext.collect(&block) : [] @targets[key] = Target.new(name: key, references: references) end |
#toolchain(name, &block) ⇒ void
This method returns an undefined value.
A top-level toolchain <name> — always a definition, so the
block is part of the grammar and mruby is never definable.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/beni/dsl/context.rb', line 41 def toolchain(name, &block) key = name.to_s raise Error, "top-level `toolchain #{key.inspect}` must carry a definition block" unless block if key == "mruby" raise Error, "a toolchain definition never names \"mruby\" — select it with the `version` setting" end DSL.assert_known_toolchain!(key) raise Error, "duplicate toolchain definition #{key.inspect}" if @definitions.key?(key) @definitions[key] = DefinitionContext.collect(key, &block) end |
#vendor_dir(path) ⇒ void
This method returns an undefined value.
24 25 26 |
# File 'lib/beni/dsl/context.rb', line 24 def vendor_dir(path) declare_scalar(:vendor_dir, path) end |
#version(value) ⇒ void
This method returns an undefined value.
16 17 18 |
# File 'lib/beni/dsl/context.rb', line 16 def version(value) declare_scalar(:version, value) end |