diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Conf.cpp | 10 | ||||
-rw-r--r-- | src/FileUtil.cpp | 14 | ||||
-rw-r--r-- | src/main.cpp | 49 |
3 files changed, 50 insertions, 23 deletions
diff --git a/src/Conf.cpp b/src/Conf.cpp index cea1b01..56b1e2a 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -1,7 +1,6 @@ #include "../include/Conf.hpp" #include "../include/FileUtil.hpp" #include "../external/utf8/unchecked.h" -#include <stdexcept> using namespace std; using u8string = utf8::unchecked::iterator<char*>; @@ -156,15 +155,6 @@ namespace sibs }; }; - class ParserException : public std::runtime_error - { - public: - ParserException(const string &errMsg) : runtime_error(errMsg) - { - - } - }; - class Parser { public: diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp index 30fe03d..8502e84 100644 --- a/src/FileUtil.cpp +++ b/src/FileUtil.cpp @@ -18,6 +18,7 @@ namespace sibs } } + // TODO: Handle failure (directory doesn't exist, no permission etc) void walkDirFiles(const char *directory, FileWalkCallbackFunc callbackFunc) { tinydir_dir dir; @@ -50,6 +51,7 @@ namespace sibs size_t fileSize = ftell(file); fseek(file, 0, SEEK_SET); + // TODO: Change this to string so it can be deallocated and use std::move to prevent copies char *result = (char*)malloc(fileSize + 1); if(!result) { @@ -62,4 +64,16 @@ namespace sibs fclose(file); return Result<StringView>::Ok(StringView(result, fileSize)); } + + bool fileOverwrite(const char *filepath, StringView data) + { + FILE *file = fopen(filepath, "wb"); + if(!file || errno != 0) + { + perror(filepath); + return false; + } + fwrite(data.data, 1, data.size, file); + fclose(file); + } }
\ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ce914b7..866d691 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,9 @@ #include <cstdio> #include "../include/FileUtil.hpp" #include "../include/Conf.hpp" +#include "../backend/ninja/Ninja.hpp" #include <string> +#include <cassert> using namespace std; using namespace sibs; @@ -50,6 +52,14 @@ void validateFilePath(const char *projectConfPath) class SibsConfig : public ConfigCallback { +public: + SibsConfig() : finishedProcessing(false) {} + + const string& getPackageName() const + { + assert(finishedProcessing); + return packageName; + } protected: void processObject(StringView name) override { @@ -78,15 +88,24 @@ protected: printf("]"); } printf("\n"); + + if(currentObject.equals("package") && name.equals("name")) + { + if(value.isSingle()) + packageName = string(value.asSingle().data, value.asSingle().size); + else + throw ParserException("Expected package.name to be a single value, was a list"); + } } void finished() override { - + finishedProcessing = true; } - private: StringView currentObject; + string packageName; + bool finishedProcessing; }; const char *sourceFileExtensions[] = { "cc", "cpp", "cxx" }; @@ -109,8 +128,8 @@ int main(int argc, const char **argv) if(argc != 2) usage(); - const char *projectPath = argv[1]; - validateDirectoryPath(projectPath); + string projectPath = argv[1]; + validateDirectoryPath(projectPath.c_str()); string projectConfFilePath = projectPath; projectConfFilePath += "/project.conf"; @@ -118,29 +137,33 @@ int main(int argc, const char **argv) SibsConfig sibsConfig; Result<bool> result = Config::readFromFile(projectConfFilePath.c_str(), sibsConfig); - if(result.isOk()) - { - - } - else + if(result.isErr()) { printf("Failed to read config: %s\n", result.getErrMsg().c_str()); exit(6); } - string projectSrcPath = string(projectPath) + "/src"; + string projectSrcPath = projectPath + "/src"; validateDirectoryPath(projectSrcPath.c_str()); - walkDirFiles(projectSrcPath.c_str(), [](tinydir_file *file) + + backend::Ninja ninja; + walkDirFiles(projectSrcPath.c_str(), [&ninja, &projectPath](tinydir_file *file) { if (isSourceFile(file)) { - printf("source file: %s\n", file->path); + printf("Adding source file: %s\n", file->path + projectPath.size() + 1); + ninja.addSourceFile(file->path + projectPath.size() + 1); } else { - printf("non source file: %s\n", file->path); + printf("Ignoring non-source file: %s\n", file->path + projectPath.size() + 1); } }); + // 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()); + return 0; }
\ No newline at end of file |