aboutsummaryrefslogtreecommitdiff
path: root/src/Conf.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-10 07:59:51 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:33 +0200
commit7c24c5d0de4d3584d6d2f9f3c26b4d757b0a0df2 (patch)
tree81585a1be9126c4bc1be946e74b4b6e1d706279b /src/Conf.cpp
parent6b238d4bc3c142f6337a73d858e069cae778dc54 (diff)
Fix sibs test not including parent library correctly
Refactor config parsing to reduce number of changes when introducing a new platform to support
Diffstat (limited to 'src/Conf.cpp')
-rw-r--r--src/Conf.cpp190
1 files changed, 117 insertions, 73 deletions
diff --git a/src/Conf.cpp b/src/Conf.cpp
index 38774e0..0307bc0 100644
--- a/src/Conf.cpp
+++ b/src/Conf.cpp
@@ -80,8 +80,12 @@ namespace sibs
char *startOfIdentifier = code.base();
++code;
c = *code;
+ char prevChar = '\0';
while(isIdentifierChar(c))
{
+ if(c == '.' && prevChar == '.')
+ throw UnexpectedTokenException("Identifier can't have two dots in a row");
+ prevChar = c;
++code;
c = *code;
}
@@ -863,59 +867,12 @@ namespace sibs
}
else if(currentObject.size >= 6 && strncmp(currentObject.data, "config", 6) == 0)
{
- bool platformConfig = currentObject.equals(CONFIGS[CONFIG_SYSTEM_PLATFORM]);
- if(currentObject.size == 6 || platformConfig) // [config]
+ if(currentObject.size == 6) // [config]
{
- if(name.equals("expose_include_dirs"))
- {
- if (value.isList())
- {
- for (const StringView &includeDir : value.asList())
- {
- exposeIncludeDirs.emplace_back(string(includeDir.data, includeDir.size));
- }
- }
- else
- {
- string errMsg = "Expected ";
- errMsg += string(currentObject.data, currentObject.size);
- errMsg += " to be a list, was a single value";
- throw ParserException(errMsg);
- }
- }
- else if(name.equals("include_dirs"))
- {
- if(value.isList())
- {
- for(const StringView &includeDir : value.asList())
- {
- includeDirs.emplace_back(string(includeDir.data, includeDir.size));
- }
- }
- else
- throw ParserException("Expected " + string(currentObject.data, currentObject.size) + ".include_dirs to be a list, was a single value");
- }
- else if(name.equals("ignore_dirs"))
- {
- if (value.isList())
- {
- string projectPathUtf8 = toUtf8(projectPath);
- for (const StringView &ignoreDir : value.asList())
- {
- string ignoreDirFull = projectPathUtf8;
- ignoreDirFull += "/";
- ignoreDirFull += string(ignoreDir.data, ignoreDir.size);
- ignoreDirs.emplace_back(move(ignoreDirFull));
- }
- }
- else
- throw ParserException("Expected " + string(currentObject.data, currentObject.size) + ".ignore_dirs to be a list, was a single value");
- }
- else
- failInvalidFieldUnderObject(name);
+ parseConfig(name, value);
}
else
- parsePlatformBuildTypeConfigs(name, value);
+ parsePlatformConfig(name, value);
}
else if(currentObject.equals("dependencies"))
{
@@ -1012,6 +969,57 @@ namespace sibs
throw ParserException(errMsg);
}
}
+
+ void SibsConfig::parseConfig(const StringView &name, const ConfigValue &value)
+ {
+ if(name.equals("expose_include_dirs"))
+ {
+ if (value.isList())
+ {
+ for (const StringView &includeDir : value.asList())
+ {
+ exposeIncludeDirs.emplace_back(string(includeDir.data, includeDir.size));
+ }
+ }
+ else
+ {
+ string errMsg = "Expected ";
+ errMsg += string(currentObject.data, currentObject.size);
+ errMsg += " to be a list, was a single value";
+ throw ParserException(errMsg);
+ }
+ }
+ else if(name.equals("include_dirs"))
+ {
+ if(value.isList())
+ {
+ for(const StringView &includeDir : value.asList())
+ {
+ includeDirs.emplace_back(string(includeDir.data, includeDir.size));
+ }
+ }
+ else
+ throw ParserException("Expected " + string(currentObject.data, currentObject.size) + ".include_dirs to be a list, was a single value");
+ }
+ else if(name.equals("ignore_dirs"))
+ {
+ if (value.isList())
+ {
+ string projectPathUtf8 = toUtf8(projectPath);
+ for (const StringView &ignoreDir : value.asList())
+ {
+ string ignoreDirFull = projectPathUtf8;
+ ignoreDirFull += "/";
+ ignoreDirFull += string(ignoreDir.data, ignoreDir.size);
+ ignoreDirs.emplace_back(move(ignoreDirFull));
+ }
+ }
+ else
+ throw ParserException("Expected " + string(currentObject.data, currentObject.size) + ".ignore_dirs to be a list, was a single value");
+ }
+ else
+ failInvalidFieldUnderObject(name);
+ }
void SibsConfig::parseDependencies(const StringView &name, const ConfigValue &value)
{
@@ -1171,39 +1179,75 @@ namespace sibs
else
failInvalidFieldUnderObject(fieldName);
}
-
- void SibsConfig::parsePlatformBuildTypeConfigs(const StringView &fieldName, const ConfigValue &fieldValue)
+
+ static bool isObjectIdentifierSymbol(char c)
{
- bool validConfig = false;
- for(int i = 0; i < NUM_CONFIGS; ++i)
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || c == '-';
+ }
+
+ static StringView getNextIdentifierInObject(const StringView &objectName)
+ {
+ size_t identifierStart = -1;
+ for(size_t i = 0; i < objectName.size; ++i)
{
- const StringView &config = CONFIGS[i];
- if(currentObject.equals(config))
+ char c = objectName[i];
+ if(c == '.')
{
- 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;
- default:
- break;
- }
+ if(identifierStart == -1)
+ identifierStart = i + 1;
+ else
+ return { objectName.data + identifierStart, i - identifierStart };
}
}
-
- if(!validConfig)
+
+ if(identifierStart == -1)
+ return { objectName.data + objectName.size, 0 };
+ else
+ return { objectName.data + identifierStart, objectName.size - identifierStart };
+ }
+
+ void SibsConfig::parsePlatformConfig(const StringView &fieldName, const ConfigValue &fieldValue)
+ {
+ StringView platformName = getNextIdentifierInObject(currentObject);
+ Platform platform = getPlatformByName(platformName);
+
+ if(platform == PLATFORM_INVALID)
{
string errMsg = "Invalid config object \"";
errMsg += string(currentObject.data, currentObject.size);
- errMsg += "\"";
+ errMsg += "\", invalid platform: ";
+ errMsg += string(platformName.data, platformName.size);
throw ParserException(errMsg);
}
+
+ if(!isBaseForPlatform(platform, SYSTEM_PLATFORM))
+ return;
+
+ const char *start = platformName.data + platformName.size;
+ const char *currentObjEnd = currentObject.data + currentObject.size;
+ if(start < currentObjEnd)
+ {
+ size_t size = currentObjEnd - start;
+ StringView platformConfigType = { start, size };
+
+ if(size == 13 && strncmp(platformConfigType.data, ".static.debug", 13) == 0)
+ {
+ parsePlatformConfigStaticDebug(fieldName, fieldValue);
+ }
+ else if(size == 15 && strncmp(platformConfigType.data, ".static.release", 15) == 0)
+ {
+ parsePlatformConfigStaticRelease(fieldName, fieldValue);
+ }
+ else
+ {
+ string errMsg = "Invalid config object \"";
+ errMsg += string(currentObject.data, currentObject.size);
+ errMsg += "\"";
+ throw ParserException(errMsg);
+ }
+ }
+ else
+ parseConfig(fieldName, fieldValue);
}
string SibsConfig::parsePlatformConfigStatic(const StringView &fieldName, const ConfigValue &fieldValue)