aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Conf.cpp83
-rw-r--r--src/GlobalLib.cpp15
-rw-r--r--src/Package.cpp23
-rw-r--r--src/Platform.cpp44
-rw-r--r--src/main.cpp4
5 files changed, 80 insertions, 89 deletions
diff --git a/src/Conf.cpp b/src/Conf.cpp
index 2fdef25..c93f830 100644
--- a/src/Conf.cpp
+++ b/src/Conf.cpp
@@ -491,16 +491,6 @@ namespace sibs
return parseResult;
}
-
- bool containsPlatform(const vector<Platform> &platforms, Platform platform)
- {
- for (Platform vecPlatform : platforms)
- {
- if (vecPlatform == platform || vecPlatform == PLATFORM_ANY)
- return true;
- }
- return false;
- }
void readSibsConfig(const FileString &projectPath, const FileString &projectConfFilePath, SibsConfig &sibsConfig, FileString &buildPath)
{
@@ -523,21 +513,6 @@ namespace sibs
}
}
- const char* asString(Platform platform)
- {
- switch (platform)
- {
- case PLATFORM_ANY: return "any";
- case PLATFORM_LINUX32: return "linux32";
- case PLATFORM_LINUX64: return "linux64";
- case PLATFORM_WIN32: return "win32";
- case PLATFORM_WIN64: return "win64";
- case PLATFORM_MACOS32: return "macos32";
- case PLATFORM_MACOS64: return "macos64";
- default: return nullptr;
- }
- }
-
const char* asString(OptimizationLevel optLevel)
{
switch(optLevel)
@@ -666,6 +641,23 @@ namespace sibs
});
}
+ static string combineSupportedPlatformsAsString()
+ {
+ string result;
+ int i = 0;
+ int size = PLATFORM_BY_NAME.size();
+ for(const auto &it : PLATFORM_BY_NAME)
+ {
+ if(i > 0 && i == size - 1)
+ result += " or ";
+ else if(i > 0)
+ result += ", ";
+ result += it.second;
+ ++i;
+ }
+ return result;
+ }
+
void SibsConfig::processObject(StringView name)
{
currentObject = name;
@@ -783,47 +775,16 @@ namespace sibs
for (const StringView &platform : value.asList())
{
- if (platform.equals("any"))
- {
- platforms.push_back(PLATFORM_ANY);
- }
- else if (platform.equals("linux32"))
- {
- platforms.push_back(PLATFORM_LINUX32);
- }
- else if (platform.equals("linux64"))
- {
- platforms.push_back(PLATFORM_LINUX64);
- }
- else if (platform.equals("win32"))
- {
- platforms.push_back(PLATFORM_WIN32);
- }
- else if (platform.equals("win64"))
- {
- platforms.push_back(PLATFORM_WIN64);
- }
- else if (platform.equals("macos32"))
- {
- platforms.push_back(PLATFORM_MACOS32);
- }
- else if (platform.equals("macos64"))
- {
- platforms.push_back(PLATFORM_MACOS64);
- }
- else if (platform.equals("openbsd32"))
- {
- platforms.push_back(PLATFORM_OPENBSD32);
- }
- else if (platform.equals("openbsd64"))
+ Platform platformType = getPlatformByName(platform);
+ if (platformType != PLATFORM_INVALID)
{
- platforms.push_back(PLATFORM_OPENBSD64);
+ platforms.push_back(platformType);
}
else
{
string errMsg = "package.platforms contains invalid platform \"";
errMsg += string(platform.data, platform.size);
- errMsg += "\". Expected platform to be one of: any, linux32, linux64, win32, win64, macos32, macos64, openbsd32 or openbsd64";
+ errMsg += "\". Expected platform to be one of: " + combineSupportedPlatformsAsString();
throw ParserException(errMsg);
}
}
@@ -1177,9 +1138,11 @@ namespace sibs
validConfig = true;
switch(i)
{
+ case CONFIG_GENERIC_STATIC_DEBUG_PLATFORM:
case CONFIG_STATIC_DEBUG_PLATFORM:
parsePlatformConfigStaticDebug(fieldName, fieldValue);
break;
+ case CONFIG_GENERIC_STATIC_RELEASE_PLATFORM:
case CONFIG_STATIC_RELEASE_PLATFORM:
parsePlatformConfigStaticRelease(fieldName, fieldValue);
break;
diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp
index 9921c1b..916ba3e 100644
--- a/src/GlobalLib.cpp
+++ b/src/GlobalLib.cpp
@@ -205,9 +205,6 @@ namespace sibs
if (result.isErr())
return result;
- if(sibsConfig.getPackageName().empty())
- return Result<bool>::Err("project.conf is missing required field package.name");
-
if(sibsConfig.getPackageType() == PackageType::EXECUTABLE)
{
string errMsg = "The dependency ";
@@ -215,16 +212,6 @@ namespace sibs
errMsg += " is an executable. Only libraries can be dependencies";
return Result<bool>::Err(errMsg);
}
-
- if (!containsPlatform(sibsConfig.getPlatforms(), SYSTEM_PLATFORM))
- {
- string errMsg = "The dependency ";
- errMsg += dependencyName;
- errMsg += " does not support your platform (";
- errMsg += asString(SYSTEM_PLATFORM);
- errMsg += ")";
- return Result<bool>::Err(errMsg);
- }
FileString buildPath = packageDir + TINYDIR_STRING("/sibs-build/");
switch (sibsConfig.getOptimizationLevel())
@@ -272,7 +259,7 @@ namespace sibs
Result<bool> GlobalLib::downloadDependency(PackageListDependency *dependency)
{
- Result<string> packageUrlResult = Package::getPackageUrl(dependency->name.c_str(), dependency->version.c_str(), SYSTEM_PLATFORM_NAME);
+ Result<string> packageUrlResult = Package::getPackageUrl(dependency->name.c_str(), dependency->version.c_str(), SYSTEM_PLATFORM);
if(!packageUrlResult)
return Result<bool>::Err(packageUrlResult);
diff --git a/src/Package.cpp b/src/Package.cpp
index 9ba26cd..6773265 100644
--- a/src/Package.cpp
+++ b/src/Package.cpp
@@ -13,19 +13,18 @@ static Document *packageList = nullptr;
namespace sibs
{
- // TODO: Use containsPlatform in Conf.hpp instead? dont need a vector of string when we can use vector of enum
- bool containsPlatform(const vector<string> &supportedPlatforms, const char *platform)
+ static vector<Platform> getPlatformsByNames(const vector<string> &platformNames)
{
- for(const string &supportedPlatform : supportedPlatforms)
+ vector<Platform> result;
+ result.reserve(platformNames.size());
+ for(const string &platformName : platformNames)
{
- if(strcmp(supportedPlatform.c_str(), platform) == 0 || strcmp(supportedPlatform.c_str(), "any") == 0)
- return true;
+ result.push_back(getPlatformByName(StringView(platformName.data(), platformName.size())));
}
-
- return false;
+ return result;
}
-
- Result<PackageMetadata> getPackageMetadata(Value::ConstObject jsonObj)
+
+ static Result<PackageMetadata> getPackageMetadata(Value::ConstObject jsonObj)
{
const auto &description = jsonObj.FindMember("description");
if(description == jsonObj.MemberEnd() || !description->value.IsString()) return Result<PackageMetadata>::Err("Expected description to be a string");
@@ -63,7 +62,7 @@ namespace sibs
return Result<PackageMetadata>::Ok(packageMetadata);
}
- Result<string> getPackageUrl(const PackageMetadata &packageMetadata, const char *packageName, const char *packageVersion, const char *platform)
+ static Result<string> getPackageUrl(const PackageMetadata &packageMetadata, const char *packageName, const char *packageVersion, Platform platform)
{
if(strcmp(packageMetadata.version.c_str(), packageVersion) != 0)
{
@@ -75,7 +74,7 @@ namespace sibs
return Result<string>::Err(errMsg);
}
- if(!containsPlatform(packageMetadata.platforms, platform))
+ if(!containsPlatform(getPlatformsByNames(packageMetadata.platforms), platform))
{
string errMsg = "Package \"";
errMsg += packageName;
@@ -121,7 +120,7 @@ namespace sibs
return Result<Document*>::Ok(packageList);
}
- Result<string> Package::getPackageUrl(const char *packageName, const char *packageVersion, const char *platform)
+ Result<string> Package::getPackageUrl(const char *packageName, const char *packageVersion, Platform platform)
{
Result<Document*> packageList = Package::getPackageList("https://gitlab.com/DEC05EBA/sibs_packages/raw/master/packages.json");
if(!packageList)
diff --git a/src/Platform.cpp b/src/Platform.cpp
new file mode 100644
index 0000000..44f42db
--- /dev/null
+++ b/src/Platform.cpp
@@ -0,0 +1,44 @@
+#include "../include/Platform.hpp"
+
+namespace sibs
+{
+ bool containsPlatform(const std::vector<Platform> &platforms, Platform platform)
+ {
+ for (Platform vecPlatform : platforms)
+ {
+ if(platform & vecPlatform)
+ return true;
+ }
+ return false;
+ }
+
+ const char* asString(Platform platform)
+ {
+ switch (platform)
+ {
+ case PLATFORM_ANY: return "any";
+ case PLATFORM_LINUX: return "linux";
+ case PLATFORM_LINUX32: return "linux32";
+ case PLATFORM_LINUX64: return "linux64";
+ case PLATFORM_WIN: return "win";
+ case PLATFORM_WIN32: return "win32";
+ case PLATFORM_WIN64: return "win64";
+ case PLATFORM_MACOS: return "macos";
+ case PLATFORM_MACOS32: return "macos32";
+ case PLATFORM_MACOS64: return "macos64";
+ case PLATFORM_BSD: return "bsd";
+ case PLATFORM_OPENBSD: return "openbsd";
+ case PLATFORM_OPENBSD32: return "openbsd32";
+ case PLATFORM_OPENBSD64: return "openbsd64";
+ default: return nullptr;
+ }
+ }
+
+ Platform getPlatformByName(StringView name)
+ {
+ auto it = PLATFORM_BY_NAME.find(name);
+ if(it != PLATFORM_BY_NAME.end())
+ return it->second;
+ return PLATFORM_INVALID;
+ }
+} \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 110c178..6a330ca 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -653,9 +653,7 @@ static Result<bool> newProjectCreateConf(const string &projectName, const string
projectConfStr += "name = \"" + projectName + "\"\n";
projectConfStr += "type = \"" + projectType + "\"\n";
projectConfStr += "version = \"0.1.0\"\n";
- projectConfStr += "platforms = [\"";
- projectConfStr += asString(SYSTEM_PLATFORM);
- projectConfStr += "\"]\n\n";
+ projectConfStr += "platforms = [\"any\"]\n\n";
projectConfStr += "[dependencies]\n";
FileString projectConfPath = projectPath;