boklm pushed to branch main at The Tor Project / Applications / RBM
Commits:
-
4c881eb4
by Nicolas Vigier at 2026-01-28T09:51:39+01:00
5 changed files:
- doc/rbm_config.asc
- doc/rbm_input_files.asc
- doc/rbm_templates.asc
- lib/RBM.pm
- lib/RBM/DefaultConfig.pm
Changes:
| ... | ... | @@ -246,8 +246,17 @@ input_files_by_name:: |
| 246 | 246 | with their +name+ as index. The input files without a +name+
|
| 247 | 247 | are not in this hash.
|
| 248 | 248 | |
| 249 | +input_files_ids_by_name::
|
|
| 250 | + This option contains the ids (hashes) of all the +input_files+,
|
|
| 251 | + with their +name+ as index. The id of an input file will be the
|
|
| 252 | + value of the option +input_file_id+ if it is defined, or
|
|
| 253 | + +filename:hash+, where +filename+ is the filename of the file,
|
|
| 254 | + and +hash+ is the sha512sum if the +sha512sum+ option is defined,
|
|
| 255 | + the sha256sum otherwise. This option does not work for input
|
|
| 256 | + files of type +project+, +exec+ or +content+.
|
|
| 257 | + |
|
| 249 | 258 | input_files_id::
|
| 250 | - The value of this option is an identifier of the input_files.
|
|
| 259 | + The value of this option is a single identifier of all the input_files.
|
|
| 251 | 260 | When any of the input files is changed, the identifier changes.
|
| 252 | 261 | This identifier is something that can be used in a project's
|
| 253 | 262 | filename to trigger a rebuild when any of its input files is
|
| ... | ... | @@ -280,11 +289,6 @@ timestamp:: |
| 280 | 289 | commit time of the commit used. If set to 0 it will use the
|
| 281 | 290 | current time.
|
| 282 | 291 | |
| 283 | -notmpl::
|
|
| 284 | - An array containing a list of options that should not be
|
|
| 285 | - processed as template (see the +template+ section below for
|
|
| 286 | - details).
|
|
| 287 | - |
|
| 288 | 292 | step::
|
| 289 | 293 | The value of this option is the name of the build script we are
|
| 290 | 294 | going to be running (by default 'build', but you could have an
|
| ... | ... | @@ -53,7 +53,7 @@ filename:: |
| 53 | 53 | |
| 54 | 54 | name::
|
| 55 | 55 | Optionaly the input_file can have a name. This name is used as
|
| 56 | - key in the +input_files_by_name+ option.
|
|
| 56 | + key in the +input_files_by_name+ and +input_files_ids_by_name+ options.
|
|
| 57 | 57 | |
| 58 | 58 | content::
|
| 59 | 59 | The content of the file.
|
| ... | ... | @@ -15,10 +15,7 @@ however, for the options that are needed to process templates, so they |
| 15 | 15 | can't be templated themself. The following options are not templated :
|
| 16 | 16 | |
| 17 | 17 | - projects_dir
|
| 18 | - |
|
| 19 | -If you want to make other options not templated, add them to the
|
|
| 20 | -+notmpl+ config option, which is an array. All the other options are
|
|
| 21 | -automatically processed as template.
|
|
| 18 | + - modules_dir
|
|
| 22 | 19 | |
| 23 | 20 | The template are made using perl Template Toolkit. You can read more
|
| 24 | 21 | about the syntax on the http://www.template-toolkit.org/[Template
|
| ... | ... | @@ -237,11 +237,8 @@ sub config { |
| 237 | 237 | }
|
| 238 | 238 | |
| 239 | 239 | sub notmpl {
|
| 240 | - my ($name, $project) = @_;
|
|
| 241 | - return 1 if $name eq 'notmpl';
|
|
| 242 | - my @n = (@{$config->{default}{notmpl}},
|
|
| 243 | - @{project_config($project, 'notmpl')});
|
|
| 244 | - return grep { $name eq $_ } @n;
|
|
| 240 | + my ($name) = @_;
|
|
| 241 | + return grep { $name eq $_ } @{$config->{default}{notmpl}};
|
|
| 245 | 242 | }
|
| 246 | 243 | |
| 247 | 244 | sub confkey_str {
|
| ... | ... | @@ -282,9 +279,13 @@ sub project_config { |
| 282 | 279 | ['run'], $project_path, ['local'], [],
|
| 283 | 280 | @modules, ['system'], ['default']);
|
| 284 | 281 | if (!$options->{no_tmpl} && defined($res) && !ref $res
|
| 285 | - && !notmpl(confkey_str($name), $project)) {
|
|
| 286 | - $res = process_template($project, $res,
|
|
| 287 | - confkey_str($name) eq 'output_dir' ? '.' : undef);
|
|
| 282 | + && !notmpl(confkey_str($name))) {
|
|
| 283 | + my $output_dir = undef;
|
|
| 284 | + if (confkey_str($name) eq 'output_dir' ||
|
|
| 285 | + confkey_str($name) eq 'getting_id_value/output_dir') {
|
|
| 286 | + $output_dir = '.';
|
|
| 287 | + }
|
|
| 288 | + $res = process_template($project, $res, $output_dir);
|
|
| 288 | 289 | }
|
| 289 | 290 | $config_cache{$project}{$step}{$name_str}{$cache_id} = $res;
|
| 290 | 291 | $config->{opt} = $opt_save;
|
| ... | ... | @@ -733,7 +734,7 @@ sub process_template { |
| 733 | 734 | }
|
| 734 | 735 | return $res;
|
| 735 | 736 | }
|
| 736 | - $dest_dir //= rbm_path(project_config($project, 'output_dir'));
|
|
| 737 | + $dest_dir //= rbm_path(project_config($project, 'getting_id_value/output_dir'));
|
|
| 737 | 738 | my $project_dir = modules_project_dir($project);
|
| 738 | 739 | my $common_dirs = join(':', modules_common_dirs($project));
|
| 739 | 740 | my $template = Template->new(
|
| ... | ... | @@ -823,7 +824,7 @@ sub input_file_need_dl { |
| 823 | 824 | $fname = undef;
|
| 824 | 825 | }
|
| 825 | 826 | }
|
| 826 | - if ($action eq 'input_files_id') {
|
|
| 827 | + if ($action eq 'input_files_id' || $action eq 'getfids') {
|
|
| 827 | 828 | return undef if $input_file->{input_file_id};
|
| 828 | 829 | for my $checksum (qw/sha512sum sha256sum/) {
|
| 829 | 830 | if ( ($input_file->{$checksum} || $input_file->{norec}{$checksum})
|
| ... | ... | @@ -861,7 +862,7 @@ sub input_file_id { |
| 861 | 862 | return $filename . ':' . $t->($checksum);
|
| 862 | 863 | }
|
| 863 | 864 | }
|
| 864 | - my $opts = { norec => { output_dir => '/out', getting_id => 1, }};
|
|
| 865 | + my $opts = { norec => { getting_id => 1, }};
|
|
| 865 | 866 | return $filename . ':' . sha256_hex($t->('exec', $opts))
|
| 866 | 867 | if $input_file->{exec};
|
| 867 | 868 | shafile('sha256sum', $fname, { remove_cache => 1 }) if $t->('refresh_input');
|
| ... | ... | @@ -923,6 +924,7 @@ sub input_files { |
| 923 | 924 | my @res_copy;
|
| 924 | 925 | my %res_getfnames;
|
| 925 | 926 | my @res_getfpaths;
|
| 927 | + my %res_getfids;
|
|
| 926 | 928 | my $getfnames_noname = 0;
|
| 927 | 929 | my $input_files_id = '';
|
| 928 | 930 | $options = {$options ? %$options : ()};
|
| ... | ... | @@ -1016,6 +1018,11 @@ sub input_files { |
| 1016 | 1018 | };
|
| 1017 | 1019 | next;
|
| 1018 | 1020 | }
|
| 1021 | + if ($action eq 'getfids') {
|
|
| 1022 | + next if $input_file->{project};
|
|
| 1023 | + next if $input_file->{exec};
|
|
| 1024 | + next if $input_file->{content};
|
|
| 1025 | + }
|
|
| 1019 | 1026 | my $proj_out_dir;
|
| 1020 | 1027 | if ($input_file->{project}) {
|
| 1021 | 1028 | $proj_out_dir = rbm_path(project_step_config($t->('project'), 'output_dir',
|
| ... | ... | @@ -1038,38 +1045,51 @@ sub input_files { |
| 1038 | 1045 | my ($fname) = file_in_dir($name, $src_dir, $proj_out_dir,
|
| 1039 | 1046 | @modules_common_dirs);
|
| 1040 | 1047 | my $file_gpg_id = gpg_id($t->('file_gpg_id'));
|
| 1048 | + my $dl_file = sub {};
|
|
| 1041 | 1049 | if (input_file_need_dl($input_file, $t, $fname, $action)) {
|
| 1042 | - if ($t->('content')) {
|
|
| 1043 | - my $dname = dirname("$proj_out_dir/$name");
|
|
| 1044 | - make_path($dname) unless -d $dname;
|
|
| 1045 | - path("$proj_out_dir/$name")->spew_utf8($t->('content'));
|
|
| 1046 | - } elsif ($t->('URL')) {
|
|
| 1047 | - urlget($project, {%$options, %$input_file, filename => $name}, 1);
|
|
| 1048 | - } elsif ($t->('exec')) {
|
|
| 1049 | - my $exec_script = project_config($project, 'exec',
|
|
| 1050 | - { $options ? %$options : (), %$input_file });
|
|
| 1051 | - if (run_script($project, $exec_script,
|
|
| 1052 | - sub { system(@_) }) != 0) {
|
|
| 1053 | - exit_error "Error creating $name";
|
|
| 1050 | + $dl_file = sub {
|
|
| 1051 | + if ($t->('content')) {
|
|
| 1052 | + my $dname = dirname("$proj_out_dir/$name");
|
|
| 1053 | + make_path($dname) unless -d $dname;
|
|
| 1054 | + path("$proj_out_dir/$name")->spew_utf8($t->('content'));
|
|
| 1055 | + } elsif ($t->('URL')) {
|
|
| 1056 | + urlget($project, {%$options, %$input_file, filename => $name}, 1);
|
|
| 1057 | + } elsif ($t->('exec')) {
|
|
| 1058 | + my $exec_script = project_config($project, 'exec',
|
|
| 1059 | + { $options ? %$options : (), %$input_file });
|
|
| 1060 | + if (run_script($project, $exec_script,
|
|
| 1061 | + sub { system(@_) }) != 0) {
|
|
| 1062 | + exit_error "Error creating $name";
|
|
| 1063 | + }
|
|
| 1064 | + } elsif ($input_file->{project} && $t->('project')) {
|
|
| 1065 | + my $p = $t->('project');
|
|
| 1066 | + print "Building project $p - $name\n";
|
|
| 1067 | + my $run_save = $config->{run};
|
|
| 1068 | + $config->{run} = { target => $input_file->{target} };
|
|
| 1069 | + $config->{run}{target} //= $run_save->{target};
|
|
| 1070 | + build_pkg($p, {%$options, origin_project => $project,
|
|
| 1071 | + %$input_file});
|
|
| 1072 | + $config->{run} = $run_save;
|
|
| 1073 | + print "Finished build of project $p - $name\n";
|
|
| 1074 | + } else {
|
|
| 1075 | + dd $input_file;
|
|
| 1076 | + exit_error "Missing file $name";
|
|
| 1054 | 1077 | }
|
| 1055 | - } elsif ($input_file->{project} && $t->('project')) {
|
|
| 1056 | - my $p = $t->('project');
|
|
| 1057 | - print "Building project $p - $name\n";
|
|
| 1058 | - my $run_save = $config->{run};
|
|
| 1059 | - $config->{run} = { target => $input_file->{target} };
|
|
| 1060 | - $config->{run}{target} //= $run_save->{target};
|
|
| 1061 | - build_pkg($p, {%$options, origin_project => $project,
|
|
| 1062 | - %$input_file});
|
|
| 1063 | - $config->{run} = $run_save;
|
|
| 1064 | - print "Finished build of project $p - $name\n";
|
|
| 1065 | - } else {
|
|
| 1066 | - dd $input_file;
|
|
| 1067 | - exit_error "Missing file $name";
|
|
| 1078 | + ($fname) = file_in_dir($name, $src_dir, $proj_out_dir,
|
|
| 1079 | + @modules_common_dirs);
|
|
| 1080 | + exit_error "Error getting file $name" unless $fname;
|
|
| 1068 | 1081 | }
|
| 1069 | - ($fname) = file_in_dir($name, $src_dir, $proj_out_dir,
|
|
| 1070 | - @modules_common_dirs);
|
|
| 1071 | - exit_error "Error getting file $name" unless $fname;
|
|
| 1072 | 1082 | }
|
| 1083 | + if ($action eq 'getfids') {
|
|
| 1084 | + my $if_name = $t->('name') if $input_file->{name};
|
|
| 1085 | + next unless $if_name;
|
|
| 1086 | + $res_getfids{$if_name} = sub {
|
|
| 1087 | + $dl_file->();
|
|
| 1088 | + return input_file_id($input_file, $t, $fname, $name);
|
|
| 1089 | + };
|
|
| 1090 | + next;
|
|
| 1091 | + }
|
|
| 1092 | + $dl_file->();
|
|
| 1073 | 1093 | if ($action eq 'input_files_id') {
|
| 1074 | 1094 | $input_files_id .= input_file_id($input_file, $t, $fname, $name);
|
| 1075 | 1095 | $input_files_id .= "\n";
|
| ... | ... | @@ -1145,6 +1165,7 @@ sub input_files { |
| 1145 | 1165 | return @res_copy if ($action eq 'copy' || $action eq 'link');
|
| 1146 | 1166 | return \%res_getfnames if $action eq 'getfnames';
|
| 1147 | 1167 | return \@res_getfpaths if $action eq 'getfpaths';
|
| 1168 | + return \%res_getfids if $action eq 'getfids';
|
|
| 1148 | 1169 | }
|
| 1149 | 1170 | |
| 1150 | 1171 | sub system_log {
|
| ... | ... | @@ -114,6 +114,12 @@ our %default_config = ( |
| 114 | 114 | projects_dir => 'projects',
|
| 115 | 115 | modules_dir => 'modules',
|
| 116 | 116 | output_dir => 'out',
|
| 117 | + # `getting_id_value/output_dir` is used as `output_dir` when processing
|
|
| 118 | + # template. To avoid having ids being affected by changing `output_dir`,
|
|
| 119 | + # a fixed value is returned when `getting_id` is set.
|
|
| 120 | + getting_id_value => {
|
|
| 121 | + output_dir => '[% IF c("getting_id"); GET "/out"; ELSE; GET c("output_dir"); END %]',
|
|
| 122 | + },
|
|
| 117 | 123 | git_clone_dir => 'git_clones',
|
| 118 | 124 | hg_clone_dir => 'hg_clones',
|
| 119 | 125 | hg_clone_subdir => '.',
|
| ... | ... | @@ -122,7 +128,7 @@ our %default_config = ( |
| 122 | 128 | build => '[% INCLUDE build -%]',
|
| 123 | 129 | build_log => '-',
|
| 124 | 130 | build_log_append => '1',
|
| 125 | - notmpl => [ qw(projects_dir modules_dir) ],
|
|
| 131 | + notmpl => [ qw(projects_dir modules_dir getting_id) ],
|
|
| 126 | 132 | abbrev_length => '12',
|
| 127 | 133 | abbrev => '[%
|
| 128 | 134 | IF c("git_url");
|
| ... | ... | @@ -626,6 +632,7 @@ ZIP_END |
| 626 | 632 | touch => "[% USE date %]touch -m -t [% date.format(c('timestamp'), format = '%Y%m%d%H%M') %]",
|
| 627 | 633 | arch => \&get_arch,
|
| 628 | 634 | input_files_by_name => sub { RBM::input_files('getfnames', @_); },
|
| 635 | + input_files_ids_by_name => sub { RBM::input_files('getfids', @_); },
|
|
| 629 | 636 | input_files_id => sub { RBM::input_files('input_files_id', @_); },
|
| 630 | 637 | input_files_paths => sub { RBM::input_files('getfpaths', @_); },
|
| 631 | 638 | link_input_files => '[% IF c("remote_exec") %]1[% END %]',
|