boklm pushed to branch main at The Tor Project / Applications / RBM


Commits:
c88489dd by Nicolas Vigier at 2026-02-11T12:44:50+01:00
Bug 40103: Allow having multiple tmp_dir values

The `rbm_tmp_dir` function (and config option) is used to get a
directory where temporary files can be stored. This directory is
automatically removed when rbm exits, and its location is based on the
`tmp_dir` config option. To return always the same directory and avoid
creating a new one each time, a state variable is used, however that
means that the value of the `tmp_dir` config option is ignored on
following uses of `rbm_tmp_dir`. To fix that we change the state
variable to be a hash variable, using `tmp_dir` as key. So that we
create the temporary directory one time per value of `tmp_dir`.

We are also adding a test to check the temporary directory from which we
build is matching `tmp_dir` when we have two separate projects using a
different value. The test was failing without the change and is now
passing.

- - - - -


5 changed files:

- lib/RBM/DefaultConfig.pm
- test.pl
- + test/projects/tmpdir_t1/config
- + test/projects/tmpdir_t2/config
- + test/projects/tmpdir_t3/config


Changes:

=====================================
lib/RBM/DefaultConfig.pm
=====================================
@@ -88,14 +88,14 @@ sub docker_version {
 
 sub rbm_tmp_dir {
     my ($project, $options) = @_;
-    CORE::state $rbm_tmp_dir;
-    return $rbm_tmp_dir->dirname if $rbm_tmp_dir;
+    CORE::state %rbm_tmp_dir;
     my $tmp_dir = RBM::project_config($project, 'tmp_dir', $options)
                   || RBM::exit_error('No tmp_dir specified');
+    return $rbm_tmp_dir{$tmp_dir}->dirname if $rbm_tmp_dir{$tmp_dir};
     make_path($tmp_dir);
-    $rbm_tmp_dir = File::Temp->newdir(TEMPLATE => 'rbm-XXXXXX',
+    $rbm_tmp_dir{$tmp_dir} = File::Temp->newdir(TEMPLATE => 'rbm-XXXXXX',
                                       DIR => $tmp_dir);
-    return $rbm_tmp_dir->dirname;
+    return $rbm_tmp_dir{$tmp_dir}->dirname;
 }
 
 our %default_config = (


=====================================
test.pl
=====================================
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 use strict;
 use Path::Tiny;
-use Test::More tests => 45;
+use Test::More tests => 46;
 use lib 'lib/';
 
 sub set_target {
@@ -282,6 +282,15 @@ my @tests = (
         target => [ 'wrong_sha512sum' ],
         fail_build  => [ 'shasum', 'build' ],
     },
+    {
+        name   => 'setting different tmp_dir per project',
+        step   => 'build',
+        target => [],
+        build  => [ 'tmpdir_t1', 'build' ],
+        files  => {
+            'out/tmpdir_t1.txt' => "/var/tmp\n/tmp\n",
+        },
+    },
 );
 
 foreach my $test (@tests) {


=====================================
test/projects/tmpdir_t1/config
=====================================
@@ -0,0 +1,11 @@
+filename: tmpdir_t1.txt
+tmp_dir: /tmp
+build: |
+  #!/bin/sh
+  set -e
+  cat tmpdir_t2.txt tmpdir_t3.txt > [% dest_dir %]/[% c('filename') %]
+input_files:
+  - project: tmpdir_t2
+    refresh_input: 1
+  - project: tmpdir_t3
+    refresh_input: 1


=====================================
test/projects/tmpdir_t2/config
=====================================
@@ -0,0 +1,8 @@
+filename: tmpdir_t2.txt
+tmp_dir: /var/tmp
+build: |
+  #!/bin/sh
+  set -e
+  dir=$(dirname $(dirname $(pwd)))
+  test "$dir" = '[% c("tmp_dir") %]'
+  echo "$dir" > [% dest_dir %]/[% c('filename') %]


=====================================
test/projects/tmpdir_t3/config
=====================================
@@ -0,0 +1,8 @@
+filename: tmpdir_t3.txt
+tmp_dir: /tmp
+build: |
+  #!/bin/sh
+  set -e
+  dir=$(dirname $(dirname $(pwd)))
+  test "$dir" = '[% c("tmp_dir") %]'
+  echo "$dir" > [% dest_dir %]/[% c('filename') %]



View it on GitLab: 
https://gitlab.torproject.org/tpo/applications/rbm/-/commit/c88489ddb9c3749fe8bdfd0442a19a3bef346727

-- 
View it on GitLab: 
https://gitlab.torproject.org/tpo/applications/rbm/-/commit/c88489ddb9c3749fe8bdfd0442a19a3bef346727
You're receiving this email because of your account on gitlab.torproject.org.


_______________________________________________
tor-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to