Crafter.Build/implementations/Crafter.Build-Implementation.cpp

58 lines
2.3 KiB
C++
Raw Normal View History

2026-07-23 01:24:42 +02:00
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
2025-10-31 16:50:47 +01:00
module Crafter.Build:Implementation_impl;
import std;
import :Implementation;
2026-04-27 07:04:42 +02:00
import :Interface;
import :Platform;
2025-10-31 16:50:47 +01:00
namespace fs = std::filesystem;
namespace Crafter {
Implementation::Implementation(fs::path&& path) : path(std::move(path)) {
}
2026-04-27 07:04:42 +02:00
bool Implementation::Check(const fs::path& buildDir, const fs::path& pcmDir, fs::file_time_type sourceFloor) const {
2026-07-23 01:24:42 +02:00
std::string objPath = std::format("{}_impl.o", (buildDir/path.filename()).string());
std::string cppPath = std::format("{}.cpp", path.string());
2026-04-27 07:04:42 +02:00
if(!fs::exists(objPath) || std::max(fs::last_write_time(cppPath), sourceFloor) >= fs::last_write_time(objPath)) {
2025-10-31 16:50:47 +01:00
return true;
}
2026-04-27 07:04:42 +02:00
fs::file_time_type objTime = fs::last_write_time(objPath);
for(ModulePartition* dependency : partitionDependencies) {
if(dependency->Check(pcmDir, sourceFloor)) return true;
}
for(Module* dependency : moduleDependencies) {
if(dependency->Check(pcmDir, sourceFloor)) return true;
}
for(const auto& [externalMod, externalPcmPath] : externalModuleDependencies) {
std::error_code ec;
fs::file_time_type pcmTime = fs::last_write_time(externalPcmPath, ec);
if (!ec && pcmTime >= objTime) return true;
}
return false;
2025-10-31 16:50:47 +01:00
}
2026-04-23 01:57:25 +02:00
void Implementation::Compile(const std::string_view clang, const fs::path& buildDir, std::atomic<bool>& buildCancelled, std::string& buildError) const {
2025-10-31 16:50:47 +01:00
for(ModulePartition* dependency : partitionDependencies) {
if(!dependency->compiled.load()) {
2026-04-27 07:04:42 +02:00
dependency->compiled.wait(false);
2025-10-31 16:50:47 +01:00
}
}
for(Module* dependency : moduleDependencies) {
if(!dependency->compiled.load()) {
2026-04-27 07:04:42 +02:00
dependency->compiled.wait(false);
2025-10-31 16:50:47 +01:00
}
}
2026-04-23 01:57:25 +02:00
2026-04-27 07:04:42 +02:00
if (buildCancelled.load(std::memory_order_relaxed)) {
2026-04-23 01:57:25 +02:00
return;
}
std::string result = RunCommand(std::format("{} {}.cpp -c -o {}_impl.o", clang, path.string(), (buildDir/path.filename()).string()));
2026-04-27 07:04:42 +02:00
bool expected = false;
if(!result.empty() && buildCancelled.compare_exchange_strong(expected, true)) {
buildError = std::move(result);
}
2025-10-31 16:50:47 +01:00
}
}