From e048ca9685bfeab7e4ca0767f8165dc774a605a0 Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Thu, 29 Aug 2019 14:51:50 +0200 Subject: [PATCH] Environment variables are configuration-defined. It was previously inherited, but that behavior was error-prone. This commit fixes that. --- src/context.cr | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/context.cr b/src/context.cr index b1609a3..5a3f165 100644 --- a/src/context.cr +++ b/src/context.cr @@ -74,6 +74,7 @@ class Package::Context property architecture = "x86_64" property prefixes = ["/usr", "/", "/usr/weirdos"] + property environment = {} of String => String def initialize @packaging_backends << Backend::Packaging.new "pkgutils" do |context, package| @@ -213,7 +214,7 @@ class Package::Context end def run(chdir, command, args) - Process.run command, args, chdir: chdir, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit + Process.run command, args, chdir: chdir, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit, env: @environment end def run(command, args) @@ -263,6 +264,19 @@ class Package::Context @sources_directory = value.as_s when "prefixes" @prefixes = value.as_a_or_s + when "environment" + value.as_a_or_s.each do |entry| + match = entry.split(':').map( + &.gsub(/^[ \t]*/, "").gsub(/[ \t]*$/, "")) + + if match.size != 2 + STDERR.puts "WARNING: misformed environment definition: #{entry}" + next + end + + key, value = match + @environment[key] = value + end end end end