Skip to content

Implement support for custom build script inside CI Action on Github Part 2 (Command line) #458 #459

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 2 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
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
25 changes: 20 additions & 5 deletions docker/release_distribution_scripts/utbot_run_system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fi
# Check if arguments are correct
if [ "$1" != "cli" ] && [ "$1" != "server" ] && [ "$1" != "test" ]
then
echo "Wrong UTBOT_MODE: expected cli|server|test"
echo "Wrong execution mode: expected cli|server|test"
exit 1
fi

Expand Down Expand Up @@ -102,7 +102,6 @@ source $COMMON_FUNCTIONS_SCRIPT_PATH

if [ "$1" = "server" ]
then
UTBOT_MODE=server
if [ -z "$2" ]
then
export UTBOT_PORT=2121
Expand All @@ -112,7 +111,7 @@ then

#Server-specific parameters
UTBOT_EXECUTABLE_PATH=$UTBOT_BINARIES_FOLDER/$UTBOT_PROCESS_PATTERN
UTBOT_SERVER_OPTIONS="$UTBOT_MODE --port $UTBOT_PORT --log=$UTBOT_LOGS_FOLDER"
UTBOT_SERVER_OPTIONS="server --port $UTBOT_PORT --log=$UTBOT_LOGS_FOLDER"
UTBOT_STDOUT_LOG_FILE=$UTBOT_LOGS_FOLDER/logs/"latest.log"

log "Starting a new server process; logs are written into [$UTBOT_LOGS_FOLDER] folder"
Expand All @@ -126,14 +125,30 @@ then
#Online-cli-specific parameters
UTBOT_EXECUTABLE_PATH=$UTBOT_BINARIES_FOLDER/$UTBOT_PROCESS_PATTERN
UTBOT_CLI_OPTIONS="${@:2}"
UTBOT_BUILD_SCRIPT="utbot_build.sh"
UTBOT_BUILD_SCRIPT_RUNNER="utbot_configure.sh"

if [ "$2" == "generate" ]
then
PROJECT_PATH=$4
mkdir -p $PROJECT_PATH/build
cd $PROJECT_PATH/build || exit
cmake ..
bear make

if [ -f "../$UTBOT_BUILD_SCRIPT" ]
then
echo "Trying to run '$UTBOT_BUILD_SCRIPT'!"
echo "#!/bin/bash
# This file is automatically generated by UnitTestBot. For further information see https://www.utbot.org
cd ..
./$UTBOT_BUILD_SCRIPT" > $UTBOT_BUILD_SCRIPT_RUNNER
chmod +x $UTBOT_BUILD_SCRIPT_RUNNER
bear "./$UTBOT_BUILD_SCRIPT_RUNNER"
else
echo "Trying to run 'cmake' and 'make'!"
cmake ..
bear make
fi

cd $CURRENT_FOLDER || exit
fi

Expand Down
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