summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-01-17 16:44:53 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-01-18 08:59:50 +0000
commitbb13c8f9ce616e76ef9ec604bb8f26c7a9c00e8d (patch)
treea0010bb88dd384b33fe7ace86ec0ce3310ea5ab3
parentd6f577c2a5e72457ebb768239e6542ab934d5482 (diff)
qt5_tool: Refactor config file reading
The tool opened the file for each branch-specific key and each key. Store the values in a hash instead. Change-Id: I6719e490a4ad78da70e9db0ce8016b0db2ea3ed5 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rwxr-xr-xbin/qt5_tool47
1 files changed, 27 insertions, 20 deletions
diff --git a/bin/qt5_tool b/bin/qt5_tool
index b4c227b..68fda17 100755
--- a/bin/qt5_tool
+++ b/bin/qt5_tool
@@ -334,30 +334,31 @@ sub runGitAllModules
return $runRC;
}
-# ---- Read a value from a configuration file of the form key=value.
+# ---- Read a value from a configuration file of the form key=value
+# and return an anonymous hash.
sub readConfigFile
{
- my ($fileName, $key) = @_;
-
- my $configLine = '';
- my $configFile = new IO::File('<' . $fileName) or return $configLine;
- while (my $line = <$configFile>) {
+ my ($fileName) = @_;
+ my $f = new IO::File('<' . $fileName) or die ('Cannot open ' . $fileName . ': ' . $1);
+ my $result = {};
+ while (my $line = <$f>) {
chomp($line);
- if ($line =~ /^\s*$key\s*=\s*(.*)$/) {
- $configLine .= $1;
- while (index($configLine, '\\') == length($configLine) - 1) { # continuation lines "a=b\", "continued..."
- chop($configLine);
- my $line = <$configFile>;
- die('Trailing continuation line "' . $configLine . '"') unless defined $line;
+ if ($line =~ /^\s*([A-Za-z0-9_\-\.]+)\s*=\s*(.*)$/) {
+ my $key = $1;
+ my $value = $2;
+ while (rindex($value, '\\') == length($value) - 1) { # continuation lines "a=b\", "continued..."
+ chop($value);
+ my $line = <$f>;
+ die('Trailing continuation line "' . $value . '"') unless defined $line;
chomp($line);
- $configLine .= $line;
+ $value .= $line;
}
- last;
+ $$result{$key} = $value;
}
}
- $configFile->close();
- return $configLine;
+ $f->close();
+ return $result;
}
# ---- Read a value from a git config line.
@@ -365,7 +366,10 @@ sub readConfigFile
sub readGitConfig
{
my ($module, $key) = @_;
- return readConfigFile(File::Spec->catfile($rootDir, $module, '.git', 'config'), $key);
+ my $gitConfigFile = File::Spec->catfile($rootDir, $module, '.git', 'config');
+ my $hashRef = readConfigFile($gitConfigFile);
+ my $value = $$hashRef{$key};
+ return defined($value) ? $value : '';
}
# ---- MinGW: Remove git from path (prevent sh.exe from throwing off mingw32-make).
@@ -427,13 +431,16 @@ sub ls
# check for the repo-specific value 'key-qt5' and then for the general
# 'key'.
+my $configHashRef;
+
sub readQt5ToolConfig
{
my ($key) = @_;
+ $configHashRef = readConfigFile($configFile) unless defined($configHashRef);
my $repoKey = $key . '-' . $baseDir;
- my $repoValue = readConfigFile($configFile, $repoKey);
- return $repoValue if $repoValue ne '';
- return readConfigFile($configFile, $key);
+ my $value = $$configHashRef{$key . '-' . $baseDir};
+ $value = $$configHashRef{$key} unless defined($value);
+ return defined($value) ? $value : '';
}
sub readQt5ToolConfigBool