Skip to content

Commit

Permalink
Add support for multiple engine archive artifacts
Browse files Browse the repository at this point in the history
- Use `rm` command with CMake 3.17 or newer
- Update CMake minimum required version for compiling to 3.5
  • Loading branch information
encelo committed Oct 16, 2023
1 parent 0b2d3e8 commit b2bd20e
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmake/clipp_download.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.5)

project(clipp-download NONE)

Expand Down
2 changes: 1 addition & 1 deletion cmake/cpptoml_download.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.5)

project(cpptoml-download NONE)

Expand Down
18 changes: 18 additions & 0 deletions src/CMakeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ bool CMakeCommand::generatorIsMultiConfig()
#endif
}

const char *CMakeCommand::removeFile()
{
assert(found_);
if (Helpers::checkMinVersion(version_, 3, 17, 0))
return "rm ";
else
return "remove ";
}

const char *CMakeCommand::removeDir()
{
assert(found_);
if (Helpers::checkMinVersion(version_, 3, 17, 0))
return "rm -r ";
else
return "remove_directory ";
}

bool CMakeCommand::toolsMode(const char *command)
{
assert(found_);
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class CMakeCommand
static bool generatorIsMultiConfig();
static bool generatorIsVisualStudio() { return generatorIsMultiConfig(); }

const char *removeFile();
const char *removeDir();
bool toolsMode(const char *command);

bool configure(const char *srcDir, const char *binDir, const char *generator, const char *platform, const char *arguments);
Expand Down
2 changes: 1 addition & 1 deletion src/ConfMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ bool cleanBuildDir(CMakeCommand &cmake, const Settings &settings, const std::str
if (settings.clean() && fs::isDirectory(buildDir.data()))
{
Helpers::info("Remove the build directory: ", buildDir.data());
std::string cleanCommand = "remove_directory " + buildDir;
std::string cleanCommand = cmake.removeDir() + buildDir;
bool executed = cmake.toolsMode(cleanCommand.data());

return executed;
Expand Down
2 changes: 1 addition & 1 deletion src/DistMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool cleanDistDir(CMakeCommand &cmake, const Settings &settings, const std::stri
if (settings.clean() && fs::isDirectory(buildDir.data()))
{
Helpers::info("Remove the build directory: ", buildDir.data());
std::string cleanCommand = "remove_directory " + buildDir;
std::string cleanCommand = cmake.removeDir() + buildDir;
bool executed = cmake.toolsMode(cleanCommand.data());

return executed;
Expand Down
35 changes: 27 additions & 8 deletions src/DownloadMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ bool extractArchiveAndDeleteDir(CMakeCommand &cmake, const char *archiveFile, co
if (*archiveFile == '\0' || *directory == '\0')
return false;

std::string toolCommand = "remove_directory ";
std::string toolCommand = cmake.removeDir();
toolCommand += directory;
bool executed = cmake.toolsMode(toolCommand.data());

Expand All @@ -169,7 +169,7 @@ bool extractArchiveAndDeleteDir(CMakeCommand &cmake, const char *archiveFile, co

if (executed)
{
toolCommand = "remove ";
toolCommand = cmake.removeFile();
toolCommand += archiveFile;
cmake.toolsMode(toolCommand.data());
}
Expand Down Expand Up @@ -226,7 +226,7 @@ bool extractEngineArchive(GitCommand &git, CMakeCommand &cmake, std::string &arc
if (config().withMinGW() == false)
{
// Multiple archives in the branch
std::string archiveFiles = git.output();
std::string archiveFiles = archiveFile;
if (archiveFiles.empty())
return false;

Expand All @@ -242,7 +242,7 @@ bool extractEngineArchive(GitCommand &git, CMakeCommand &cmake, std::string &arc
break;
else
{
std::string toolCommand = "remove ";
std::string toolCommand = cmake.removeFile();
toolCommand += archiveFile;
cmake.toolsMode(toolCommand.data());
}
Expand All @@ -254,14 +254,14 @@ bool extractEngineArchive(GitCommand &git, CMakeCommand &cmake, std::string &arc
#ifndef __APPLE__
const bool hasExtracted = extractArchiveAndDeleteDir(cmake, archiveFile.data(), Helpers::nCineArtifactsSourceDir());
#else
std::string command = "remove_directory ";
std::string command = cmake.removeDir();
command += Helpers::nCineArtifactsSourceDir();
cmake.toolsMode(command.data());

command = "hdiutil convert " + archiveFile + " -format UDTO -o nCine";
bool executed = Process::executeCommand(command.data());

command = "remove " + archiveFile;
command = cmake.removeFile() + archiveFile;
cmake.toolsMode(command.data());
archiveFile = archiveFile.substr(0, archiveFile.find(".dmg"));

Expand All @@ -278,7 +278,9 @@ bool extractEngineArchive(GitCommand &git, CMakeCommand &cmake, std::string &arc
Process::executeCommand(command.data(), Process::Echo::COMMAND_ONLY);
}

cmake.toolsMode("remove nCine.cdr");
command = cmake.removeFile();
command += "nCine.cdr";
cmake.toolsMode(command.data());
}
const bool hasExtracted = executed;
#endif
Expand All @@ -293,7 +295,24 @@ void downloadEngineArtifact(GitCommand &git, CMakeCommand &cmake)

git.customCommand(Helpers::nCineArtifactsSourceDir(), "ls-tree -r --name-only HEAD");

std::string archiveFile = git.output();
const std::string &archiveFiles = git.output();
// Find the `nCine` archive and delete the `nCineLua` one
std::string archiveFile;
std::string::size_type pos = 0;
std::string::size_type prev = 0;
while ((pos = archiveFiles.find('\n', prev)) != std::string::npos)
{
std::string currentArchiveFile = archiveFiles.substr(prev, pos - prev);
if (currentArchiveFile.find("nCine-") == 0)
archiveFile += currentArchiveFile + "\n";
else
{
std::string toolCommand = cmake.removeFile();
toolCommand += currentArchiveFile;
cmake.toolsMode(toolCommand.data());
}
prev = pos + 1;
}

bool hasExtracted = false;
if (config().platform() == Configuration::Platform::EMSCRIPTEN)
Expand Down

0 comments on commit b2bd20e

Please sign in to comment.