gen_config: allow options to be overridden by environment

From caa2cd968be140ed3e91eeb0d30e0c006b55e17a Mon Sep 17 00:00:00 2001
From: Daniel Hermann <daniel.hermann@1und1.de>
Date: Thu, 11 Jul 2013 11:45:16 +0200
Subject: [PATCH] gen_config: allow options to be overridden by environment
This commit is contained in:
Daniel Hermann 2013-07-11 15:16:44 +02:00 committed by Thomas Schoebel-Theuer
parent d70a415b9a
commit 5eae58a3a4
1 changed files with 9 additions and 0 deletions

View File

@ -16,11 +16,14 @@ my $DEBUG = 0;
my $option; my $option;
my $type; my $type;
my @default; my @default;
my %setByEnv;
while (my $line = <STDIN>) { while (my $line = <STDIN>) {
if ($line =~ /^config\s+(\w+)\W*$/) { if ($line =~ /^config\s+(\w+)\W*$/) {
$option = $1; $option = $1;
$setByEnv{$option} = $ENV{$option} if exists $ENV{$option};
printf STDERR "OPTION: %s\n", $option if $DEBUG; printf STDERR "OPTION: %s\n", $option if $DEBUG;
printf STDERR "ENV: %s='%s'\n", $option, $setByEnv{$option} if $DEBUG && exists $ENV{$option};
} }
elsif ($line =~ /^\s+(tristate|bool|int|string)\s+.*$/) { elsif ($line =~ /^\s+(tristate|bool|int|string)\s+.*$/) {
$type = $1; $type = $1;
@ -79,6 +82,12 @@ foreach my $opt (@default) {
my $optname = $opt->{option}; my $optname = $opt->{option};
my $optval = $opt->{value}; my $optval = $opt->{value};
if (exists $setByEnv{$optname}) {
print qq%
/* CONFIG_$optname overridden by ENVIRONMENT */%;
$optval = $setByEnv{$optname};
}
if (!defined($optname) || !defined($optval)) { if (!defined($optname) || !defined($optval)) {
printf(STDERR "SKIPPED option due to missing parameters: optname=%s optval=%s\n", printf(STDERR "SKIPPED option due to missing parameters: optname=%s optval=%s\n",
$optname||'', $optval||''); $optname||'', $optval||'');