aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp49
1 files changed, 36 insertions, 13 deletions
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