diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 101 |
1 files changed, 15 insertions, 86 deletions
diff --git a/src/main.cpp b/src/main.cpp index 05a6a03..f9fbd82 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,83 +51,6 @@ void validateFilePath(const char *projectConfPath) } } -class SibsConfig : public ConfigCallback -{ -public: - SibsConfig() : finishedProcessing(false) {} - - const string& getPackageName() const - { - assert(finishedProcessing); - return packageName; - } - - const std::vector<Dependency>& getDependencies() const - { - return dependencies; - } -protected: - void processObject(StringView name) override - { - currentObject = name; - printf("Process object: %.*s\n", name.size, name.data); - } - - void processField(StringView name, const ConfigValue &value) override - { - printf("Process field: %.*s, value: ", name.size, name.data); - if(value.isSingle()) - { - printf("\"%.*s\"", value.asSingle().size, value.asSingle().data); - } - else - { - printf("["); - int i = 0; - for(auto listElement : value.asList()) - { - if(i > 0) - printf(", "); - printf("\"%.*s\"", listElement.size, listElement.data); - ++i; - } - 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"); - } - 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 - { - finishedProcessing = true; - } -private: - StringView currentObject; - string packageName; - std::vector<Dependency> dependencies; - bool finishedProcessing; -}; - const char *sourceFileExtensions[] = { "cc", "cpp", "cxx" }; bool isSourceFile(tinydir_file *file) { @@ -150,6 +73,8 @@ int main(int argc, const char **argv) string projectPath = argv[1]; validateDirectoryPath(projectPath.c_str()); + if(projectPath.back() != '/') + projectPath += "/"; string projectConfFilePath = projectPath; projectConfFilePath += "/project.conf"; @@ -163,27 +88,31 @@ int main(int argc, const char **argv) exit(6); } + if(sibsConfig.getPackageName().empty()) + { + printf("project.conf is missing required field package.name\n"); + exit(10); + } + //string projectSrcPath = projectPath + "/src"; //validateDirectoryPath(projectSrcPath.c_str()); backend::Ninja ninja; - walkDirFiles(projectPath.c_str(), [&ninja, &projectPath](tinydir_file *file) + walkDirFilesRecursive(projectPath.c_str(), [&ninja, &projectPath](tinydir_file *file) { if (isSourceFile(file)) { - printf("Adding source file: %s\n", file->path + projectPath.size() + 1); - ninja.addSourceFile(file->path + projectPath.size() + 1); - } - else + printf("Adding source file: %s\n", file->path + projectPath.size()); + ninja.addSourceFile(file->path + projectPath.size()); + } else { - printf("Ignoring non-source file: %s\n", file->path + projectPath.size() + 1); + //printf("Ignoring non-source file: %s\n", file->path + projectPath.size()); } }); // TODO: Create build path if it doesn't exist string debugBuildPath = projectPath + "/build/debug"; - string buildFilePath = debugBuildPath + "/build.ninja"; - Result<bool> buildFileResult = ninja.createBuildFile(sibsConfig.getPackageName(), sibsConfig.getDependencies(), buildFilePath.c_str()); + Result<bool> buildFileResult = ninja.createBuildFile(sibsConfig.getPackageName(), sibsConfig.getDependencies(), debugBuildPath.c_str()); if(buildFileResult.isErr()) { printf("Failed to build ninja file: %s\n", buildFileResult.getErrMsg().c_str()); @@ -197,4 +126,4 @@ int main(int argc, const char **argv) } return 0; -}
\ No newline at end of file +} |