Skip to content

Commit 60704fb

Browse files
committed
Implement support for custom build script inside CI Action on Github #451
1 parent 5b25d20 commit 60704fb

File tree

1 file changed

+52
-22
lines changed

1 file changed

+52
-22
lines changed

server/src/building/UserProjectConfiguration.cpp

+52-22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#include "loguru.h"
1414

15+
#include <fstream>
16+
1517
Status UserProjectConfiguration::CheckProjectConfiguration(const fs::path &buildDirPath,
1618
ProjectConfigWriter const &writer) {
1719
if (!fs::exists(buildDirPath)) {
@@ -46,37 +48,65 @@ static const std::vector<std::string> CMAKE_MANDATORY_OPTIONS = {
4648
"-DCMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES=OFF",
4749
};
4850

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+
4959
Status
5060
UserProjectConfiguration::RunProjectConfigurationCommands(const fs::path &buildDirPath,
5161
const utbot::ProjectContext &projectContext,
5262
std::vector<std::string> cmakeOptions,
5363
ProjectConfigWriter const &writer) {
5464
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;
6173
}
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);
6282
}
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);
77109
}
78-
LOG_S(INFO) << "Configure make project";
79-
RunProjectConfigurationCommand(buildDirPath, bearMakeParams, projectContext, writer);
80110
writer.writeResponse(ProjectConfigStatus::IS_OK);
81111
} catch (const std::exception &e) {
82112
fs::remove(getCompileCommandsJsonPath(buildDirPath));

0 commit comments

Comments
 (0)