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/Archive.cpp | 4 +- src/CmakeModule.cpp | 11 +-- src/Conf.cpp | 194 +++++++++++++++++++++++++++++++--------------------- 3 files changed, 120 insertions(+), 89 deletions(-) (limited to 'src') diff --git a/src/Archive.cpp b/src/Archive.cpp index 506b020..08106c3 100644 --- a/src/Archive.cpp +++ b/src/Archive.cpp @@ -45,7 +45,7 @@ namespace sibs int r; const void *buff; size_t size; - la_int64_t offset; + int64_t offset; while(true) { @@ -178,4 +178,4 @@ namespace sibs archive_write_free(ext); return Result::Ok(true); } -} \ No newline at end of file +} diff --git a/src/CmakeModule.cpp b/src/CmakeModule.cpp index 1995023..e05a65f 100644 --- a/src/CmakeModule.cpp +++ b/src/CmakeModule.cpp @@ -133,20 +133,14 @@ namespace sibs if(config.getPackageType() != PackageType::EXECUTABLE) { - #if OS_TYPE == OS_TYPE_WINDOWS - const _tinydir_char_t *libFileExtension = TINYDIR_STRING("lib"); - #elif OS_TYPE == OS_TYPE_LINUX - const _tinydir_char_t *libFileExtension = TINYDIR_STRING("so"); - #endif - FileString libFile; u64 libFileLastModified = 0; string buildPathUtf8 = toUtf8(buildPath); nprintf("Searching for library generate by cmake in build path: %s\n", buildPathUtf8.c_str()); - walkDirFiles(buildPath.c_str(), [&libFileExtension, &libFile, &libFileLastModified](tinydir_file *file) + walkDirFiles(buildPath.c_str(), [&libFile, &libFileLastModified](tinydir_file *file) { - if(_tinydir_strcmp(file->extension, libFileExtension) == 0) + if(_tinydir_strcmp(file->extension, CONFIG_DYNAMIC_LIB_FILE_EXTENSION) == 0) { u32 fileLastModified = getFileLastModifiedTime(file->path); if(fileLastModified > libFileLastModified) @@ -190,7 +184,6 @@ namespace sibs // TODO: Clean this up. The below code is indentical to code in Ninja.cpp....... string projectPathUtf8 = toUtf8(config.getProjectPath()); - printf("BUILD CMAKE MODULE!, num global include dirs: %d\n", config.getGlobalIncludeDirs().size()); for (const string &globalIncludeDir : config.getGlobalIncludeDirs()) { string globalIncludeDirFull = projectPathUtf8; 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