From d9f0e34a8dbbdbfc93162f0297ff9330b86d3c01 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 15 Apr 2018 23:48:37 +0200 Subject: Do not build project twice if project is an executable and running 'sibs test' --- backend/ninja/Ninja.cpp | 15 +-------------- src/main.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 814f190..d311110 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -921,20 +921,7 @@ namespace backend if(testSourceDirs.empty() || !config.shouldBuildTests()) return Result::Ok(true); - // Tests need parent project as dependency. Executables can't be included as dependency so we build it as dynamic library. - // `build` also builds tests - if(getNinjaLibraryType(config.getPackageType()) == LibraryType::EXECUTABLE) - { - SibsConfig parentProjConfigLib = config; - parentProjConfigLib.setPackageType(PackageType::DYNAMIC); - // HACK: We can build a package that is defined as executable and contains main function by redefining `main` - // as something else. - // TODO: Do not allow defining `main` in project.conf or as program argument to sibs (when sibs supports defines). - // It's ok if `define` fails. It could fail if `main` has already been replaced by other tests somehow. - parentProjConfigLib.define("main", "sibs_lib_ignore_main"); - parentProjConfigLib.define("wmain", "sibs_lib_ignore_wmain"); - return build(parentProjConfigLib, savePath, nullptr, nullptr); - } + assert(getNinjaLibraryType(config.getPackageType()) != LibraryType::EXECUTABLE); string parentProjectPathUtf8 = toUtf8(config.getProjectPath()); string parentExportIncludeDirs = parentDependencyExportIncludeDirs; diff --git a/src/main.cpp b/src/main.cpp index 24ef61f..2223b56 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -201,6 +201,16 @@ int buildProject(const FileString &projectPath, const FileString &projectConfFil { FileString buildPath; readSibsConfig(projectPath, projectConfFilePath, sibsConfig, buildPath); + // Test project has the main project as dependency, and therefore the main project can't be built as an executable + if(sibsConfig.shouldBuildTests()) + { + // HACK: We can build a package that is defined as executable and contains main function by redefining `main` as something else. + // TODO: Do not allow defining `main` in project.conf or as program argument to sibs. + // It's ok if `define` fails. It could fail if `main` has already been replaced by other tests somehow. + sibsConfig.define("main", "sibs_lib_ignore_main"); + sibsConfig.define("wmain", "sibs_lib_ignore_wmain"); + sibsConfig.setPackageType(PackageType::DYNAMIC); + } auto startTime = high_resolution_clock::now(); if(sibsConfig.shouldUseCmake()) -- cgit v1.2.3