[tbb-commits] [builders/rbm] 03/06: Bug 40028: Add support for input_files and template files in modules
gitolite role
git at cupani.torproject.org
Fri Jul 1 09:33:01 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 471330953fb61bab10bff35bb74c8dbb69094cfb
Author: Nicolas Vigier <boklm at torproject.org>
AuthorDate: Mon Jun 27 18:48:38 2022 +0200
Bug 40028: Add support for input_files and template files in modules
---
lib/RBM.pm | 48 +++++++++++++++++++---
test.pl | 35 +++++++++++++++-
test/modules/module_1/projects/common/common_2.txt | 1 +
test/modules/module_1/projects/common/common_3.txt | 1 +
test/modules/module_1/projects/common/common_4.txt | 1 +
test/modules/module_1/projects/m1_a/config | 1 +
test/modules/module_1/projects/m1_a/m1_a-i.txt | 1 +
test/modules/module_1/rbm.module.conf | 1 +
test/modules/module_2/projects/common/common_4.txt | 1 +
test/modules/module_3/projects/m3_a/config | 7 ++++
test/modules/module_3/projects/m3_a/m3.txt | 1 +
test/projects/a/config | 3 ++
test/projects/common/common_1.txt | 1 +
test/projects/common/common_3.txt | 1 +
14 files changed, 96 insertions(+), 7 deletions(-)
diff --git a/lib/RBM.pm b/lib/RBM.pm
index ee987c8..afbe003 100644
--- a/lib/RBM.pm
+++ b/lib/RBM.pm
@@ -683,10 +683,11 @@ sub process_template {
return $res;
}
$dest_dir //= rbm_path(project_config($project, 'output_dir'));
- my $projects_dir = rbm_path(project_config($project, 'projects_dir'));
+ my $project_dir = modules_project_dir($project);
+ my $common_dirs = join(':', modules_common_dirs($project));
my $template = Template->new(
ENCODING => 'utf8',
- INCLUDE_PATH => "$projects_dir/$project:$projects_dir/common",
+ INCLUDE_PATH => "$project_dir:$common_dirs",
);
my $vars = {
config => $config,
@@ -815,6 +816,39 @@ sub recursive_copy {
return @copied;
}
+sub modules_project_dir {
+ my ($project, $options) = @_;
+ my $proj_dir = rbm_path(project_config($project, 'projects_dir', $options));
+ return "$proj_dir/$project" if -f "$proj_dir/$project/config";
+ my $modules_dir = project_config($project, 'modules_dir');
+ for my $dir (@{as_array($modules_dir)}) {
+ my $d = rbm_path($dir);
+ next unless -d $d;
+ for my $module (sort map { $_->basename } path($d)->children) {
+ my $pdir = "$d/$module/projects/$project";
+ return $pdir if -f "$pdir/config";
+ }
+ }
+ return "$proj_dir/$project";
+}
+
+sub modules_common_dirs {
+ my ($project, $options) = @_;
+ #my $proj_dir = rbm_path(project_config($project, 'projects_dir', $options));
+ my $proj_dir = rbm_path('projects');
+ my @cdirs = ("$proj_dir/common");
+ my $modules_dir = project_config($project, 'modules_dir');
+ for my $dir (@{as_array($modules_dir)}) {
+ my $d = rbm_path($dir);
+ next unless -d $d;
+ for my $module (sort map { $_->basename } path($d)->children) {
+ push @cdirs, "$d/$module/projects/common"
+ if -d "$d/$module/projects/common";
+ }
+ }
+ return @cdirs;
+}
+
sub input_files {
my ($action, $project, $options, $dest_dir) = @_;
my @res_copy;
@@ -827,8 +861,8 @@ sub input_files {
my $input_files = project_config($project, 'input_files', $options);
goto RETURN_RES unless $input_files;
my $proj_dir = rbm_path(project_config($project, 'projects_dir', $options));
- my $src_dir = "$proj_dir/$project";
- my $common_dir = "$proj_dir/common";
+ my $src_dir = modules_project_dir($project, $options);
+ my @modules_common_dirs = modules_common_dirs($project, $options);
my $old_cwd = getcwd;
chdir $src_dir || exit_error "cannot chdir to $src_dir";
foreach my $input_file_alias (@$input_files) {
@@ -919,7 +953,8 @@ sub input_files {
origin_project => $project, %$input_file})
if $input_file->{project};
exit_error("Missing filename:\n" . pp($input_file)) unless $name;
- my ($fname) = file_in_dir($name, $src_dir, $proj_out_dir, $common_dir);
+ my ($fname) = file_in_dir($name, $src_dir, $proj_out_dir,
+ @modules_common_dirs);
my $file_gpg_id = gpg_id($t->('file_gpg_id'));
if (input_file_need_dl($input_file, $t, $fname, $action)) {
if ($t->('content')) {
@@ -947,7 +982,8 @@ sub input_files {
dd $input_file;
exit_error "Missing file $name";
}
- ($fname) = file_in_dir($name, $src_dir, $proj_out_dir, $common_dir);
+ ($fname) = file_in_dir($name, $src_dir, $proj_out_dir,
+ @modules_common_dirs);
exit_error "Error getting file $name" unless $fname;
}
if ($action eq 'input_files_id') {
diff --git a/test.pl b/test.pl
index d71baaa..8992ad7 100755
--- a/test.pl
+++ b/test.pl
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
use strict;
use Path::Tiny;
-use Test::More tests => 34;
+use Test::More tests => 40;
use lib 'lib/';
sub set_target {
@@ -173,6 +173,31 @@ my @tests = (
config => [ 'a', 'project_a' ],
expected => 'a',
},
+ {
+ name => 'Using template file from common project',
+ config => [ 'a', 'c_1' ],
+ expected => "c1\n",
+ },
+ {
+ name => 'Using template file from common project in a module',
+ config => [ 'a', 'c_2' ],
+ expected => "c2\n",
+ },
+ {
+ name => 'Using template file in multiple common directories',
+ config => [ 'a', 'c_3' ],
+ expected => "c3_main\n",
+ },
+ {
+ name => 'Using template file in multiple modules common directories',
+ config => [ 'a', 'c_4' ],
+ expected => "c4_module1\n",
+ },
+ {
+ name => 'Using template file in project directories in a module',
+ config => [ 'm1_a', 'i' ],
+ expected => "i1\n",
+ },
{
name => 'build + steps config - 1',
target => [ 'version_1' ],
@@ -195,6 +220,14 @@ my @tests = (
'out/r3' => "1 - build\n2 - build\n3 - build\n",
},
},
+ {
+ name => 'build project in a module',
+ target => [],
+ build => [ 'm3_a', 'build', { pkg_type => 'build' } ],
+ files => {
+ 'out/m3-output' => "1 - build\n___m3\n"
+ },
+ },
{
name => 'mercurial repo',
target => [],
diff --git a/test/modules/module_1/projects/common/common_2.txt b/test/modules/module_1/projects/common/common_2.txt
new file mode 100644
index 0000000..16f9ec0
--- /dev/null
+++ b/test/modules/module_1/projects/common/common_2.txt
@@ -0,0 +1 @@
+c2
diff --git a/test/modules/module_1/projects/common/common_3.txt b/test/modules/module_1/projects/common/common_3.txt
new file mode 100644
index 0000000..7b6a471
--- /dev/null
+++ b/test/modules/module_1/projects/common/common_3.txt
@@ -0,0 +1 @@
+c3_module
diff --git a/test/modules/module_1/projects/common/common_4.txt b/test/modules/module_1/projects/common/common_4.txt
new file mode 100644
index 0000000..e0c56bd
--- /dev/null
+++ b/test/modules/module_1/projects/common/common_4.txt
@@ -0,0 +1 @@
+c4_module1
diff --git a/test/modules/module_1/projects/m1_a/config b/test/modules/module_1/projects/m1_a/config
index 9f8b6c6..9426965 100644
--- a/test/modules/module_1/projects/m1_a/config
+++ b/test/modules/module_1/projects/m1_a/config
@@ -1,2 +1,3 @@
m1_a: m1_a
project_m: m1_a
+i: '[% INCLUDE "m1_a-i.txt" -%]'
diff --git a/test/modules/module_1/projects/m1_a/m1_a-i.txt b/test/modules/module_1/projects/m1_a/m1_a-i.txt
new file mode 100644
index 0000000..ca49db8
--- /dev/null
+++ b/test/modules/module_1/projects/m1_a/m1_a-i.txt
@@ -0,0 +1 @@
+i1
diff --git a/test/modules/module_1/rbm.module.conf b/test/modules/module_1/rbm.module.conf
index 243b870..1a3dd98 100644
--- a/test/modules/module_1/rbm.module.conf
+++ b/test/modules/module_1/rbm.module.conf
@@ -1,2 +1,3 @@
module_m: 1
module_1: 1
+c_2: '[% INCLUDE common_2.txt %]'
diff --git a/test/modules/module_2/projects/common/common_4.txt b/test/modules/module_2/projects/common/common_4.txt
new file mode 100644
index 0000000..2a9eb48
--- /dev/null
+++ b/test/modules/module_2/projects/common/common_4.txt
@@ -0,0 +1 @@
+c4_module2
diff --git a/test/modules/module_3/projects/m3_a/config b/test/modules/module_3/projects/m3_a/config
new file mode 100644
index 0000000..3337d35
--- /dev/null
+++ b/test/modules/module_3/projects/m3_a/config
@@ -0,0 +1,7 @@
+filename: m3-output
+build: |
+ #!/bin/sh
+ echo 1 - [% c('pkg_type') %] > [% dest_dir %]/[% c('filename') %]
+ cat m3.txt >> [% dest_dir %]/[% c('filename') %]
+input_files:
+ - filename: m3.txt
diff --git a/test/modules/module_3/projects/m3_a/m3.txt b/test/modules/module_3/projects/m3_a/m3.txt
new file mode 100644
index 0000000..7f6edf0
--- /dev/null
+++ b/test/modules/module_3/projects/m3_a/m3.txt
@@ -0,0 +1 @@
+___m3
diff --git a/test/projects/a/config b/test/projects/a/config
index c578032..28866fe 100644
--- a/test/projects/a/config
+++ b/test/projects/a/config
@@ -17,3 +17,6 @@ z_2: '[% c("z", { option_a => "Z" }) %]'
Z_1: '[% c("z_1") _ c("z_2") _ c("z_1") %]'
Z_2: '[% pc("a", "z_1", { step => "S"}) _ c("z_2") _ c("z_1") %]'
Z: '[% c("Z_1") _ " " _ c("Z_2") _ " " _ c("Z_1") %]'
+c_1: '[% INCLUDE common_1.txt -%]'
+c_3: '[% INCLUDE common_3.txt -%]'
+c_4: '[% INCLUDE common_4.txt -%]'
diff --git a/test/projects/common/common_1.txt b/test/projects/common/common_1.txt
new file mode 100644
index 0000000..ae93045
--- /dev/null
+++ b/test/projects/common/common_1.txt
@@ -0,0 +1 @@
+c1
diff --git a/test/projects/common/common_3.txt b/test/projects/common/common_3.txt
new file mode 100644
index 0000000..4fb18ff
--- /dev/null
+++ b/test/projects/common/common_3.txt
@@ -0,0 +1 @@
+c3_main
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the tbb-commits
mailing list