diff --git a/src/context.cr b/src/context.cr index a38a96f..d16a676 100644 --- a/src/context.cr +++ b/src/context.cr @@ -20,6 +20,9 @@ class Package::Context getter packaging_backends = Hash(String, Backend::Packaging).new getter splitter_backends = Hash(String, Backend::Splitter).new + # General options, to add to the recipe before reading it. + getter options = Hash(String, String).new + getter all_phase_names = [ "sources-split", "pre-configure", "configure", @@ -111,9 +114,11 @@ class Package::Context @sources_directory = value.as_s when "working-directory" @working_directory = value.as_s + when "prefixes" # Prefixes during the build process. @prefixes = value.as_a_or_s + when "build-cores" # NB of cores used to compile applications. @build_cores = value.as_s.to_i @@ -136,6 +141,25 @@ class Package::Context end end + when "options" + value.as_a_or_s.each do |option| + match = option.split(':').map(&.strip) + + if match.size != 2 + STDERR.puts "WARNING: misformed option: #{option}" + next + end + + key, value = match + + @options[key] = value + end + + # (default) user instructions (for testing). + when /(?(pre-)?(configure|build|install)|post-install)/ + phase = $~["phase"] + @user_instructions[phase] = Instructions.new(phase).<<(value.as_s_or_ls) + when "package-manager" # Targeted package manager (default: package, for BaguetteOS). begin diff --git a/src/recipe.cr b/src/recipe.cr index 1d3f5d0..d3d5e1d 100644 --- a/src/recipe.cr +++ b/src/recipe.cr @@ -80,6 +80,9 @@ class Package::Recipe property require_stripping = true def initialize(@context, @name, @version) + @context.options.each do |k, v| + @options[k] = v + end end def self.new(context, name, version) @@ -91,6 +94,9 @@ class Package::Recipe end def initialize(@context, filename : String) + @context.options.each do |k, v| + @options[k] = v + end specs = SpecParser.parse File.read(filename), { "pkg" => fake_root_directory, "prefix" => prefix