[tbb-commits] [builders/rbm] 01/06: Bug 40027: Add support for rbm.module.conf files

gitolite role git at cupani.torproject.org
Fri Jul 1 09:32:59 UTC 2022


This is an automated email from the git hooks/post-receive script.

gk pushed a commit to branch master
in repository builders/rbm.

commit 313f08fcc9d9bd4ef1ba4a98e92de2dd06e8c216
Author: Nicolas Vigier <boklm at torproject.org>
AuthorDate: Mon Jun 27 14:49:17 2022 +0200

    Bug 40027: Add support for rbm.module.conf files
---
 lib/RBM.pm                            | 19 ++++++++++++++++++-
 lib/RBM/DefaultConfig.pm              |  3 ++-
 rbm                                   |  1 +
 test.pl                               | 15 ++++++++++++++-
 test/modules/module_1/rbm.module.conf |  2 ++
 test/modules/module_2/rbm.module.conf |  2 ++
 test/modules/module_3/rbm.module.conf |  2 ++
 7 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/lib/RBM.pm b/lib/RBM.pm
index 24c6d44..7e29d3e 100644
--- a/lib/RBM.pm
+++ b/lib/RBM.pm
@@ -79,6 +79,21 @@ sub load_local_config {
     $config->{local} = -f $cfile ? load_config_file($cfile) : {};
 }
 
+sub load_modules_config {
+    my ($project) = @_;
+    $config->{modules} = {};
+    my $modules_dir = project_config($project ? $project : 'undef', 'modules_dir');
+    for my $dir (reverse @{as_array($modules_dir)}) {
+        my $d = rbm_path($dir);
+        next unless -d $d;
+        for my $module (map { $_->basename } path($d)->children) {
+            my $cfile = "$d/$module/rbm.module.conf";
+            $config->{modules}{$module} = load_config_file($cfile)
+                if -f $cfile;
+        }
+    }
+}
+
 sub find_config_file {
     for (my $dir = getcwd; $dir ne '/'; $dir = dirname($dir)) {
         return "$dir/rbm.conf" if -f "$dir/rbm.conf";
@@ -232,9 +247,11 @@ sub project_config {
     goto FINISH unless @$name;
     my $opt_save = $config->{opt};
     $config->{opt} = { %{$config->{opt}}, %$options } if $options;
+    my @modules = map { [ 'modules', $_ ] }
+                        sort keys %{ $config->{modules} };
     $res = config($project, $name, $options, ['opt', 'norec'], ['opt'],
                         ['run'], ['projects', $project], ['local'], [],
-                        ['system'], ['default']);
+                        @modules, ['system'], ['default']);
     if (!$options->{no_tmpl} && defined($res) && !ref $res
         && !notmpl(confkey_str($name), $project)) {
         $res = process_template($project, $res,
diff --git a/lib/RBM/DefaultConfig.pm b/lib/RBM/DefaultConfig.pm
index ce75c1a..4fbe079 100644
--- a/lib/RBM/DefaultConfig.pm
+++ b/lib/RBM/DefaultConfig.pm
@@ -104,6 +104,7 @@ our %default_config = (
     tmp_dir       => '[% GET ENV.TMPDIR ? ENV.TMPDIR : "/tmp"; %]',
     rbm_tmp_dir   => \&rbm_tmp_dir,
     projects_dir  => 'projects',
+    modules_dir   => 'modules',
     output_dir    => 'out',
     git_clone_dir => 'git_clones',
     hg_clone_dir  => 'hg_clones',
@@ -112,7 +113,7 @@ our %default_config = (
     build         => '[% INCLUDE build -%]',
     build_log     => '-',
     build_log_append => '1',
-    notmpl        => [ qw(projects_dir) ],
+    notmpl        => [ qw(projects_dir modules_dir) ],
     abbrev_length => '12',
     abbrev        => '[%
                          IF c("git_url");
diff --git a/rbm b/rbm
index 764141e..c99de28 100755
--- a/rbm
+++ b/rbm
@@ -80,6 +80,7 @@ sub set_options {
     }
     RBM::load_system_config(@_);
     RBM::load_local_config(@_);
+    RBM::load_modules_config(@_);
     if (!defined $val{step} && @_) {
         $RBM::config->{step} = RBM::project_config($_[0], 'pkg_type');
     }
diff --git a/test.pl b/test.pl
index 6c99cf0..0700d9c 100755
--- a/test.pl
+++ b/test.pl
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 use strict;
 use Path::Tiny;
-use Test::More tests => 29;
+use Test::More tests => 31;
 use lib 'lib/';
 
 sub set_target {
@@ -19,6 +19,7 @@ sub set_step {
 BEGIN { use_ok('RBM') };
 chdir 'test';
 RBM::load_config;
+RBM::load_modules_config;
 RBM::set_default_env;
 ok($RBM::config, 'load config');
 
@@ -145,6 +146,18 @@ my @tests = (
         config => [ 'c', 'option_deb' ],
         expected => '1',
     },
+    {
+        name => 'Using option from rbm.module.conf',
+        target => [],
+        config => [ 'b', 'module_3'],
+        expected => '3',
+    },
+    {
+        name => 'Using option defined in multiple rbm.module.conf',
+        target => [],
+        config => [ 'b', 'module_m'],
+        expected => '1',
+    },
     {
         name => 'build + steps config - 1',
         target => [ 'version_1' ],
diff --git a/test/modules/module_1/rbm.module.conf b/test/modules/module_1/rbm.module.conf
new file mode 100644
index 0000000..243b870
--- /dev/null
+++ b/test/modules/module_1/rbm.module.conf
@@ -0,0 +1,2 @@
+module_m: 1
+module_1: 1
diff --git a/test/modules/module_2/rbm.module.conf b/test/modules/module_2/rbm.module.conf
new file mode 100644
index 0000000..5a79ea6
--- /dev/null
+++ b/test/modules/module_2/rbm.module.conf
@@ -0,0 +1,2 @@
+module_m: 2
+module_2: 2
diff --git a/test/modules/module_3/rbm.module.conf b/test/modules/module_3/rbm.module.conf
new file mode 100644
index 0000000..ed43fbd
--- /dev/null
+++ b/test/modules/module_3/rbm.module.conf
@@ -0,0 +1,2 @@
+module_m: 3
+module_3: 3

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tbb-commits mailing list