From 379e5c20280e8e2df285d8bc4b340921a4786cb7 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Fri, 27 Feb 2026 04:36:51 +0100 Subject: [PATCH] global clone cache --- .../Crafter.Build-Configuration.cpp | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/implementations/Crafter.Build-Configuration.cpp b/implementations/Crafter.Build-Configuration.cpp index d309472..114de04 100644 --- a/implementations/Crafter.Build-Configuration.cpp +++ b/implementations/Crafter.Build-Configuration.cpp @@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA module; #include "../lib/json.hpp" #include +#include module Crafter.Build:Configuration_impl; import :Configuration; import std; @@ -250,7 +251,7 @@ namespace Crafter { if(path.string().ends_with(".git")) { fs::path name = path.filename(); name.replace_extension(); - std::string depFolder = name.string() + "-" + configName; + std::string depFolder = name.string(); // if (it.contains("commit")) { // depFolder += it["commit"].get(); @@ -258,14 +259,16 @@ namespace Crafter { // depFolder += it["branch"].get(); // } - if (!fs::exists(project.buildDir/depFolder)) { - fs::create_directories(project.buildDir/depFolder); + char self[PATH_MAX]; + ssize_t count = readlink("/proc/self/exe", self, PATH_MAX); + if (count == -1) { + throw std::runtime_error("Failed to get executable path"); + } + self[count] = '\0'; + const fs::path cacheDir = (fs::path(self).parent_path().parent_path() / "cloneCache").string(); - std::string cloneCommand = std::format("cd {} && git clone {} {} && cd {}", - project.buildDir.string(), - path.string(), - depFolder, - depFolder); + if (!fs::exists(cacheDir/depFolder)) { + std::string cloneCommand = std::format("cd {} && git clone {} && cd {}", cacheDir.string(), path.string(), depFolder); if (it.contains("branch")) { cloneCommand += std::format(" && git switch {}", it["branch"].get()); @@ -276,11 +279,11 @@ namespace Crafter { // Execute the clone command system(cloneCommand.c_str()); } else if (!it.contains("commit")) { - system(std::format("cd {} && git pull", (project.buildDir/depFolder).string()).c_str()); + system(std::format("cd {} && git pull", (cacheDir/depFolder).string()).c_str()); } // Update path to the project.json of the dependency - path = project.buildDir/ depFolder / "project.json"; + path = cacheDir / depFolder / "project.json"; } // Create a Project object for the dependency