diff options
author | dec05eba <dec05eba@protonmail.com> | 2017-12-09 16:36:23 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2017-12-09 16:38:31 +0100 |
commit | e7384a7672e4449bc194ca3ec66cdd4fcc63801e (patch) | |
tree | c79bc4dfbb8b3a752ae33f26f5e1b2992a484ace /src | |
parent | 6cc190828160586abc6961354a7c05e99537d7e2 (diff) |
Add support for dependencies (including version check)
This currently only works using pkg-config and it only adds
linking flags. Need to check with a library that also includes
other types of flags.
TODO: Fallback to dependencies sub directory and github/server
if package not found in pkg-config.
Diffstat (limited to 'src')
-rw-r--r-- | src/Conf.cpp | 16 | ||||
-rw-r--r-- | src/FileUtil.cpp | 1 | ||||
-rw-r--r-- | src/main.cpp | 33 |
3 files changed, 39 insertions, 11 deletions
diff --git a/src/Conf.cpp b/src/Conf.cpp index 56b1e2a..6383c30 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -68,7 +68,7 @@ namespace sibs char *startOfIdentifier = code.base(); ++code; c = *code; - while(isAlpha(c) || c == '_' || isDigit(c)) + while(isAlpha(c) || isDigit(c) || c == '_' || c == '-') { ++code; c = *code; @@ -95,19 +95,21 @@ namespace sibs } else if(c == '"') { - u32 escapeCount = 0; + bool escapeQuote = false; ++code; char *startOfStr = code.base(); - while(escapeCount > 0 || *code != '"') + while(true) { c = *code; - if(c == '\0') - return Token::END_OF_FILE; + if(c == '"' && !escapeQuote) + break; else if(c == '\\') - ++escapeCount; + escapeQuote = !escapeQuote; + else if(c == '\0') + throw UnexpectedTokenException("Reached end of file before string end"); else - escapeCount = min(0, escapeCount - 1); + escapeQuote = false; ++code; } diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp index 8502e84..59132dc 100644 --- a/src/FileUtil.cpp +++ b/src/FileUtil.cpp @@ -75,5 +75,6 @@ namespace sibs } fwrite(data.data, 1, data.size, file); fclose(file); + return true; } }
\ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 866d691..9f14c67 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include <cstdio> #include "../include/FileUtil.hpp" #include "../include/Conf.hpp" +#include "../include/Dependency.hpp" #include "../backend/ninja/Ninja.hpp" #include <string> #include <cassert> @@ -60,6 +61,11 @@ public: assert(finishedProcessing); return packageName; } + + const std::vector<Dependency>& getDependencies() const + { + return dependencies; + } protected: void processObject(StringView name) override { @@ -96,6 +102,19 @@ protected: else throw ParserException("Expected package.name to be a single value, was a list"); } + else if(currentObject.equals("dependencies")) + { + if(value.isSingle()) + { + // TODO: Validate version is number in correct format + Dependency dependency; + dependency.name = string(name.data, name.size); + dependency.version = string(value.asSingle().data, value.asSingle().size); + dependencies.emplace_back(dependency); + } + else + throw ParserException("Expected field under dependencies to be a single value, was a list"); + } } void finished() override @@ -105,6 +124,7 @@ protected: private: StringView currentObject; string packageName; + std::vector<Dependency> dependencies; bool finishedProcessing; }; @@ -143,11 +163,11 @@ int main(int argc, const char **argv) exit(6); } - string projectSrcPath = projectPath + "/src"; - validateDirectoryPath(projectSrcPath.c_str()); + //string projectSrcPath = projectPath + "/src"; + //validateDirectoryPath(projectSrcPath.c_str()); backend::Ninja ninja; - walkDirFiles(projectSrcPath.c_str(), [&ninja, &projectPath](tinydir_file *file) + walkDirFiles(projectPath.c_str(), [&ninja, &projectPath](tinydir_file *file) { if (isSourceFile(file)) { @@ -163,7 +183,12 @@ int main(int argc, const char **argv) // TODO: Create build path if it doesn't exist string debugBuildPath = projectPath + "/build/debug"; string buildFilePath = debugBuildPath + "/build.ninja"; - ninja.build(sibsConfig.getPackageName(), buildFilePath.c_str()); + Result<bool> buildFileResult = ninja.createBuildFile(sibsConfig.getPackageName(), sibsConfig.getDependencies(), buildFilePath.c_str()); + if(buildFileResult.isErr()) + { + printf("Failed to build ninja file: %s\n", buildFileResult.getErrMsg().c_str()); + exit(7); + } return 0; }
\ No newline at end of file |