|
12 | 12 |
|
13 | 13 | #include "loguru.h"
|
14 | 14 |
|
| 15 | +#include <fstream> |
| 16 | + |
15 | 17 | Status UserProjectConfiguration::CheckProjectConfiguration(const fs::path &buildDirPath,
|
16 | 18 | ProjectConfigWriter const &writer) {
|
17 | 19 | if (!fs::exists(buildDirPath)) {
|
@@ -46,37 +48,65 @@ static const std::vector<std::string> CMAKE_MANDATORY_OPTIONS = {
|
46 | 48 | "-DCMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES=OFF",
|
47 | 49 | };
|
48 | 50 |
|
| 51 | +static std::string IN_PROJECT_ROOT_CI_BUILD_SCRIPT_NAME = "utbot_build.sh"; |
| 52 | +static std::string IN_BUILD_CONFIGURATION_SCRIPT_NAME = "utbot_configure.sh"; |
| 53 | +static std::string IN_BUILD_CONFIGURATION_SCRIPT_CONTENT = |
| 54 | + "#!/bin/bash\n" + |
| 55 | + Copyright::GENERATED_SH_HEADER + |
| 56 | + "cd ..\n" |
| 57 | + "./" + IN_PROJECT_ROOT_CI_BUILD_SCRIPT_NAME + "\n"; |
| 58 | + |
49 | 59 | Status
|
50 | 60 | UserProjectConfiguration::RunProjectConfigurationCommands(const fs::path &buildDirPath,
|
51 | 61 | const utbot::ProjectContext &projectContext,
|
52 | 62 | std::vector<std::string> cmakeOptions,
|
53 | 63 | ProjectConfigWriter const &writer) {
|
54 | 64 | try {
|
55 |
| - fs::path bearShPath = createBearShScript(buildDirPath); |
56 |
| - |
57 |
| - std::vector<std::string> cmakeOptionsWithMandatory = CMAKE_MANDATORY_OPTIONS; |
58 |
| - for (const std::string &op : cmakeOptions) { |
59 |
| - if (op.find("_USE_RESPONSE_FILE_FOR_") == std::string::npos) { |
60 |
| - cmakeOptionsWithMandatory.emplace_back(op); |
| 65 | + if (fs::exists(buildDirPath.parent_path() / IN_PROJECT_ROOT_CI_BUILD_SCRIPT_NAME)) { |
| 66 | + LOG_S(INFO) << "Configure project by " << IN_PROJECT_ROOT_CI_BUILD_SCRIPT_NAME; |
| 67 | + |
| 68 | + const fs::path utbotConfigurePath = buildDirPath / IN_BUILD_CONFIGURATION_SCRIPT_NAME; |
| 69 | + { |
| 70 | + // create wrapper script for in-root build script |
| 71 | + std::ofstream(buildDirPath / IN_BUILD_CONFIGURATION_SCRIPT_NAME) |
| 72 | + << IN_BUILD_CONFIGURATION_SCRIPT_CONTENT; |
61 | 73 | }
|
| 74 | + fs::permissions(utbotConfigurePath, |
| 75 | + fs::perms::owner_exec, |
| 76 | + std::filesystem::perm_options::add); |
| 77 | + |
| 78 | + ShellExecTask::ExecutionParameters bearBuildParams( |
| 79 | + Paths::getBear(), |
| 80 | + {utbotConfigurePath}); |
| 81 | + RunProjectConfigurationCommand(buildDirPath, bearBuildParams, projectContext, writer); |
62 | 82 | }
|
63 |
| - cmakeOptionsWithMandatory.emplace_back(".."); |
64 |
| - |
65 |
| - ShellExecTask::ExecutionParameters cmakeParams(Paths::getCMake(), cmakeOptionsWithMandatory); |
66 |
| - ShellExecTask::ExecutionParameters bearMakeParams(Paths::getBear(), |
67 |
| - {Paths::getMake(), MakefileUtils::threadFlag()}); |
68 |
| - |
69 |
| - |
70 |
| - fs::path cmakeListsPath = getCmakeListsPath(buildDirPath); |
71 |
| - if (fs::exists(cmakeListsPath)) { |
72 |
| - LOG_S(INFO) << "Configure cmake project"; |
73 |
| - RunProjectConfigurationCommand(buildDirPath, cmakeParams, projectContext, writer); |
74 |
| - } else { |
75 |
| - LOG_S(INFO) << "CMakeLists.txt not found in root project directory: " << cmakeListsPath |
76 |
| - << ". Skipping cmake step."; |
| 83 | + else { |
| 84 | + std::vector<std::string> cmakeOptionsWithMandatory = CMAKE_MANDATORY_OPTIONS; |
| 85 | + for (const std::string &op : cmakeOptions) { |
| 86 | + if (op.find("_USE_RESPONSE_FILE_FOR_") == std::string::npos) { |
| 87 | + cmakeOptionsWithMandatory.emplace_back(op); |
| 88 | + } |
| 89 | + } |
| 90 | + cmakeOptionsWithMandatory.emplace_back(".."); |
| 91 | + |
| 92 | + ShellExecTask::ExecutionParameters cmakeParams( |
| 93 | + Paths::getCMake(), |
| 94 | + cmakeOptionsWithMandatory); |
| 95 | + ShellExecTask::ExecutionParameters bearMakeParams( |
| 96 | + Paths::getBear(), |
| 97 | + { Paths::getMake(), MakefileUtils::threadFlag() }); |
| 98 | + |
| 99 | + fs::path cmakeListsPath = getCmakeListsPath(buildDirPath); |
| 100 | + if (fs::exists(cmakeListsPath)) { |
| 101 | + LOG_S(INFO) << "Configure cmake project"; |
| 102 | + RunProjectConfigurationCommand(buildDirPath, cmakeParams, projectContext, writer); |
| 103 | + } else { |
| 104 | + LOG_S(INFO) << "CMakeLists.txt not found in root project directory: " |
| 105 | + << cmakeListsPath << ". Skipping cmake step."; |
| 106 | + } |
| 107 | + LOG_S(INFO) << "Configure make project"; |
| 108 | + RunProjectConfigurationCommand(buildDirPath, bearMakeParams, projectContext, writer); |
77 | 109 | }
|
78 |
| - LOG_S(INFO) << "Configure make project"; |
79 |
| - RunProjectConfigurationCommand(buildDirPath, bearMakeParams, projectContext, writer); |
80 | 110 | writer.writeResponse(ProjectConfigStatus::IS_OK);
|
81 | 111 | } catch (const std::exception &e) {
|
82 | 112 | fs::remove(getCompileCommandsJsonPath(buildDirPath));
|
|
0 commit comments