commit a57b4846c8aba5697ce1f197996e2962ffb5b534 Author: Nicolas Vigier boklm@torproject.org Date: Tue Feb 14 00:28:45 2017 +0100
Add support for optional local configuration file rbm.local.conf --- NEWS | 2 ++ doc/rbm_cli.asc | 3 +++ doc/rbm_config.asc | 29 ++++++++++++++++++++++++++--- lib/RBM.pm | 10 +++++++++- lib/RBM/DefaultConfig.pm | 1 + rbm | 3 ++- 6 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/NEWS b/NEWS index 82890a5..1a1789f 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +- Add support for optional local configuration file rbm.local.conf + - add the git_submodule option
- add the hg_opt option diff --git a/doc/rbm_cli.asc b/doc/rbm_cli.asc index 92b84ef..66f6025 100644 --- a/doc/rbm_cli.asc +++ b/doc/rbm_cli.asc @@ -31,6 +31,9 @@ The following options can be set on the command line : --sysconf-file=<file>:: Set the optional system configuration file path
+ --localconf-file=<file>:: + Set the optional local configuration file path + --target=<target>:: Set the target. This option can be used multiple times to use more than one target. See link:rbm_targets.html[rbm_targets(7)] for diff --git a/doc/rbm_config.asc b/doc/rbm_config.asc index 27b8f7a..e8decd9 100644 --- a/doc/rbm_config.asc +++ b/doc/rbm_config.asc @@ -8,11 +8,13 @@ rbm_config - The rbm configuration DESCRIPTION -----------
-All configuration options can be defined in 3 different places : +All configuration options can be defined in 5 different places :
-- in the main configuration in your working directory +- in the main configuration in your working directory (+rbm.conf+)
-- in the global system configuration +- in the local configuration in your working directory (+rbm.local.conf+) + +- in the global system configuration (+/etc/rbm.conf+)
- in a project configuration
@@ -30,6 +32,14 @@ The option values are used with the following priority order :
- project config
+- local config for matching step and target + +- local config for matching step + +- local config for matching target + +- local config + - workspace config for matching step and target
- workspace config for matching step @@ -62,6 +72,13 @@ This is where you will put configuration relevant to all projects under this working directory. All relative paths used in the configuration are relative from the +rbm.conf+ location.
+The local configuration file is +rbm.local.conf+ (or the file defined +by the +localconf_file+ option), in the same directory as the +rbm.conf+ +file. If the file does not exists, it is ignored. The +rbm.local.conf+ +file is used to override some options from +rbm.conf+ relevent to your +local setup, whithout modifying the +rbm.conf+ file which is usually +maintained in a VCS. + An example +rbm.conf+ file will look like this :
---- @@ -89,6 +106,12 @@ sysconf_file:: is +/etc/rbm.conf+. This can also be set with the --sysconf-file command line parameter.
+localconf_file:: + The path to an optional local configuration file. The default + is +rbm.local.conf+. If the path is relative, it is relative to + the directory where the +rbm.conf+ file is located. This can + also be set with the --localconf-file command line parameter. + projects_dir:: The directory containing the projects definitions. The default value is +projects+. diff --git a/lib/RBM.pm b/lib/RBM.pm index ad39526..4b5bfe9 100644 --- a/lib/RBM.pm +++ b/lib/RBM.pm @@ -61,6 +61,13 @@ sub load_system_config { $config->{system} = -f $cfile ? load_config_file($cfile) : {}; }
+sub load_local_config { + my ($project) = @_; + my $cfile = project_config($project ? $project : 'undef', 'localconf_file'); + $cfile = path($cfile); + $config->{local} = -f $cfile ? load_config_file($cfile) : {}; +} + sub find_config_file { for (my $dir = getcwd; $dir ne '/'; $dir = dirname($dir)) { return "$dir/rbm.conf" if -f "$dir/rbm.conf"; @@ -209,7 +216,8 @@ sub project_config { my $opt_save = $config->{opt}; $config->{opt} = { %{$config->{opt}}, %$options } if $options; $res = config($project, $name, $options, ['opt'], ['run'], - ['projects', $project], [], ['system'], ['default']); + ['projects', $project], ['local'], [], + ['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 8172f04..052cf16 100644 --- a/lib/RBM/DefaultConfig.pm +++ b/lib/RBM/DefaultConfig.pm @@ -103,6 +103,7 @@ sub docker_version {
our %default_config = ( sysconf_file => '/etc/rbm.conf', + localconf_file=> 'rbm.local.conf', tmp_dir => '[% GET ENV.TMPDIR ? ENV.TMPDIR : "/tmp"; %]', projects_dir => 'projects', output_dir => 'out', diff --git a/rbm b/rbm index 52f3076..c618ada 100755 --- a/rbm +++ b/rbm @@ -95,7 +95,7 @@ sub set_options { gpg-keyring=s gpg-keyring-dir=s gpg-args=s gpg-bin=s sysconf-file=s debsign-keyid=s use-pbuilder! step=s target=s@ publish-src-dir=s debug! hg-clone-dir=s - hg-hash=s); + hg-hash=s localconf-file=s); my %val; Getopt::Long::GetOptionsFromArray(@_, %val, @options) || exit 1; foreach my $k (keys %val) { @@ -108,6 +108,7 @@ sub set_options { $RBM::config->{run}{$l} = $val{$k}; } RBM::load_system_config(@_); + RBM::load_local_config(@_); return $RBM::config->{run}{args} = @_; }