diff options
author | Ivan Komissarov <abbapoh@gmail.com> | 2022-07-31 02:59:08 +0300 |
---|---|---|
committer | Ivan Komissarov <ABBAPOH@gmail.com> | 2022-08-05 08:22:45 +0000 |
commit | 3e0553e4651197e61c5086d96048b75462bde897 (patch) | |
tree | d95e9f080c4d499c8ecc5d0fd2f0fff67f60d5d4 | |
parent | 235bb0a2b96d5c93a15641d152da30ce769f39f9 (diff) |
qbspkgconfig: fix handling empty variablesv1.23.1
Variables should be allowed to be set to empty values,
only missing variables should produce errors.
Fixes: QBS-1702
Change-Id: Ib9aac611a578a3673fb8201099a707e5842fd750
Reviewed-by: Kai Dohmen <psykai1993@googlemail.com>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r-- | changelogs/changes-1.23.1.md | 1 | ||||
-rw-r--r-- | src/lib/pkgconfig/pcparser.cpp | 4 | ||||
-rw-r--r-- | src/lib/pkgconfig/pkgconfig.cpp | 19 | ||||
-rw-r--r-- | src/lib/pkgconfig/pkgconfig.h | 3 | ||||
-rw-r--r-- | tests/auto/pkgconfig/testdata/empty-variable.json | 21 | ||||
-rw-r--r-- | tests/auto/pkgconfig/testdata/empty-variable.pc | 13 | ||||
-rw-r--r-- | tests/auto/pkgconfig/tst_pkgconfig.cpp | 2 |
7 files changed, 51 insertions, 12 deletions
diff --git a/changelogs/changes-1.23.1.md b/changelogs/changes-1.23.1.md index 7b936f313..65536bfeb 100644 --- a/changelogs/changes-1.23.1.md +++ b/changelogs/changes-1.23.1.md @@ -11,6 +11,7 @@ # Other modules * Fixed protobuf linking on macOS 11. +* Fixed handling empty variables in qbspkgconfig (QBS-1702) # Contributors * Christian Kandeler diff --git a/src/lib/pkgconfig/pcparser.cpp b/src/lib/pkgconfig/pcparser.cpp index cc8b0ae69..388363af6 100644 --- a/src/lib/pkgconfig/pcparser.cpp +++ b/src/lib/pkgconfig/pcparser.cpp @@ -475,10 +475,10 @@ std::string PcParser::trimAndSubstitute(const PcPackage &pkg, std::string_view s const auto varval = m_pkgConfig.packageGetVariable(pkg, varname); - if (varval.empty()) + if (!varval) raizeUndefinedVariableException(pkg, varname); - result += varval; + result += *varval; } else { result += str.front(); str.remove_prefix(1); diff --git a/src/lib/pkgconfig/pkgconfig.cpp b/src/lib/pkgconfig/pkgconfig.cpp index 856c871bf..b2c3d4d71 100644 --- a/src/lib/pkgconfig/pkgconfig.cpp +++ b/src/lib/pkgconfig/pkgconfig.cpp @@ -217,16 +217,17 @@ const PcPackageVariant &PkgConfig::getPackage(std::string_view baseFileName) con return *it; } -std::string_view PkgConfig::packageGetVariable(const PcPackage &pkg, std::string_view var) const +std::optional<std::string_view> PkgConfig::packageGetVariable( + const PcPackage &pkg, std::string_view var) const { - std::string_view varval; + std::optional<std::string_view> result; if (var.empty()) - return varval; + return result; const auto &globals = m_options.globalVariables; if (auto it = globals.find(var); it != globals.end()) - varval = it->second; + result = it->second; // Allow overriding specific variables using an environment variable of the // form PKG_CONFIG_$PACKAGENAME_$VARIABLE @@ -234,15 +235,15 @@ std::string_view PkgConfig::packageGetVariable(const PcPackage &pkg, std::string const std::string envVariable = varToEnvVar(pkg.baseFileName, var); const auto it = m_options.systemVariables.find(envVariable); if (it != m_options.systemVariables.end()) - return it->second; + result = it->second; } - if (varval.empty()) { - const auto it = pkg.variables.find(var); - varval = (it != pkg.variables.end()) ? it->second : std::string_view(); + if (!result) { + if (const auto it = pkg.variables.find(var); it != pkg.variables.end()) + result = it->second; } - return varval; + return result; } #if HAS_STD_FILESYSTEM diff --git a/src/lib/pkgconfig/pkgconfig.h b/src/lib/pkgconfig/pkgconfig.h index 6da1f053f..c1cc634e3 100644 --- a/src/lib/pkgconfig/pkgconfig.h +++ b/src/lib/pkgconfig/pkgconfig.h @@ -72,7 +72,8 @@ public: const Packages &packages() const { return m_packages; } const PcPackageVariant &getPackage(std::string_view baseFileName) const; - std::string_view packageGetVariable(const PcPackage &pkg, std::string_view var) const; + std::optional<std::string_view> packageGetVariable( + const PcPackage &pkg, std::string_view var) const; private: Packages findPackages() const; diff --git a/tests/auto/pkgconfig/testdata/empty-variable.json b/tests/auto/pkgconfig/testdata/empty-variable.json new file mode 100644 index 000000000..b96689979 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/empty-variable.json @@ -0,0 +1,21 @@ +{ + "Name": "Empty Variable test", + "Description": "Checks that empty variables are handled correcty", + "Version": "1.0.0", + "Vars": { + "rootprefix": "", + "prefix": "/usr", + "exec_prefix": "//usr", + "libdir": "//usr/lib", + "includedir": "//usr/include" + }, + "Libs": [ + {"Type": "LibraryName", "Value": "simple"} + ], + "LibsPrivate": [ + {"Type": "LibraryName", "Value": "m"} + ], + "Cflags": [ + {"Type": "IncludePath", "Value": "//usr/include"} + ] +} diff --git a/tests/auto/pkgconfig/testdata/empty-variable.pc b/tests/auto/pkgconfig/testdata/empty-variable.pc new file mode 100644 index 000000000..581382b7e --- /dev/null +++ b/tests/auto/pkgconfig/testdata/empty-variable.pc @@ -0,0 +1,13 @@ +rootprefix= +prefix=/usr +exec_prefix=${rootprefix}/${prefix} +libdir=${exec_prefix}/lib +includedir=${rootprefix}/${prefix}/include + +Name: Empty Variable test +Description: Checks that empty variables are handled correcty +Version: 1.0.0 +Requires: +Libs: -lsimple +Libs.private: -lm +Cflags: -I${includedir} diff --git a/tests/auto/pkgconfig/tst_pkgconfig.cpp b/tests/auto/pkgconfig/tst_pkgconfig.cpp index ec62e1a7f..220e54e7a 100644 --- a/tests/auto/pkgconfig/tst_pkgconfig.cpp +++ b/tests/auto/pkgconfig/tst_pkgconfig.cpp @@ -168,6 +168,8 @@ void TestPkgConfig::pkgConfig_data() QTest::addColumn<QString>("jsonFileName"); QTest::addColumn<QVariantMap>("optionsMap"); + QTest::newRow("empty-variable") + << QStringLiteral("empty-variable") << QString() << QVariantMap(); QTest::newRow("non-l-required") << QStringLiteral("non-l-required") << QString() << QVariantMap(); QTest::newRow("simple") |