From 8ac9ddf460cc4c1b2972df1069128fb615b31042 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 2 Jan 2018 19:30:52 +0100 Subject: Fix bug when using config for several platforms in one project --- src/Conf.cpp | 194 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 116 insertions(+), 78 deletions(-) (limited to 'src/Conf.cpp') diff --git a/src/Conf.cpp b/src/Conf.cpp index 2d7db93..852fcd4 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -447,13 +447,13 @@ namespace sibs { case FileType::FILE_NOT_FOUND: { - string errMsg = "Path not found: "; + string errMsg = "Library path not found: "; errMsg += libPath; throw ParserException(errMsg); } case FileType::REGULAR: { - string errMsg = "Expected path "; + string errMsg = "Expected library path "; errMsg += libPath; errMsg += " to be a directory, was a regular file"; throw ParserException(errMsg); @@ -462,7 +462,8 @@ namespace sibs walkDirFiles(nativePath.c_str(), [&outputFiles](tinydir_file *file) { - outputFiles.push_back(toUtf8(file->path)); + if(_tinydir_strcmp(file->extension, CONFIG_STATIC_LIB_FILE_EXTENSION) == 0) + outputFiles.push_back(toUtf8(file->path)); }); } @@ -644,93 +645,34 @@ namespace sibs else failInvalidFieldUnderObject(name); } - else if(currentObject.equals("config")) + else if(currentObject.size >= 6 && strncmp(currentObject.data, "config", 6) == 0) { - if (name.equals("expose_include_dirs")) + if(currentObject.size == 6) // [config] { - if (value.isList()) + if (name.equals("expose_include_dirs")) { - for (const StringView &includeDir : value.asList()) + if (value.isList()) { - exposeIncludeDirs.emplace_back(string(includeDir.data, includeDir.size)); + 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 - failInvalidFieldUnderObject(name); - } - else if (currentObject.equals(CONFIG_SYSTEM_PLATFORM)) - { - if (name.equals("expose_include_dirs")) - { - if (value.isList()) - { - for (const StringView &includeDir : value.asList()) + else { - exposeIncludeDirs.emplace_back(string(includeDir.data, includeDir.size)); + string errMsg = "Expected "; + errMsg += string(currentObject.data, currentObject.size); + errMsg += " to be a list, was a single value"; + throw ParserException(errMsg); } } else - { - string errMsg = "Expected "; - errMsg += string(currentObject.data, currentObject.size); - errMsg += " to be a list, was a single value"; - throw ParserException(errMsg); - } + failInvalidFieldUnderObject(name); } - else - failInvalidFieldUnderObject(name); - } - else if (currentObject.equals(CONFIG_STATIC_DEBUG_PLATFORM)) - { - if (name.equals("lib")) + else // [config.*] { - if (value.isSingle()) - { - string debugStaticLibPath = toUtf8(projectPath); - debugStaticLibPath += "/"; - debugStaticLibPath += string(value.asSingle().data, value.asSingle().size); - getLibFiles(debugStaticLibPath, debugStaticLibs); - } - else - { - string errMsg = "Expected "; - errMsg += string(currentObject.data, currentObject.size); - errMsg += " to be a single value, was a list"; - throw ParserException(errMsg); - } + parsePlatformConfigs(name, value); } - else - failInvalidFieldUnderObject(name); - } - else if (currentObject.equals(CONFIG_STATIC_RELEASE_PLATFORM)) - { - if (name.equals("lib")) - { - if (value.isSingle()) - { - string releaseStaticLibPath = toUtf8(projectPath); - releaseStaticLibPath += "/"; - releaseStaticLibPath += string(value.asSingle().data, value.asSingle().size); - getLibFiles(releaseStaticLibPath, releaseStaticLibs); - } - else - { - string errMsg = "Expected "; - errMsg += string(currentObject.data, currentObject.size); - errMsg += " to be a single value, was a list"; - throw ParserException(errMsg); - } - } - else - failInvalidFieldUnderObject(name); } else if(currentObject.equals("dependencies")) { @@ -766,6 +708,102 @@ namespace sibs } } + void SibsConfig::parsePlatformConfigs(const StringView &fieldName, const ConfigValue &fieldValue) + { + for(int i = 0; i < NUM_CONFIGS; ++i) + { + const StringView &config = CONFIGS[i]; + if(currentObject.equals(config)) + { + switch(i) + { + case CONFIG_SYSTEM_PLATFORM: + return parsePlatformConfig(fieldName, fieldValue); + case CONFIG_STATIC_DEBUG_PLATFORM: + return parsePlatformConfigStaticDebug(fieldName, fieldValue); + case CONFIG_STATIC_RELEASE_PLATFORM: + return parsePlatformConfigStaticRelease(fieldName, fieldValue); + default: + return; + } + } + } + + string errMsg = "Invalid config object \""; + errMsg += string(currentObject.data, currentObject.size); + errMsg += "\""; + throw ParserException(errMsg); + } + + void SibsConfig::parsePlatformConfig(const StringView &fieldName, const ConfigValue &fieldValue) + { + if (fieldName.equals("expose_include_dirs")) + { + if (fieldValue.isList()) + { + for (const StringView &includeDir : fieldValue.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 + failInvalidFieldUnderObject(fieldName); + } + + void SibsConfig::parsePlatformConfigStaticDebug(const StringView &fieldName, const ConfigValue &fieldValue) + { + if (fieldName.equals("lib")) + { + if (fieldValue.isSingle()) + { + string debugStaticLibPath = toUtf8(projectPath); + debugStaticLibPath += "/"; + debugStaticLibPath += string(fieldValue.asSingle().data, fieldValue.asSingle().size); + getLibFiles(debugStaticLibPath, debugStaticLibs); + } + else + { + string errMsg = "Expected "; + errMsg += string(currentObject.data, currentObject.size); + errMsg += " to be a single value, was a list"; + throw ParserException(errMsg); + } + } + else + failInvalidFieldUnderObject(fieldName); + } + + void SibsConfig::parsePlatformConfigStaticRelease(const StringView &fieldName, const ConfigValue &fieldValue) + { + if (fieldName.equals("lib")) + { + if (fieldValue.isSingle()) + { + string releaseStaticLibPath = toUtf8(projectPath); + releaseStaticLibPath += "/"; + releaseStaticLibPath += string(fieldValue.asSingle().data, fieldValue.asSingle().size); + getLibFiles(releaseStaticLibPath, releaseStaticLibs); + } + else + { + string errMsg = "Expected "; + errMsg += string(currentObject.data, currentObject.size); + errMsg += " to be a single value, was a list"; + throw ParserException(errMsg); + } + } + else + failInvalidFieldUnderObject(fieldName); + } + void SibsConfig::parseCmake(const StringView &fieldName, const ConfigValue &fieldValue, string &cmakeDir, string &cmakeArgs) { if(fieldName.equals("dir")) -- cgit v1.2.3