2024-12-29 01:04:33 +01:00
|
|
|
/*
|
|
|
|
|
Crafter.Build
|
2024-12-30 17:21:04 +01:00
|
|
|
Copyright (C) 2024 Catcrafts
|
2024-12-31 20:32:00 +01:00
|
|
|
Catcrafts.net
|
2024-12-29 01:04:33 +01:00
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
2024-12-31 20:32:00 +01:00
|
|
|
version 3.0 of the License, or (at your option) any later version.
|
2024-12-29 01:04:33 +01:00
|
|
|
|
2024-12-30 17:21:04 +01:00
|
|
|
This library is distributed in the hope that it will be useful,
|
2024-12-29 01:04:33 +01:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
License along with this library; if not, write to the Free Software
|
2024-12-31 20:32:00 +01:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2024-12-29 01:04:33 +01:00
|
|
|
*/
|
|
|
|
|
|
2024-12-28 21:00:12 +01:00
|
|
|
module;
|
|
|
|
|
#include "json.hpp"
|
2024-12-30 20:06:48 +01:00
|
|
|
module Crafter.Build;
|
2024-12-28 21:00:12 +01:00
|
|
|
using namespace Crafter::Build;
|
2024-12-29 17:53:46 +01:00
|
|
|
namespace fs = std::filesystem;
|
2024-12-28 21:00:12 +01:00
|
|
|
|
2025-02-03 22:06:54 +01:00
|
|
|
Configuration::Configuration(std::string name, std::string standard, std::vector<fs::path> sourceFiles, std::vector<fs::path> moduleFiles, std::string optimizationLevel, std::string buildDir, std::string outputDir, std::string type, std::string target, std::string march, std::vector<Dependency> dependencies, std::vector<fs::path> additionalFiles, std::vector<std::string> flags): name(name), standard(standard), sourceFiles(sourceFiles), moduleFiles(moduleFiles), optimizationLevel(optimizationLevel), buildDir(buildDir), outputDir(outputDir), type(type), target(target), march(march), dependencies(dependencies), additionalFiles(additionalFiles), flags(flags) {
|
2024-12-28 21:00:12 +01:00
|
|
|
|
|
|
|
|
}
|
2024-12-29 17:53:46 +01:00
|
|
|
|
2024-12-30 20:18:23 +01:00
|
|
|
Configuration::Configuration(const nlohmann::json& configs, const nlohmann::json& config, fs::path workingDir) {
|
2024-12-30 13:48:49 +01:00
|
|
|
name = config["name"].get<std::string>();
|
|
|
|
|
for (auto& [key, val] : config.items())
|
|
|
|
|
{
|
|
|
|
|
if(key == "standard"){
|
|
|
|
|
standard = val.get<std::string>();
|
|
|
|
|
} else if(key == "target") {
|
|
|
|
|
target = val.get<std::string>();
|
|
|
|
|
} else if(key == "type") {
|
|
|
|
|
type = val.get<std::string>();
|
2025-02-03 22:06:54 +01:00
|
|
|
} else if(key == "march") {
|
|
|
|
|
march = val.get<std::string>();
|
2024-12-30 13:48:49 +01:00
|
|
|
} else if(key == "source_files") {
|
|
|
|
|
const std::vector<std::string> tempSourceFiles = val.get<std::vector<std::string>>();
|
|
|
|
|
sourceFiles = std::vector<fs::path>(tempSourceFiles.size());
|
|
|
|
|
for(std::int_fast32_t i = 0; i < sourceFiles.size(); i++){
|
|
|
|
|
const std::filesystem::path filePath (tempSourceFiles[i]);
|
|
|
|
|
const std::filesystem::path fullFilePath = workingDir / filePath;
|
|
|
|
|
sourceFiles[i] = fullFilePath.generic_string();
|
|
|
|
|
}
|
2025-02-03 22:06:54 +01:00
|
|
|
} else if(key == "flags") {
|
|
|
|
|
flags = val.get<std::vector<std::string>>();
|
2024-12-30 13:48:49 +01:00
|
|
|
} else if(key == "module_files") {
|
|
|
|
|
const std::vector<std::string> tempModuleFiles = val.get<std::vector<std::string>>();
|
|
|
|
|
moduleFiles = std::vector<fs::path>(tempModuleFiles.size());
|
|
|
|
|
for(std::int_fast32_t i = 0; i < moduleFiles.size(); i++){
|
|
|
|
|
const std::filesystem::path filePath (tempModuleFiles[i]);
|
|
|
|
|
const std::filesystem::path fullFilePath = workingDir / filePath;
|
|
|
|
|
moduleFiles[i] = fullFilePath.generic_string();
|
|
|
|
|
}
|
2025-01-02 02:53:39 +01:00
|
|
|
} else if(key == "additional_files") {
|
|
|
|
|
const std::vector<std::string> tempAdditionalFiles = val.get<std::vector<std::string>>();
|
|
|
|
|
additionalFiles = std::vector<fs::path>(tempAdditionalFiles.size());
|
|
|
|
|
for(std::int_fast32_t i = 0; i < additionalFiles.size(); i++){
|
|
|
|
|
const std::filesystem::path filePath (tempAdditionalFiles[i]);
|
|
|
|
|
const std::filesystem::path fullFilePath = workingDir / filePath;
|
|
|
|
|
additionalFiles[i] = fullFilePath.generic_string();
|
|
|
|
|
}
|
2024-12-30 13:48:49 +01:00
|
|
|
} else if(key == "optimization_level") {
|
|
|
|
|
optimizationLevel = val.get<std::string>();
|
|
|
|
|
} else if(key == "build_dir") {
|
|
|
|
|
const std::string tempBuildDir = val.get<std::string>();
|
|
|
|
|
const std::filesystem::path buildPath (tempBuildDir);
|
|
|
|
|
const std::filesystem::path fullBuildPath = workingDir / buildPath;
|
|
|
|
|
buildDir = fullBuildPath.generic_string();
|
|
|
|
|
} else if(key == "output_dir") {
|
|
|
|
|
const std::string tempOutputDir = val.get<std::string>();
|
|
|
|
|
const std::filesystem::path outputPath (tempOutputDir);
|
|
|
|
|
const std::filesystem::path fullOutputPath = workingDir / outputPath;
|
|
|
|
|
outputDir = fullOutputPath.generic_string();
|
|
|
|
|
} else if(key == "dependencies") {
|
|
|
|
|
for (auto it : val) {
|
2025-03-29 22:36:43 +01:00
|
|
|
std::string commit;
|
|
|
|
|
std::string branch;
|
|
|
|
|
if(it.contains("commit")){
|
|
|
|
|
commit = it["commit"].get<std::string>();
|
|
|
|
|
}
|
|
|
|
|
if(it.contains("branch")){
|
|
|
|
|
branch = it["branch"].get<std::string>();
|
|
|
|
|
}
|
|
|
|
|
dependencies.emplace_back(it["path"].get<std::string>(), it["configuration"].get<std::string>(), commit, branch);
|
2024-12-30 13:48:49 +01:00
|
|
|
}
|
|
|
|
|
} else if(key != "extends") {
|
|
|
|
|
additionalProperties.insert({key, val});
|
2024-12-29 17:53:46 +01:00
|
|
|
}
|
2024-12-30 13:48:49 +01:00
|
|
|
}
|
|
|
|
|
if(config.contains("extends")) {
|
2024-12-29 17:53:46 +01:00
|
|
|
const std::vector<std::string> extends = config["extends"].get<std::vector<std::string>>();
|
|
|
|
|
for(const std::string& extendName : extends) {
|
2024-12-30 13:48:49 +01:00
|
|
|
for (auto it : configs) {
|
|
|
|
|
if(it["name"].get<std::string>() == extendName) {
|
|
|
|
|
Configuration extendData = Configuration(configs, it, workingDir);
|
2024-12-29 17:53:46 +01:00
|
|
|
if(!extendData.standard.empty() && standard.empty()){
|
|
|
|
|
standard = extendData.standard;
|
|
|
|
|
}
|
|
|
|
|
if(!extendData.sourceFiles.empty()){
|
|
|
|
|
sourceFiles.insert(sourceFiles.end(), extendData.sourceFiles.begin(), extendData.sourceFiles.end());
|
|
|
|
|
}
|
|
|
|
|
if(!extendData.moduleFiles.empty()){
|
|
|
|
|
moduleFiles.insert(moduleFiles.end(), extendData.moduleFiles.begin(), extendData.moduleFiles.end());
|
|
|
|
|
}
|
2025-01-02 02:53:39 +01:00
|
|
|
if(!extendData.additionalFiles.empty()){
|
|
|
|
|
additionalFiles.insert(additionalFiles.end(), extendData.additionalFiles.begin(), extendData.additionalFiles.end());
|
|
|
|
|
}
|
2024-12-29 17:53:46 +01:00
|
|
|
if(!extendData.optimizationLevel.empty() && optimizationLevel.empty()){
|
|
|
|
|
optimizationLevel = extendData.optimizationLevel;
|
|
|
|
|
}
|
|
|
|
|
if(!extendData.dependencies.empty()){
|
|
|
|
|
dependencies.insert(dependencies.end(), extendData.dependencies.begin(), extendData.dependencies.end());
|
|
|
|
|
}
|
|
|
|
|
if(!extendData.buildDir.empty() && buildDir.empty()) {
|
|
|
|
|
buildDir = extendData.buildDir;
|
|
|
|
|
}
|
|
|
|
|
if(!extendData.outputDir.empty() && outputDir.empty()) {
|
|
|
|
|
outputDir = extendData.outputDir;
|
|
|
|
|
}
|
|
|
|
|
if(!extendData.target.empty() && target.empty()) {
|
|
|
|
|
target = extendData.target;
|
|
|
|
|
}
|
|
|
|
|
if(!extendData.type.empty() && type.empty()) {
|
|
|
|
|
type = extendData.type;
|
|
|
|
|
}
|
2025-02-03 22:06:54 +01:00
|
|
|
if(!extendData.march.empty() && march.empty()) {
|
|
|
|
|
march = extendData.march;
|
|
|
|
|
}
|
|
|
|
|
if(!extendData.flags.empty()){
|
|
|
|
|
flags.insert(flags.end(), extendData.flags.begin(), extendData.flags.end());
|
|
|
|
|
}
|
2024-12-29 17:53:46 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|