V2 progress
This commit is contained in:
parent
d2f5863552
commit
5e1fcd8590
9837 changed files with 790 additions and 1708518 deletions
|
|
@ -1,147 +0,0 @@
|
|||
/*
|
||||
Crafter.Build
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
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
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
import Crafter.Build;
|
||||
import std;
|
||||
using namespace Crafter;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
void terminateHandler() {
|
||||
try {
|
||||
if (auto e = std::current_exception()) {
|
||||
std::rethrow_exception(e);
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
std::abort();
|
||||
}
|
||||
#endif//
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
std::set_terminate(terminateHandler);
|
||||
#endif
|
||||
if(std::string(argv[1]) == "--help" || std::string(argv[1]) == "help" ) {
|
||||
std::println("Crafter.Build - A modern build system for C++ projects\n");
|
||||
std::println("Usage: crafter-build [command] [options]");
|
||||
std::println("\nCommands:");
|
||||
std::println(" build\t\tBuild the project");
|
||||
std::println(" test\t\tRun project tests");
|
||||
std::println("\nOptions:");
|
||||
std::println(" --help\tDisplay this help message");
|
||||
std::println(" -p PATH\tSpecify the project file path (default: project.json)");
|
||||
std::println(" -r\t\tRun the built executable after building");
|
||||
return 0;
|
||||
}
|
||||
if(argc < 2 && std::string(argv[1]) == "build") {
|
||||
std::println("Too little arguments provided, use --help for help");
|
||||
return 0;
|
||||
}
|
||||
fs::path filepath = "project.json";
|
||||
std::string configuration;
|
||||
std::string command = std::string(argv[1]);
|
||||
std::string argument;
|
||||
if(argc > 2) {
|
||||
argument = std::string(argv[2]);
|
||||
}
|
||||
|
||||
bool run = false;
|
||||
for (std::uint_fast32_t i = 3; i < argc; i++) {
|
||||
std::string arg = std::string(argv[i]);
|
||||
if(arg == "-r"){
|
||||
run = true;
|
||||
} else if(arg == "-p"){
|
||||
filepath = fs::path(argv[++i]);
|
||||
} else{
|
||||
std::println("Unkown argument: {}", argv[i]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
fs::path projectPath;
|
||||
if(filepath.is_relative()){
|
||||
projectPath = fs::current_path()/filepath;
|
||||
}else{
|
||||
projectPath = filepath;
|
||||
}
|
||||
|
||||
Project project(std::move(projectPath));
|
||||
|
||||
if(command == "build") {
|
||||
std::tuple<Configuration&, BuildResult> config = project.Build(argument);
|
||||
try {
|
||||
if(std::get<1>(config).errors.empty()) {
|
||||
if(run){
|
||||
std::string binDir = std::format("{}/{}", project.binDir.string(), std::get<0>(config).name);
|
||||
if(std::get<0>(config).target == "x86_64-w64-mingw32") {
|
||||
if(std::get<0>(config).debug) {
|
||||
system(std::format("cd {} && wine ./{}.exe", (project.path.parent_path()/binDir).string(), project.name).c_str());
|
||||
//system(std::format("cd {} && lldb -o run {}", (fs::path(projectPath).parent_path()/binDir).string(), project.name).c_str());
|
||||
} else {
|
||||
system(std::format("cd {} && wine ./{}.exe", (project.path.parent_path()/binDir).string(), project.name).c_str());
|
||||
}
|
||||
} else {
|
||||
if(std::get<0>(config).debug) {
|
||||
system(std::format("cd {} && ./{}", (project.path.parent_path()/binDir).string(), project.name).c_str());
|
||||
//system(std::format("cd {} && lldb -o run {}", (fs::path(projectPath).parent_path()/binDir).string(), project.name).c_str());
|
||||
} else {
|
||||
system(std::format("cd {} && ./{}", (project.path.parent_path()/binDir).string(), project.name).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::cout << std::get<1>(config).errors << std::endl;
|
||||
return 1;
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
} else if(command == "test") {
|
||||
bool anyFailed = false;
|
||||
|
||||
if(argument.empty()) {
|
||||
std::vector<TestResult> results = project.RunTests();
|
||||
for(const TestResult& result : results) {
|
||||
if(result.message.empty()) {
|
||||
std::cout << std::format("✅ {}", result.name) << std::endl;
|
||||
} else {
|
||||
std::cout << std::format("❌ {}\t{}", result.name, result.message) << std::endl;
|
||||
anyFailed = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
TestResult result = project.RunTest(argument);
|
||||
if(result.message.empty()) {
|
||||
std::cout << std::format("✅ {}", result.name) << std::endl;
|
||||
} else {
|
||||
std::cout << std::format("❌ {}\t{}", result.name, result.message) << std::endl;
|
||||
anyFailed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return anyFailed ? 1 : 0;
|
||||
} else {
|
||||
std::println("Unkown command: {}", command);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue