From a5eeb97292ed084d0da3a02d7057d6f72219e6b9 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 29 Sep 2018 15:03:24 +0200 Subject: Fix TODO: Move include_dirs & ignore_dirs under config Merge duplicate parsing code into one function --- src/Conf.cpp | 122 +++++++++++++++++++++++++++++------------------------------ src/main.cpp | 7 ---- 2 files changed, 60 insertions(+), 69 deletions(-) (limited to 'src') diff --git a/src/Conf.cpp b/src/Conf.cpp index 40ff018..8dc4e7c 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -766,6 +766,7 @@ namespace sibs { includeDirs.emplace_back(string(includeDir.data, includeDir.size)); } + fprintf(stderr, "Warning: package.include_dirs is deprecated, please move include_dirs under config\n"); } else throw ParserException("Expected package.include_dirs to be a list, was a single value"); @@ -828,6 +829,7 @@ namespace sibs ignoreDirFull += string(ignoreDir.data, ignoreDir.size); ignoreDirs.emplace_back(ignoreDirFull); } + fprintf(stderr, "Warning: package.ignore_dirs is deprecated, please move ignore_dirs under config\n"); } else throw ParserException("Expected package.ignore_dirs to be a list, was a single value"); @@ -837,9 +839,10 @@ namespace sibs } else if(currentObject.size >= 6 && strncmp(currentObject.data, "config", 6) == 0) { - if(currentObject.size == 6) // [config] + bool platformConfig = currentObject.equals(CONFIGS[CONFIG_SYSTEM_PLATFORM]); + if(currentObject.size == 6 || platformConfig) // [config] { - if (name.equals("expose_include_dirs")) + if(name.equals("expose_include_dirs")) { if (value.isList()) { @@ -856,13 +859,39 @@ namespace sibs 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); } - else // [config.*] - { - parsePlatformConfigs(name, value); - } + else + parsePlatformBuildTypeConfigs(name, value); } else if(currentObject.equals("dependencies")) { @@ -1119,66 +1148,48 @@ namespace sibs failInvalidFieldUnderObject(fieldName); } - void SibsConfig::parsePlatformConfigs(const StringView &fieldName, const ConfigValue &fieldValue) + void SibsConfig::parsePlatformBuildTypeConfigs(const StringView &fieldName, const ConfigValue &fieldValue) { + bool validConfig = false; for(int i = 0; i < NUM_CONFIGS; ++i) { const StringView &config = CONFIGS[i]; if(currentObject.equals(config)) { + validConfig = true; switch(i) { - case CONFIG_SYSTEM_PLATFORM: - return parsePlatformConfig(fieldName, fieldValue); case CONFIG_STATIC_DEBUG_PLATFORM: - return parsePlatformConfigStaticDebug(fieldName, fieldValue); + parsePlatformConfigStaticDebug(fieldName, fieldValue); + break; case CONFIG_STATIC_RELEASE_PLATFORM: - return parsePlatformConfigStaticRelease(fieldName, fieldValue); + parsePlatformConfigStaticRelease(fieldName, fieldValue); + break; default: - return; + break; } } } - 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(!validConfig) { - 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); - } + string errMsg = "Invalid config object \""; + errMsg += string(currentObject.data, currentObject.size); + errMsg += "\""; + throw ParserException(errMsg); } - else - failInvalidFieldUnderObject(fieldName); } - - void SibsConfig::parsePlatformConfigStaticDebug(const StringView &fieldName, const ConfigValue &fieldValue) + + string SibsConfig::parsePlatformConfigStatic(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); + string staticLibPath = toUtf8(projectPath); + staticLibPath += "/"; + staticLibPath += string(fieldValue.asSingle().data, fieldValue.asSingle().size); + return staticLibPath; } else { @@ -1192,27 +1203,14 @@ namespace sibs failInvalidFieldUnderObject(fieldName); } + void SibsConfig::parsePlatformConfigStaticDebug(const StringView &fieldName, const ConfigValue &fieldValue) + { + getLibFiles(parsePlatformConfigStatic(fieldName, fieldValue), debugStaticLibs); + } + 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); + getLibFiles(parsePlatformConfigStatic(fieldName, fieldValue), releaseStaticLibs); } void SibsConfig::parseCmake(const StringView &fieldName, const ConfigValue &fieldValue, FileString &cmakeDir, FileString &cmakeArgs) diff --git a/src/main.cpp b/src/main.cpp index 334f972..a5f7562 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,10 +29,6 @@ using namespace std::chrono; // TODO: Remove install.sh when sibs supports installation of packages (so it can install itself) -// TODO: Move package include_dirs and ignore_dirs under config in project.conf. -// Package object should only contain metadata for the package, which is used for finding dependencies -// and when building a list of installed packages / available packages. - // TODO: Allow different platforms to have different dependencies. // This can be done by specifying dependencies under [dependencies.platform] instead of [dependencies], // for example for win32: [dependencies.win32] @@ -46,9 +42,6 @@ using namespace std::chrono; // Might need to make it possible to define variables if a dependency exists (or doesn't exist) because the code might have // preprocessor like: USE_LIBSODIUM or NO_LIBSODIUM. -// TODO: When building a sibs project, add a hardlink in ~/.cache/sibs/lib to it. This allows us to have dependency to a project that we can modify -// without having to commit & push to remote - // TODO: Check compiler flags generated by cmake and visual studio in debug and release mode and use the same ones when building sibs project. // There are certain compiler flags we do not currently have, for example _ITERATOR_DEBUG_LEVEL in debug mode which enables runtime checks. // You should be able to specify runtime checks as an option to `sibs build` and project specific config in .conf file. -- cgit v1.2.3