summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorIvan Komissarov <abbapoh@gmail.com>2022-07-31 02:59:08 +0300
committerIvan Komissarov <ABBAPOH@gmail.com>2022-08-05 08:22:45 +0000
commit3e0553e4651197e61c5086d96048b75462bde897 (patch)
treed95e9f080c4d499c8ecc5d0fd2f0fff67f60d5d4 /src/lib
parent235bb0a2b96d5c93a15641d152da30ce769f39f9 (diff)
downloadqbs-3e0553e4651197e61c5086d96048b75462bde897.tar.gz
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>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/pkgconfig/pcparser.cpp4
-rw-r--r--src/lib/pkgconfig/pkgconfig.cpp19
-rw-r--r--src/lib/pkgconfig/pkgconfig.h3
3 files changed, 14 insertions, 12 deletions
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;