aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp91
1 files changed, 25 insertions, 66 deletions
diff --git a/src/main.cpp b/src/main.cpp
index b9d6c1b..910380a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,6 +6,7 @@
#include "../include/Conf.hpp"
#include "../include/Exec.hpp"
#include "../include/CmakeModule.hpp"
+#include "../backend/BackendUtils.hpp"
#include "../backend/ninja/Ninja.hpp"
using namespace std;
@@ -42,11 +43,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: Set c++ standard to c++11 and c standard to c98 - for consistency across different compilers and compiler version.
-// It should be possible to override language version in project.conf
-
-// TODO: If file extension is common c extension (.c, ...) then remove cast checking (for example using malloc without casting result to result type)
-
// TODO: When building a sibs project, add a hardlink in ~/.sibs/lib to it. This allows us to have dependency to a project that we can modify
// without having to commit & push to remote
@@ -199,48 +195,17 @@ bool isPathSubPathOf(const FileString &path, const FileString &subPathOf)
return _tinydir_strncmp(path.c_str(), subPathOf.c_str(), subPathOf.size()) == 0;
}
-int buildProject(const FileString &projectPath, const FileString &projectConfFilePath, const SibsConfig &sibsConfig)
+int buildProject(const FileString &projectPath, const FileString &projectConfFilePath, SibsConfig &sibsConfig)
{
- Result<bool> result = Config::readFromFile(projectConfFilePath.c_str(), sibsConfig);
- if(result.isErr())
- {
- ferr << "Failed to read config: " << toFileString(result.getErrMsg()) << endl;
- exit(6);
- }
-
- if(sibsConfig.getPackageName().empty())
- {
- ferr << "project.conf is missing required field package.name" << endl;
- exit(10);
- }
-
- if (!containsPlatform(sibsConfig.getPlatforms(), SYSTEM_PLATFORM))
- {
- string errMsg = "The project ";
- errMsg += sibsConfig.getPackageName();
- errMsg += " does not support your platform (";
- errMsg += asString(SYSTEM_PLATFORM);
- errMsg += ")";
- cerr << errMsg << endl;
- exit(11);
- }
-
- FileString buildPath = projectPath + TINYDIR_STRING("/sibs-build/");
- switch(sibsConfig.getOptimizationLevel())
- {
- case OPT_LEV_DEBUG:
- buildPath += TINYDIR_STRING("debug");
- break;
- case OPT_LEV_RELEASE:
- buildPath += TINYDIR_STRING("release");
- break;
- }
+ FileString buildPath;
+ readSibsConfig(projectPath, projectConfFilePath, sibsConfig, buildPath);
auto startTime = high_resolution_clock::now();
if(sibsConfig.shouldUseCmake())
{
auto dummyCallback = [](const string&){};
+ // TODO: Add test and sub projects
CmakeModule cmakeModule;
Result<bool> cmakeCompileResult = cmakeModule.compile(sibsConfig, buildPath, dummyCallback, dummyCallback, dummyCallback);
if(!cmakeCompileResult)
@@ -252,42 +217,36 @@ int buildProject(const FileString &projectPath, const FileString &projectConfFil
else
{
backend::Ninja ninja;
- FileWalkCallbackFunc collectSourceFiles = [&ninja, &sibsConfig, &collectSourceFiles](tinydir_file *file)
+ // TODO: Do same for cmake
+ switch (sibsConfig.getOptimizationLevel())
{
- FileString pathNative = file->path;
- #if OS_FAMILY == OS_FAMILY_WINDOWS
- replaceChar(pathNative, L'/', L'\\');
- #endif
- if(file->is_reg)
+ case OPT_LEV_DEBUG:
{
- if (isSourceFile(file))
+ // TODO: Check if this dependency is static or dynamic and decide which lib path to use from that
+ for(const string &staticLib : sibsConfig.getDebugStaticLibs())
{
- string filePathUtf8 = toUtf8(pathNative.c_str() + sibsConfig.getProjectPath().size());
- ninja.addSourceFile(filePathUtf8.c_str());
- }
- else
- {
- //printf("Ignoring non-source file: %s\n", file->path + projectPath.size());
+ string staticLibCmd = "\"";
+ staticLibCmd += staticLib;
+ staticLibCmd += "\"";
+ ninja.addDependency(staticLibCmd);
}
+ break;
}
- else
+ case OPT_LEV_RELEASE:
{
- if (!sibsConfig.getTestPath().empty() && isPathSubPathOf(pathNative.c_str(), sibsConfig.getTestPath()))
+ // TODO: Check if this dependency is static or dynamic and decide which lib path to use from that
+ for (const string &staticLib : sibsConfig.getReleaseStaticLibs())
{
- string filePathUtf8 = toUtf8(pathNative.c_str());
- ninja.addTestSourceDir(filePathUtf8.c_str());
+ string staticLibCmd = "\"";
+ staticLibCmd += staticLib;
+ staticLibCmd += "\"";
+ ninja.addDependency(staticLibCmd);
}
- else if(!directoryToIgnore(pathNative, sibsConfig.getIgnoreDirs()))
- walkDir(file->path, collectSourceFiles);
+ break;
}
- };
- walkDir(projectPath.c_str(), collectSourceFiles);
-
- if(sibsConfig.shouldBuildTests() && sibsConfig.getTestPath().empty())
- {
- printf("Project is missing package.tests config. No tests to build\n");
- exit(0);
}
+
+ backend::BackendUtils::collectSourceFiles(projectPath.c_str(), &ninja, sibsConfig);
Result<bool> buildFileResult = ninja.build(sibsConfig, buildPath.c_str());
if(buildFileResult.isErr())