This is an automated email from the git hooks/post-receive script.
gk pushed a commit to branch master in repository builders/rbm.
commit 278411fb12ef71b6f2973ce70669118748474124 Author: Nicolas Vigier boklm@torproject.org AuthorDate: Mon Jun 27 15:40:21 2022 +0200
Bug 40028: Load projects config from modules --- lib/RBM.pm | 31 ++++++++++++++++++++++++------ test.pl | 17 +++++++++++++++- test/modules/module_1/projects/a/config | 1 + test/modules/module_1/projects/m1_a/config | 2 ++ 4 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/lib/RBM.pm b/lib/RBM.pm index 7e29d3e..ee987c8 100644 --- a/lib/RBM.pm +++ b/lib/RBM.pm @@ -90,6 +90,13 @@ sub load_modules_config { my $cfile = "$d/$module/rbm.module.conf"; $config->{modules}{$module} = load_config_file($cfile) if -f $cfile; + next unless -d "$d/$module/projects"; + for my $project (map { $_->basename } path("$d/$module/projects")->children) { + next if $config->{projects}{$project}; + next unless -f "$d/$module/projects/$project/config"; + $config->{modules}{$module}{projects}{$project} = + load_config_file("$d/$module/projects/$project/config"); + } } } } @@ -249,8 +256,17 @@ sub project_config { $config->{opt} = { %{$config->{opt}}, %$options } if $options; my @modules = map { [ 'modules', $_ ] } sort keys %{ $config->{modules} }; + my $project_path = ['projects', $project]; + if (!$config->{projects}{$project}) { + for my $module (sort keys %{ $config->{modules} }) { + if ($config->{modules}{$module}{projects}{$project}) { + $project_path = [ 'modules', $module, 'projects', $project ]; + last; + } + } + } $res = config($project, $name, $options, ['opt', 'norec'], ['opt'], - ['run'], ['projects', $project], ['local'], [], + ['run'], $project_path, ['local'], [], @modules, ['system'], ['default']); if (!$options->{no_tmpl} && defined($res) && !ref $res && !notmpl(confkey_str($name), $project)) { @@ -381,8 +397,11 @@ sub valid_id {
sub valid_project { my ($project) = @_; - exists $config->{projects}{$project} - || exit_error "Unknown project $project"; + return 1 if $config->{projects}{$project}; + for my $module (keys %{$config->{modules}}) { + return 1 if $config->{modules}{$module}{projects}{$project}; + } + exit_error "Unknown project $project"; }
sub create_dir { @@ -395,7 +414,7 @@ sub create_dir {
sub git_need_fetch { my ($project, $options) = @_; - return 0 if $config->{projects}{$project}{fetched}; + return 0 if $config->{_rbm}{fetched_projects}{$project}; my $fetch = project_config($project, 'fetch', $options); if ($fetch eq 'if_needed') { my $git_hash = project_config($project, 'git_hash', $options) @@ -440,13 +459,13 @@ sub git_clone_fetch_chdir { system('git', 'fetch', @fetch_submod, 'origin', '+refs/tags/*:refs/tags/*') == 0 || exit_error "Error fetching git repository"; - $config->{projects}{$project}{fetched} = 1; + $config->{_rbm}{fetched_projects}{$project} = 1; } }
sub hg_need_fetch { my ($project, $options) = @_; - return 0 if $config->{projects}{$project}{fetched}; + return 0 if $config->{_rbm}{fetched_projects}{$project}; my $fetch = project_config($project, 'fetch', $options); if ($fetch eq 'if_needed') { my $hg_hash = project_config($project, 'hg_hash', $options) diff --git a/test.pl b/test.pl index 0700d9c..d71baaa 100755 --- a/test.pl +++ b/test.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; use Path::Tiny; -use Test::More tests => 31; +use Test::More tests => 34; use lib 'lib/';
sub set_target { @@ -158,6 +158,21 @@ my @tests = ( config => [ 'b', 'module_m'], expected => '1', }, + { + name => 'Using option defined in a module project', + config => [ 'm1_a', 'm1_a' ], + expected => 'm1_a', + }, + { + name => 'Using option defined in a module project and rbm.module.conf', + config => [ 'm1_a', 'project_m' ], + expected => 'm1_a', + }, + { + name => 'Using option defined in main projects and a module project', + config => [ 'a', 'project_a' ], + expected => 'a', + }, { name => 'build + steps config - 1', target => [ 'version_1' ], diff --git a/test/modules/module_1/projects/a/config b/test/modules/module_1/projects/a/config new file mode 100644 index 0000000..2f2e097 --- /dev/null +++ b/test/modules/module_1/projects/a/config @@ -0,0 +1 @@ +project_a: from_module_1 diff --git a/test/modules/module_1/projects/m1_a/config b/test/modules/module_1/projects/m1_a/config new file mode 100644 index 0000000..9f8b6c6 --- /dev/null +++ b/test/modules/module_1/projects/m1_a/config @@ -0,0 +1,2 @@ +m1_a: m1_a +project_m: m1_a