aboutsummaryrefslogtreecommitdiff
path: root/src/PkgConfig.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/PkgConfig.cpp')
-rw-r--r--src/PkgConfig.cpp83
1 files changed, 18 insertions, 65 deletions
diff --git a/src/PkgConfig.cpp b/src/PkgConfig.cpp
index 89d3a44..73df008 100644
--- a/src/PkgConfig.cpp
+++ b/src/PkgConfig.cpp
@@ -27,28 +27,25 @@ namespace sibs
pkgConfigPath = path;
}
- Result<bool> PkgConfig::validatePkgConfigPackageVersionExists(PackageListDependency *dependency)
+ Result<bool> PkgConfig::validatePkgConfigPackageVersionExists(const PackageListDependency &dependency)
{
- Result<bool> dependencyValidationResult = PkgConfig::validatePackageExists(dependency->name);
+ Result<bool> dependencyValidationResult = PkgConfig::validatePackageExists(dependency.name);
if(dependencyValidationResult.isErr())
return Result<bool>::Err(dependencyValidationResult.getErrMsg());
- Result<PackageVersion> dependencyVersionResult = PkgConfig::getPackageVersion(dependency->name);
+ Result<PackageVersion> dependencyVersionResult = PkgConfig::getPackageVersion(dependency.name);
if(!dependencyVersionResult)
return Result<bool>::Err(dependencyVersionResult);
- if(!dependency->version.isInRange(dependencyVersionResult.unwrap()))
- return Result<bool>::Err("pkg-config package " + dependency->name + " exists but the version does not match our expected version range");
+ if(!dependency.version.isInRange(dependencyVersionResult.unwrap()))
+ return Result<bool>::Err("pkg-config package " + dependency.name + " exists but the version does not match our expected version range");
return Result<bool>::Ok(true);
}
Result<bool> PkgConfig::validatePackageExists(const string &name)
{
- FileString command = pkgConfigPath + TINYDIR_STRING(" --exists '");
- command += toFileString(name);
- command += TINYDIR_STRING("'");
- Result<ExecResult> execResult = exec(command.c_str());
+ Result<ExecResult> execResult = exec({ pkgConfigPath, TINYDIR_STRING("--exists"), TINYDIR_STRING("--"), toFileString(name) });
if(execResult.isErr())
return Result<bool>::Err(execResult.getErrMsg());
@@ -72,45 +69,9 @@ namespace sibs
return Result<bool>::Ok(true);
}
- Result<bool> PkgConfig::validatePackageVersionAtLeast(const string &name, const string &version)
- {
- FileString command = pkgConfigPath + TINYDIR_STRING(" '--atleast-version=");
- command += toFileString(version);
- command += TINYDIR_STRING("' '");
- command += toFileString(name);
- command += TINYDIR_STRING("'");
- Result<ExecResult> execResult = exec(command.c_str());
- if(execResult.isErr())
- return Result<bool>::Err(execResult.getErrMsg());
-
- if(execResult.unwrap().exitCode == 1)
- {
- string errMsg = "Dependency ";
- errMsg += name;
- errMsg += " is installed but the version older than ";
- errMsg += version;
- return Result<bool>::Err(errMsg);
- }
- else if(execResult.unwrap().exitCode == 127)
- {
- return Result<bool>::Err("pkg-config is not installed");
- }
- else if(execResult.unwrap().exitCode != 0)
- {
- string errMsg = "Failed to check pkg-config package version, Unknown error, exit code: ";
- errMsg += to_string(execResult.unwrap().exitCode);
- return Result<bool>::Err(errMsg);
- }
-
- return Result<bool>::Ok(true);
- }
-
Result<PackageVersion> PkgConfig::getPackageVersion(const std::string &name)
{
- FileString command = pkgConfigPath + TINYDIR_STRING(" --modversion '");
- command += toFileString(name);
- command += TINYDIR_STRING("'");
- Result<ExecResult> execResult = exec(command.c_str());
+ Result<ExecResult> execResult = exec({ pkgConfigPath, TINYDIR_STRING("--modversion"), TINYDIR_STRING("--"), toFileString(name) });
if(!execResult)
return Result<PackageVersion>::Err(execResult.getErrMsg());
@@ -136,21 +97,17 @@ namespace sibs
return parsePackageVersion({ execResult.unwrap().execStdout.data(), execResult.unwrap().execStdout.size() }, nullptr);
}
- Result<string> PkgConfig::getDynamicLibsLinkerFlags(const vector<PackageListDependency*> &libs)
+ Result<string> PkgConfig::getDynamicLibsLinkerFlags(const vector<PackageListDependency> &libs)
{
if(libs.empty()) return Result<string>::Ok("");
- string args;
- for(PackageListDependency *lib : libs)
+ std::vector<FileString> args = { pkgConfigPath, TINYDIR_STRING("--libs"), TINYDIR_STRING("--") };
+ for(const PackageListDependency &lib : libs)
{
- args += " '";
- args += lib->name;
- args += "'";
+ args.push_back(toFileString(lib.name));
}
- FileString command = pkgConfigPath + TINYDIR_STRING(" --libs");
- command += toFileString(args);
- Result<ExecResult> execResult = exec(command.c_str());
+ Result<ExecResult> execResult = exec(args);
if(execResult.isErr())
return Result<string>::Err(execResult.getErrMsg());
@@ -179,21 +136,17 @@ namespace sibs
}
}
- Result<string> PkgConfig::getDynamicLibsCflags(const vector<PackageListDependency*> &libs)
+ Result<string> PkgConfig::getDynamicLibsCflags(const vector<PackageListDependency> &libs)
{
if(libs.empty()) return Result<string>::Ok("");
- string args;
- for(PackageListDependency *lib : libs)
+ std::vector<FileString> args = { pkgConfigPath, TINYDIR_STRING("--cflags"), TINYDIR_STRING("--") };
+ for(const PackageListDependency &lib : libs)
{
- args += " '";
- args += lib->name;
- args += "'";
+ args.push_back(toFileString(lib.name));
}
- FileString command = pkgConfigPath + TINYDIR_STRING(" --cflags");
- command += toFileString(args);
- Result<ExecResult> execResult = exec(command.c_str());
+ Result<ExecResult> execResult = exec(args);
if(execResult.isErr())
return Result<string>::Err(execResult.getErrMsg());
@@ -222,7 +175,7 @@ namespace sibs
}
}
- Result<PkgConfigFlags> PkgConfig::getDynamicLibsFlags(const vector<PackageListDependency*> &libs)
+ Result<PkgConfigFlags> PkgConfig::getDynamicLibsFlags(const vector<PackageListDependency> &libs)
{
PkgConfigFlags flags;