[tbb-commits] [rbm/master] Add the ENV option

boklm at torproject.org boklm at torproject.org
Wed Mar 1 13:58:56 UTC 2017


commit 1945b67fefbcf7b834b71275e301da06232f0241
Author: Nicolas Vigier <boklm at torproject.org>
Date:   Wed Mar 1 14:53:34 2017 +0100

    Add the ENV option
    
    Add the ENV option, allowing to define some default environment
    variables.
---
 NEWS               | 2 ++
 doc/rbm_config.asc | 7 +++++++
 lib/RBM.pm         | 4 ++++
 rbm                | 1 +
 test.pl            | 1 +
 5 files changed, 15 insertions(+)

diff --git a/NEWS b/NEWS
index 663a281..5de36e0 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+- Add the ENV option
+
 - Add the build_log option
 
 - Add support for optional local configuration file rbm.local.conf
diff --git a/doc/rbm_config.asc b/doc/rbm_config.asc
index a461b3d..48e505c 100644
--- a/doc/rbm_config.asc
+++ b/doc/rbm_config.asc
@@ -151,6 +151,13 @@ fetch::
         repository is fetched only if the selected commit cannot be
         found in the local clone. The default is +if_needed+.
 
+ENV::
+        This option, defined in the workspace config, is a hash
+        containing the environment variables that will be defined
+        when rbm is starting. This is useful for defining variables
+        that can affect how the templates are processed (for instance
+        the +TZ+ variable if dates are used).
+
 include::options_tar.asc[]
 
 arch::
diff --git a/lib/RBM.pm b/lib/RBM.pm
index 2248b41..632a8ba 100644
--- a/lib/RBM.pm
+++ b/lib/RBM.pm
@@ -75,6 +75,10 @@ sub find_config_file {
     exit_error("Can't find config file");
 }
 
+sub set_default_env {
+    %ENV = (%ENV, %{$config->{ENV}}) if ref $config->{ENV} eq 'HASH';
+}
+
 sub path {
     my ($path, $basedir) = @_;
     $basedir //= $config->{basedir};
diff --git a/rbm b/rbm
index 050cff5..9a8ccf2 100755
--- a/rbm
+++ b/rbm
@@ -198,6 +198,7 @@ if (@ARGV == 0 || !$actions{$ARGV[0]}) {
 }
 usage('usage', $ARGV[0]) if grep { $_ eq '--help' } @ARGV[1..(@ARGV - 1)];
 RBM::load_config unless $actions{$ARGV[0]}->{no_config};
+RBM::set_default_env unless $actions{$ARGV[0]}->{no_config};
 $actions{$ARGV[0]}->{run}->(@ARGV);
 
 # vim: expandtab sw=4
diff --git a/test.pl b/test.pl
index 64bffd7..2748614 100755
--- a/test.pl
+++ b/test.pl
@@ -19,6 +19,7 @@ sub set_step {
 BEGIN { use_ok('RBM') };
 chdir 'test';
 RBM::load_config;
+RBM::set_default_env;
 ok($RBM::config, 'load config');
 
 my @tests = (



More information about the tbb-commits mailing list