Skip to content

Implement support for custom build script inside CI Action on Github #451 #455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 52 additions & 22 deletions server/src/building/UserProjectConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "loguru.h"

#include <fstream>

Status UserProjectConfiguration::CheckProjectConfiguration(const fs::path &buildDirPath,
ProjectConfigWriter const &writer) {
if (!fs::exists(buildDirPath)) {
Expand Down Expand Up @@ -46,37 +48,65 @@ static const std::vector<std::string> CMAKE_MANDATORY_OPTIONS = {
"-DCMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES=OFF",
};

static std::string IN_PROJECT_ROOT_CI_BUILD_SCRIPT_NAME = "utbot_build.sh";
static std::string IN_BUILD_CONFIGURATION_SCRIPT_NAME = "utbot_configure.sh";
static std::string IN_BUILD_CONFIGURATION_SCRIPT_CONTENT =
"#!/bin/bash\n" +
Copyright::GENERATED_SH_HEADER +
"cd ..\n"
"./" + IN_PROJECT_ROOT_CI_BUILD_SCRIPT_NAME + "\n";

Status
UserProjectConfiguration::RunProjectConfigurationCommands(const fs::path &buildDirPath,
const utbot::ProjectContext &projectContext,
std::vector<std::string> cmakeOptions,
ProjectConfigWriter const &writer) {
try {
fs::path bearShPath = createBearShScript(buildDirPath);

std::vector<std::string> cmakeOptionsWithMandatory = CMAKE_MANDATORY_OPTIONS;
for (const std::string &op : cmakeOptions) {
if (op.find("_USE_RESPONSE_FILE_FOR_") == std::string::npos) {
cmakeOptionsWithMandatory.emplace_back(op);
if (fs::exists(buildDirPath.parent_path() / IN_PROJECT_ROOT_CI_BUILD_SCRIPT_NAME)) {
LOG_S(INFO) << "Configure project by " << IN_PROJECT_ROOT_CI_BUILD_SCRIPT_NAME;

const fs::path utbotConfigurePath = buildDirPath / IN_BUILD_CONFIGURATION_SCRIPT_NAME;
{
// create wrapper script for in-root build script
std::ofstream(buildDirPath / IN_BUILD_CONFIGURATION_SCRIPT_NAME)
<< IN_BUILD_CONFIGURATION_SCRIPT_CONTENT;
}
fs::permissions(utbotConfigurePath,
fs::perms::owner_exec,
std::filesystem::perm_options::add);

ShellExecTask::ExecutionParameters bearBuildParams(
Paths::getBear(),
{utbotConfigurePath});
RunProjectConfigurationCommand(buildDirPath, bearBuildParams, projectContext, writer);
}
cmakeOptionsWithMandatory.emplace_back("..");

ShellExecTask::ExecutionParameters cmakeParams(Paths::getCMake(), cmakeOptionsWithMandatory);
ShellExecTask::ExecutionParameters bearMakeParams(Paths::getBear(),
{Paths::getMake(), MakefileUtils::threadFlag()});


fs::path cmakeListsPath = getCmakeListsPath(buildDirPath);
if (fs::exists(cmakeListsPath)) {
LOG_S(INFO) << "Configure cmake project";
RunProjectConfigurationCommand(buildDirPath, cmakeParams, projectContext, writer);
} else {
LOG_S(INFO) << "CMakeLists.txt not found in root project directory: " << cmakeListsPath
<< ". Skipping cmake step.";
else {
std::vector<std::string> cmakeOptionsWithMandatory = CMAKE_MANDATORY_OPTIONS;
for (const std::string &op : cmakeOptions) {
if (op.find("_USE_RESPONSE_FILE_FOR_") == std::string::npos) {
cmakeOptionsWithMandatory.emplace_back(op);
}
}
cmakeOptionsWithMandatory.emplace_back("..");

ShellExecTask::ExecutionParameters cmakeParams(
Paths::getCMake(),
cmakeOptionsWithMandatory);
ShellExecTask::ExecutionParameters bearMakeParams(
Paths::getBear(),
{ Paths::getMake(), MakefileUtils::threadFlag() });

fs::path cmakeListsPath = getCmakeListsPath(buildDirPath);
if (fs::exists(cmakeListsPath)) {
LOG_S(INFO) << "Configure cmake project";
RunProjectConfigurationCommand(buildDirPath, cmakeParams, projectContext, writer);
} else {
LOG_S(INFO) << "CMakeLists.txt not found in root project directory: "
<< cmakeListsPath << ". Skipping cmake step.";
}
LOG_S(INFO) << "Configure make project";
RunProjectConfigurationCommand(buildDirPath, bearMakeParams, projectContext, writer);
}
LOG_S(INFO) << "Configure make project";
RunProjectConfigurationCommand(buildDirPath, bearMakeParams, projectContext, writer);
writer.writeResponse(ProjectConfigStatus::IS_OK);
} catch (const std::exception &e) {
fs::remove(getCompileCommandsJsonPath(buildDirPath));
Expand Down