From f9c6da38f70d9bf95937a5de8269e0f8d52600a4 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 4 Feb 2019 09:55:46 +0100 Subject: qt5_tool: Add the ability to reference arbitrary config keys by $(name) This should help to clean up the config files considerably. Change-Id: I8c994f4b1654bd5ec648715b3ccdbdd4e02a6fca Reviewed-by: Cristian Maureira-Fredes Reviewed-by: Edward Welbourne --- bin/qt5_tool | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bin/qt5_tool b/bin/qt5_tool index 68fda17..1f2cdb2 100755 --- a/bin/qt5_tool +++ b/bin/qt5_tool @@ -99,6 +99,12 @@ specifies that for a checkout in '/home/user/qt-5', shadow builds are to be done in '/home/user/qt-5-build'. It is overridden by a value for the checkout '/home/user/qt-5special', which would result in '/home/user/qt-5-special-build' Continuation lines are indicated by a trailing backslash (\\). + +Arbitrary keys can be defined and referenced by \$(name): + +skipDefault=qtcanvas3d qtcharts... +skip=\$(skipDefault) +skip-qt-minimalbuild=\$(skipDefault) qtdatavis3d... EOF # --------------- Detect OS @@ -334,6 +340,22 @@ sub runGitAllModules return $runRC; } +# ---- Expand references to other keys in config files "$(name)" by value. + +sub expandReferences +{ + my ($hashRef, $line) = @_; + while ($line =~ /\$\([^)]+\)/) { + my $matchStart = $-[0]; + my $matchEnd = $+[0]; + my $varName = substr($line, $matchStart + 2, $matchEnd - $matchStart - 3); + my $value = $$hashRef{$varName}; + die ('Undefined variable ' . $varName . ' while expanding: ' . $line) unless defined($value); + substr($line, $matchStart, $matchEnd - $matchStart, $value); + } + return $line; +} + # ---- Read a value from a configuration file of the form key=value # and return an anonymous hash. @@ -354,7 +376,7 @@ sub readConfigFile chomp($line); $value .= $line; } - $$result{$key} = $value; + $$result{$key} = expandReferences($result, $value); } } $f->close(); -- cgit v1.2.3