diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 6f7b609..f9b8e2a 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -15,5 +15,5 @@ jobs: - uses: actions/checkout@v4 - name: Install Packages run: sudo apt update && sudo apt install build-essential - - name: Build BTB - run: make build-btb \ No newline at end of file + - name: Build NeBuild + run: make build-nebuild \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1511910..16285f7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ syntax: glob html/ latex/ -btb +nebuild .cmake/ .qtc_clangd/ diff --git a/BTBKit/Macros.h b/BTBKit/Macros.h deleted file mode 100644 index c2d6194..0000000 --- a/BTBKit/Macros.h +++ /dev/null @@ -1,34 +0,0 @@ -// ============================================================= // -// btb -// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. -// ============================================================= // - -#pragma once - -extern "C" { -#include -} - -#include - -#define LIKELY(ARG) ((ARG) ? assert(false) : ((void) 0)) -#define UNLIKELY(ARG) LIKELY(!(ARG)) - -#define LIBBTB_VERSION "v0.0.1-libBTB" - -#define LIBBTB_VERSION_BCD 0x0001 - -#define LIBBTB_VERSION_MAJOR 1 -#define LIBBTB_VERSION_MINOR 1 -#define LIBBTB_VERSION_PATCH 0 - -#define LIBBTB_UNUSED(X) ((void) X) - -namespace BTB::Logger { -/// @brief replacement for std::cout for BTB logging. -inline std::ostream& info() noexcept { - auto& out = std::cout; - out << rang::fg::red << "btb: " << rang::style::reset; - return out; -} -} // namespace BTB::Logger diff --git a/CREDITS b/CREDITS index 9b99798..fc97a0a 100644 --- a/CREDITS +++ b/CREDITS @@ -1,2 +1,3 @@ rang: https://github.com/agauniyal/rang -json: https://github.com/nlohmann/json \ No newline at end of file +json: https://github.com/nlohmann/json +toml++: https://marzer.github.io/tomlplusplus/ \ No newline at end of file diff --git a/GNUmakefile b/GNUmakefile index f3c888f..a195f86 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,23 +1,23 @@ SUDO=sudo GCC=g++ GCC_MINGW=x86_64-w64-mingw32-g++ -CXXFLAGS=-I./ -I./vendor +CXXFLAGS=-I./dev -I./vendor CXXSTD= -std=c++20 -SRC=$(wildcard cli/*.cc) $(wildcard src/*.cc) -OUT=btb +SRC=$(wildcard dev/cli/*.cc) $(wildcard dev/src/*.cc) +OUT=nebuild CP=cp -.PHONY: build-btb -build-btb: +.PHONY: build-nebuild +build-nebuild: $(SUDO) $(GCC) $(CXXFLAGS) $(SRC) $(CXXSTD) -o $(OUT) $(SUDO) $(CP) $(OUT) /usr/local/bin -.PHONY: build-btb-windows -build-btb-windows: +.PHONY: build-nebuild-windows +build-nebuild-windows: $(GCC_MINGW) $(CXXFLAGS) $(SRC) -o $(OUT).exe .PHONY: help help: @echo "=> help: Show this help message." - @echo "=> build-btb-windows: Build BTB for Windows." - @echo "=> build-btb: Build BTB for POSIX." + @echo "=> build-nebuild-windows: Build NeBuild for Windows." + @echo "=> build-nebuild: Build NeBuild for POSIX." diff --git a/ReadMe.md b/ReadMe.md index 2edd5ce..d3430be 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,20 +1,19 @@ -# BTB. +# NeBuild -![CI](https://github.com/amlel-el-mahrouss/btb/actions/workflows/c-cpp.yml/badge.svg) +![CI](https://github.com/nekernel-ort/nebuild/actions/workflows/c-cpp.yml/badge.svg) [![License: GPL-3.0](https://img.shields.io/badge/license-BSD--3.0-blue.svg)](LICENSE) -[![QEMU Tested](https://img.shields.io/badge/QEMU-Tested-success)](#) -## Installation requirements: +## Requirements: - GNU C++ - GNU Make -## Steps (GNU Make): +## Guide (GNU Make): -- Run make `build-btb-core` and `build-btb`. +- Run make `build-nebuild-core` and `build-nebuild`. -## Steps (BTB): +## Guide (NeBuild): -- Run `btb` and pass the path to the manifest file. +- Run `nebuild` and pass the path to the manifest file. -###### Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. All rights reserved. +###### Copyright (C) 2024-2025, Amlal El Mahrouss and NeKernel.org Authors, all rights reserved. diff --git a/compile_flags.txt b/compile_flags.txt index 3edd1b0..460f642 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,3 +1,4 @@ -std=c++20 --I./ --Ivendor \ No newline at end of file +-Idev/ +-Ivendor +-xc++ \ No newline at end of file diff --git a/dev/BuildKit/Defines.h b/dev/BuildKit/Defines.h new file mode 100644 index 0000000..d408058 --- /dev/null +++ b/dev/BuildKit/Defines.h @@ -0,0 +1,30 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#pragma once + +#include + +#define LIKELY(ARG) ((ARG) ? assert(false) : ((void) 0)) +#define UNLIKELY(ARG) LIKELY(!(ARG)) + +#define LIBNEBUILD_VERSION "v0.0.1-libNeBuild" + +#define LIBNEBUILD_VERSION_BCD 0x0001 + +#define LIBNEBUILD_VERSION_MAJOR 1 +#define LIBNEBUILD_VERSION_MINOR 1 +#define LIBNEBUILD_VERSION_PATCH 0 + +#define LIBNEBUILD_UNUSED(X) ((void) X) + +namespace NeBuild::Logger { +/// @brief replacement for std::cout for NeBuild logging. +inline std::ostream& info() noexcept { + auto& out = std::cout; + out << rang::fg::red << "nebuild: " << rang::style::reset; + return out; +} +} // namespace NeBuild::Logger diff --git a/BTBKit/IManifestBuilder.h b/dev/BuildKit/IManifestBuilder.h similarity index 65% rename from BTBKit/IManifestBuilder.h rename to dev/BuildKit/IManifestBuilder.h index e11d431..c1d45d0 100644 --- a/BTBKit/IManifestBuilder.h +++ b/dev/BuildKit/IManifestBuilder.h @@ -1,21 +1,20 @@ // ============================================================= // -// btb +// nebuild // Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. // ============================================================= // #pragma once -#include -#include +#include -#define BTB_MANIFEST_BUILDER : public BTB::IManifestBuilder +#define NEBUILD_MANIFEST_BUILDER : public NeBuild::IManifestBuilder -namespace BTB { +namespace NeBuild { /// @brief Builder interface class. /// @note This class is meant to be used as an interface. class IManifestBuilder { public: - IManifestBuilder() = default; + IManifestBuilder() = default; virtual ~IManifestBuilder() = default; IManifestBuilder& operator=(const IManifestBuilder&) = default; @@ -26,7 +25,7 @@ class IManifestBuilder { /// @param arg_val filename path. /// @retval true succeeded. /// @retval false failed. - virtual bool buildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) = 0; - virtual const char* buildSystem() = 0; + virtual bool BuildTarget(const std::string& arg, const bool dry_run = false) = 0; + virtual const char* BuildSystem() = 0; }; -} // namespace BTB \ No newline at end of file +} // namespace NeBuild \ No newline at end of file diff --git a/BTBKit/Includes.h b/dev/BuildKit/Imports.h similarity index 71% rename from BTBKit/Includes.h rename to dev/BuildKit/Imports.h index 3695d53..c542737 100644 --- a/BTBKit/Includes.h +++ b/dev/BuildKit/Imports.h @@ -1,11 +1,13 @@ // ============================================================= // -// btb +// nebuild // Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. // ============================================================= // -#ifndef BTB_INCLUDES_H -#define BTB_INCLUDES_H +#ifndef NEBUILD_INCLUDES_H +#define NEBUILD_INCLUDES_H +#include +#include #include #include #include @@ -14,4 +16,4 @@ #include #include -#endif // BTB_INCLUDES_H +#endif // NEBUILD_INCLUDES_H diff --git a/BTBKit/JSONManifestBuilder.h b/dev/BuildKit/JSONManifestBuilder.h similarity index 59% rename from BTBKit/JSONManifestBuilder.h rename to dev/BuildKit/JSONManifestBuilder.h index f5d874c..63a67b7 100644 --- a/BTBKit/JSONManifestBuilder.h +++ b/dev/BuildKit/JSONManifestBuilder.h @@ -1,18 +1,21 @@ // ============================================================= // -// btb +// nebuild // Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. // ============================================================= // #pragma once -#include -#include +#include +#include -namespace BTB { +/// @file JSONManifestBuilder.h +/// @brief JSON manifest builder header file. + +namespace NeBuild { /// @brief JSON builder -class JSONManifestBuilder final BTB_MANIFEST_BUILDER { +class JSONManifestBuilder final NEBUILD_MANIFEST_BUILDER { public: - JSONManifestBuilder() = default; + JSONManifestBuilder() = default; ~JSONManifestBuilder() override = default; JSONManifestBuilder& operator=(const JSONManifestBuilder&) = default; @@ -24,7 +27,7 @@ class JSONManifestBuilder final BTB_MANIFEST_BUILDER { /// @param arg_val filename path. /// @retval true build succeeded. /// @retval false failed to build. - bool buildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) override; - const char* buildSystem() override; + bool BuildTarget(const std::string& arg_val, const bool dry_run = false) override; + const char* BuildSystem() override; }; -} // namespace BTB \ No newline at end of file +} // namespace NeBuild \ No newline at end of file diff --git a/dev/BuildKit/TOMLManifestBuilder.h b/dev/BuildKit/TOMLManifestBuilder.h new file mode 100644 index 0000000..10a8200 --- /dev/null +++ b/dev/BuildKit/TOMLManifestBuilder.h @@ -0,0 +1,33 @@ +// ============================================================= // +// nebuild +// Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +// ============================================================= // + +#pragma once + +#include +#include + +/// @file TOMLManifestBuilder.h +/// @brief TOML manifest builder header file. + +namespace NeBuild { +/// @brief TOML builder +class TOMLManifestBuilder final NEBUILD_MANIFEST_BUILDER { + public: + TOMLManifestBuilder() = default; + ~TOMLManifestBuilder() override = default; + + TOMLManifestBuilder& operator=(const TOMLManifestBuilder&) = default; + TOMLManifestBuilder(const TOMLManifestBuilder&) = default; + + public: + /// @brief Builds a TOML target. + /// @param arg_sz filename size + /// @param arg_val filename path. + /// @retval true build succeeded. + /// @retval false failed to build. + bool BuildTarget(int arg_sz, const char* arg_val, const bool dry_run = false) override; + const char* BuildSystem() override; +}; +} // namespace NeBuild \ No newline at end of file diff --git a/cli/CommandLine.cc b/dev/cli/Tool.cc similarity index 62% rename from cli/CommandLine.cc rename to dev/cli/Tool.cc index 300db6f..1d49c9f 100644 --- a/cli/CommandLine.cc +++ b/dev/cli/Tool.cc @@ -1,11 +1,10 @@ // ============================================================= // -// btb +// nebuild // Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. // ============================================================= // -#include -#include +#include static bool kFailed = false; static bool kDryRun = false; @@ -17,51 +16,51 @@ int main(int argc, char** argv) { std::string index_path = argv[index]; if (index_path == "-v" || index_path == "--version") { - BTB::Logger::info() << "Brought to you by Amlal El Mahrouss for the NeKernel project.\n"; - BTB::Logger::info() << "© 2024-2025 Amlal El Mahrouss, all rights reserved.\n"; + NeBuild::Logger::info() << "Brought to you by Amlal El Mahrouss for NeKernel.org.\n"; + NeBuild::Logger::info() << "© 2024-2025 Amlal El Mahrouss, all rights reserved.\n"; - BTB::Logger::info() - << "Bugs, issues? Check out: https://github.com/nekernel-org/btb/issues\n"; + NeBuild::Logger::info() + << "Bugs, issues? Check out: https://github.com/nekernel-org/nebuild/issues\n"; return EXIT_SUCCESS; } else if (index_path == "--dry-run") { kDryRun = true; continue; } else if (index_path == "-h" || index_path == "--help") { - BTB::Logger::info() << "Usage: btb \n"; + NeBuild::Logger::info() << "Usage: nebuild \n"; return EXIT_SUCCESS; } if (index_path.starts_with("-")) { - BTB::Logger::info() << "error: unknown option '" << index_path << "'\n"; + NeBuild::Logger::info() << "error: unknown option '" << index_path << "'\n"; return EXIT_FAILURE; } std::thread job_build_thread( [](std::string index_path) -> void { - BTB::IManifestBuilder* builder = nullptr; + NeBuild::IManifestBuilder* builder = nullptr; const auto kJsonExtension = ".json"; if (index_path.ends_with(kJsonExtension)) { - builder = new BTB::JSONManifestBuilder(); + builder = new NeBuild::JSONManifestBuilder(); if (!builder) { kFailed = true; return; } } else { - BTB::Logger::info() << "error: file '" << index_path << "' is not a JSON file!" - << std::endl; + NeBuild::Logger::info() + << "error: file '" << index_path << "' is not a JSON file!" << std::endl; kFailed = true; return; } - BTB::Logger::info() << "building manifest: " << index_path << std::endl; + NeBuild::Logger::info() << "building manifest: " << index_path << std::endl; - if (builder && !builder->buildTarget(index_path.size(), index_path.c_str(), kDryRun)) { + if (builder && !builder->BuildTarget(index_path, kDryRun)) { kFailed = true; } diff --git a/src/IManifestBuilder.cc b/dev/src/IManifestBuilder.cc similarity index 80% rename from src/IManifestBuilder.cc rename to dev/src/IManifestBuilder.cc index b3f4de8..1397dd4 100644 --- a/src/IManifestBuilder.cc +++ b/dev/src/IManifestBuilder.cc @@ -1,6 +1,6 @@ // ============================================================= // -// btb +// nebuild // Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. // ============================================================= // -#include +#include diff --git a/src/JSONManifestBuilder.cc b/dev/src/JSONManifestBuilder.cc similarity index 55% rename from src/JSONManifestBuilder.cc rename to dev/src/JSONManifestBuilder.cc index 46a8518..33d7f62 100644 --- a/src/JSONManifestBuilder.cc +++ b/dev/src/JSONManifestBuilder.cc @@ -1,32 +1,33 @@ // ============================================================= // -// btb +// nebuild // Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. // ============================================================= // -#include +#include + +using JSON = nlohmann::json; -using String = std::string; -using JSON = nlohmann::json; namespace FS = std::filesystem; -using namespace BTB; +using namespace NeBuild; /// @brief Builds a JSON target from a JSON file. /// @param arg_sz filename size (must be 1 or greater). /// @param arg_val filename path (must be a valid JSON file). -/// @retval true succeeded building. +/// @retval true building has succeeded. /// @retval false fail to build, see error message. -bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const bool dry_run) { - String path; +bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dry_run) { + std::string path; - if (arg_sz < 0) { - BTB::Logger::info() << "btb: error: file path is empty" << std::endl; + if (argv_val.empty()) { + NeBuild::Logger::info() << "nebuild: error: file path is empty" << std::endl; return false; } else { - path = arg_val; + path = argv_val; if (!FS::exists(path)) { - BTB::Logger::info() << "btb: error: file '" << path << "' does not exist" << std::endl; + NeBuild::Logger::info() << "nebuild: error: file '" << path << "' does not exist" + << std::endl; return false; } } @@ -35,48 +36,49 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo std::ifstream json(path); if (!json.good()) { - BTB::Logger::info() << "btb: error: file '" << path << "' is not a valid JSON" << std::endl; + NeBuild::Logger::info() << "nebuild: error: file '" << path << "' is not a valid JSON" + << std::endl; return false; } JSON json_obj = JSON::parse(json); - String compiler = json_obj["compiler_path"].get(); + std::string compiler = json_obj["compiler_path"].get(); JSON header_search_path = json_obj["headers_path"]; JSON sources_files = json_obj["sources_path"]; - String command = compiler + " "; + std::string command = compiler + " "; for (auto& sources : sources_files) { - command += sources.get() + " "; + command += sources.get() + " "; } for (auto& headers : header_search_path) { - command += "-I" + headers.get() + " "; + command += "-I" + headers.get() + " "; } JSON macros_list = json_obj["cpp_macros"]; for (auto& macro : macros_list) { - command += "-D" + macro.get() + " "; + command += "-D" + macro.get() + " "; } JSON compiler_flags = json_obj["compiler_flags"]; for (auto& flag : compiler_flags) { - command += flag.get() + " "; + command += flag.get() + " "; } if (json_obj["compiler_std"].is_string()) - command += "-std=" + json_obj["compiler_std"].get() + " "; + command += "-std=" + json_obj["compiler_std"].get() + " "; - command += "-o " + json_obj["output_name"].get(); + command += "-o " + json_obj["output_name"].get(); - auto target = json_obj["output_name"].get(); + auto target = json_obj["output_name"].get(); - BTB::Logger::info() << "output path: " << target << "\n"; - BTB::Logger::info() << "command: " << command << "\n"; + NeBuild::Logger::info() << "output path: " << target << "\n"; + NeBuild::Logger::info() << "command: " << command << "\n"; try { if (json_obj["dry_run"].get()) return true; @@ -90,15 +92,16 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo auto ret_exec = std::system(command.c_str()); if (ret_exec > 0) { - BTB::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" << std::endl; + NeBuild::Logger::info() << "error: exit with message: " << std::strerror(ret_exec) << "" + << std::endl; return false; } try { if (json_obj["run_after_build"].get()) { if (target.ends_with(".so")) { - BTB::Logger::info() << "error: can't open dynamic library, it mayn't have an entrypoint" - << std::endl; + NeBuild::Logger::info() + << "error: can't open dynamic library, it mayn't have an entrypoint" << std::endl; return true; } else if (target.ends_with(".dylib") || target.ends_with(".dll")) { @@ -107,21 +110,21 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo ss << file.rdbuf(); - if (ss.str()[0] == 'J' && ss.str()[1] == 'o' && ss.str()[2] == 'y' && ss.str()[3] == '!') - BTB::Logger::info() + if (ss.str()[0] == 'O' && ss.str()[1] == 'p' && ss.str()[2] == 'e' && ss.str()[3] == 'n') + NeBuild::Logger::info() << "error: can't open PEF dynamic library, it mayn't contain an entrypoint" << std::endl; - else if (ss.str()[0] == '!' && ss.str()[1] == 'y' && ss.str()[2] == 'o' && - ss.str()[3] == 'J') - BTB::Logger::info() + else if (ss.str()[0] == 'n' && ss.str()[1] == 'e' && ss.str()[2] == 'p' && + ss.str()[3] == 'O') + NeBuild::Logger::info() << "error: can't open FEP dynamic library, it mayn't contain an entrypoint" << std::endl; else if (ss.str()[0] == 'M' && ss.str()[1] == 'Z') - BTB::Logger::info() + NeBuild::Logger::info() << "error: can't open MZ dynamic library, it mayn't contain an entrypoint" << std::endl; else if (ss.str()[0] == 0x7F && ss.str()[1] == 'E') { - BTB::Logger::info() + NeBuild::Logger::info() << "error: can't open ELF dynamic library, it mayn't contain an entrypoint" << std::endl; } @@ -129,7 +132,7 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo return true; } -#if defined(BTB_WINDOWS) +#if defined(NEBUILD_WINDOWS) std::system((".\\" + target).c_str()); #else std::system(("./" + target).c_str()); @@ -139,7 +142,7 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo return true; } } catch (std::runtime_error& err) { - BTB::Logger::info() << "error: " << err.what() << std::endl; + NeBuild::Logger::info() << "error: " << err.what() << std::endl; return false; } @@ -147,6 +150,6 @@ bool JSONManifestBuilder::buildTarget(int arg_sz, const char* arg_val, const boo return true; } -const char* JSONManifestBuilder::buildSystem() { - return "json"; +const char* JSONManifestBuilder::BuildSystem() { + return "NeBuild (JSON)"; } diff --git a/examples/example_02_libbtb/libbtb.cc b/examples/example_02_libbtb/libbtb.cc deleted file mode 100644 index f3d45b8..0000000 --- a/examples/example_02_libbtb/libbtb.cc +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#ifndef _WIN32 -static auto kPath = "./posix.json"; -#else -static auto kPath = ".\win64.json"; -#endif - -int main(int argc, char** argv) { - auto builder = new BTB::JSONManifestBuilder(); - return builder->buildTarget(strlen(kPath), kPath); -} diff --git a/examples/example_02_libbtb/README.md b/examples/example_02_libnebuild/README.md similarity index 69% rename from examples/example_02_libbtb/README.md rename to examples/example_02_libnebuild/README.md index 26ccb72..21e64be 100644 --- a/examples/example_02_libbtb/README.md +++ b/examples/example_02_libnebuild/README.md @@ -1,6 +1,6 @@ # Notice for Deployment. -In order to use libBTB, it shall live on the same directory, +In order to use libNeBuild, it shall live on the same directory,
or within a directory recognized in the `$LD_LIBRARY_PATH` or `$DYLD_LIBRARY_PATH` variable. diff --git a/examples/example_02_libnebuild/libnebuild.cc b/examples/example_02_libnebuild/libnebuild.cc new file mode 100644 index 0000000..5540503 --- /dev/null +++ b/examples/example_02_libnebuild/libnebuild.cc @@ -0,0 +1,15 @@ +#include +#include + +#ifndef _WIN32 +static auto kPath = "./posix.json"; +#else +static auto kPath = ".\\win64.json"; +#endif + +int main(int argc, char** argv) { + auto builder = new NeBuild::JSONManifestBuilder(); + if (!builder) return EXIT_FAILURE; + + return builder->BuildTarget(kPath); +} diff --git a/examples/example_02_libbtb/posix.json b/examples/example_02_libnebuild/posix.json similarity index 73% rename from examples/example_02_libbtb/posix.json rename to examples/example_02_libnebuild/posix.json index 871712e..989e712 100644 --- a/examples/example_02_libbtb/posix.json +++ b/examples/example_02_libnebuild/posix.json @@ -2,16 +2,16 @@ "compiler_path": "g++", "compiler_std": "c++20", "headers_path": [ - "../../", + "../../dev", "../../vendor" ], "sources_path": [ - "libbtb.cc" + "libnebuild.cc" ], - "output_name": "libbtb.elf", + "output_name": "libnebuild.elf", "compiler_flags": [ "-L/usr/local/lib", - "-lBTB" + "-lNeBuild" ], "cpp_macros": [ "FOO_MACRO" diff --git a/examples/example_02_libbtb/win64.json b/examples/example_02_libnebuild/win64.json similarity index 89% rename from examples/example_02_libbtb/win64.json rename to examples/example_02_libnebuild/win64.json index 658ee0f..3118a36 100644 --- a/examples/example_02_libbtb/win64.json +++ b/examples/example_02_libnebuild/win64.json @@ -2,7 +2,7 @@ "compiler_path": "x86_64-w64-mingw32-g++", "compiler_std": "c++20", "headers_path": [ - "../../", + "../../dev", "../../vendor" ], "sources_path": [ @@ -10,7 +10,7 @@ ], "output_name": "libbtb.exe", "compiler_flags": [ - "-lBTB" + "-lNeBuild" ], "cpp_macros": [ "FOO_MACRO" diff --git a/osx-dylib.json b/osx-dylib.json index 80917d2..7f7648d 100644 --- a/osx-dylib.json +++ b/osx-dylib.json @@ -1,10 +1,10 @@ { "compiler_path": "g++", "compiler_std": "c++20", - "headers_path": ["./", "vendor"], - "sources_path": ["src/*.cc"], - "output_name": "libBTB.dylib", + "headers_path": ["dev", "vendor"], + "sources_path": ["dev/src/*.cc"], + "output_name": "libNeBuild.dylib", "compiler_flags": ["-fPIC", "-shared"], - "cpp_macros": ["BTB_POSIX", "BTB_OSX"], + "cpp_macros": ["NEBUILD_DYLIB", "NEBUILD_OSX"], "run_after_build": false } diff --git a/osx.json b/osx.json index 20d513d..8e247d9 100644 --- a/osx.json +++ b/osx.json @@ -1,10 +1,10 @@ { "compiler_path": "g++", "compiler_std": "c++20", - "headers_path": ["./", "vendor"], - "sources_path": ["src/*.cc", "cli/*.cc"], - "output_name": "btb", + "headers_path": ["dev", "vendor"], + "sources_path": ["dev/src/*.cc", "dev/cli/*.cc"], + "output_name": "nebuild", "compiler_flags": ["-fPIC"], - "cpp_macros": ["BTB_POSIX", "BTB_OSX"], + "cpp_macros": ["NEBUILD_POSIX", "NEBUILD_OSX"], "run_after_build": false } diff --git a/posix.json b/posix.json index e53cc14..5281d4d 100644 --- a/posix.json +++ b/posix.json @@ -1,10 +1,10 @@ { "compiler_path": "g++", "compiler_std": "c++20", - "headers_path": ["./", "vendor"], - "sources_path": ["src/*.cc", "cli/*.cc"], - "output_name": "btb", + "headers_path": ["dev/", "vendor"], + "sources_path": ["dev/src/*.cc", "dev/cli/*.cc"], + "output_name": "nebuild", "compiler_flags": ["-fPIC"], - "cpp_macros": ["BTB_POSIX"], + "cpp_macros": ["NEBUILD_POSIX"], "run_after_build": false } diff --git a/vendor/.keep b/vendor/.keep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/json.h b/vendor/json/json.h similarity index 100% rename from vendor/json.h rename to vendor/json/json.h diff --git a/vendor/json_fwd.h b/vendor/json/json_fwd.h similarity index 100% rename from vendor/json_fwd.h rename to vendor/json/json_fwd.h diff --git a/vendor/rang.h b/vendor/rang/rang.h similarity index 100% rename from vendor/rang.h rename to vendor/rang/rang.h diff --git a/vendor/toml++/impl/array.hpp b/vendor/toml++/impl/array.hpp new file mode 100644 index 0000000..ad79379 --- /dev/null +++ b/vendor/toml++/impl/array.hpp @@ -0,0 +1,1790 @@ +//# This file is a part of toml++ and is subject to the the terms of the MIT license. +//# Copyright (c) Mark Gillard +//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text. +// SPDX-License-Identifier: MIT +#pragma once + +#include "std_utility.hpp" +#include "std_vector.hpp" +#include "std_initializer_list.hpp" +#include "value.hpp" +#include "make_node.hpp" +#include "header_start.hpp" + +#ifndef TOML_RETURN_BOOL_FROM_FOR_EACH_BROKEN +#if TOML_GCC && TOML_GCC <= 7 +#define TOML_RETURN_BOOL_FROM_FOR_EACH_BROKEN 1 +#else +#define TOML_RETURN_BOOL_FROM_FOR_EACH_BROKEN 0 +#endif +#endif + +#if TOML_RETURN_BOOL_FROM_FOR_EACH_BROKEN && !defined(TOML_RETURN_BOOL_FROM_FOR_EACH_BROKEN_ACKNOWLEDGED) +#define TOML_RETURN_BOOL_FROM_FOR_EACH_BROKEN_MESSAGE \ + "If you're seeing this error it's because you're using one of toml++'s for_each() functions on a compiler with " \ + "known bugs in that area (e.g. GCC 7). On these compilers returning a bool (or bool-convertible) value from the " \ + "for_each() callable causes spurious compilation failures, while returning nothing (void) works fine. " \ + "If you believe this message is incorrect for your compiler, you can try your luck by #defining " \ + "TOML_RETURN_BOOL_FROM_FOR_EACH_BROKEN as 0 and recompiling - if it works, great! Let me know at " \ + "https://github.com/marzer/tomlplusplus/issues. Alternatively, if you don't have any need for early-exiting from " \ + "for_each(), you can suppress this error by #defining TOML_RETURN_BOOL_FROM_FOR_EACH_BROKEN_ACKNOWLEDGED " \ + "and moving on with your life." +#endif + +/// \cond +TOML_IMPL_NAMESPACE_START +{ + template + class TOML_TRIVIAL_ABI array_iterator + { + private: + template + friend class array_iterator; + + using mutable_vector_iterator = std::vector::iterator; + using const_vector_iterator = std::vector::const_iterator; + using vector_iterator = std::conditional_t; + + mutable vector_iterator iter_; + + public: + using value_type = std::conditional_t; + using reference = value_type&; + using pointer = value_type*; + using difference_type = ptrdiff_t; + using iterator_category = typename std::iterator_traits::iterator_category; + + TOML_NODISCARD_CTOR + array_iterator() noexcept = default; + + TOML_NODISCARD_CTOR + explicit array_iterator(mutable_vector_iterator iter) noexcept // + : iter_{ iter } + {} + + TOML_CONSTRAINED_TEMPLATE(C, bool C = IsConst) + TOML_NODISCARD_CTOR + explicit array_iterator(const_vector_iterator iter) noexcept // + : iter_{ iter } + {} + + TOML_CONSTRAINED_TEMPLATE(C, bool C = IsConst) + TOML_NODISCARD_CTOR + array_iterator(const array_iterator& other) noexcept // + : iter_{ other.iter_ } + {} + + TOML_NODISCARD_CTOR + array_iterator(const array_iterator&) noexcept = default; + + array_iterator& operator=(const array_iterator&) noexcept = default; + + array_iterator& operator++() noexcept // ++pre + { + ++iter_; + return *this; + } + + array_iterator operator++(int) noexcept // post++ + { + array_iterator out{ iter_ }; + ++iter_; + return out; + } + + array_iterator& operator--() noexcept // --pre + { + --iter_; + return *this; + } + + array_iterator operator--(int) noexcept // post-- + { + array_iterator out{ iter_ }; + --iter_; + return out; + } + + TOML_PURE_INLINE_GETTER + reference operator*() const noexcept + { + return *iter_->get(); + } + + TOML_PURE_INLINE_GETTER + pointer operator->() const noexcept + { + return iter_->get(); + } + + TOML_PURE_INLINE_GETTER + explicit operator const vector_iterator&() const noexcept + { + return iter_; + } + + TOML_CONSTRAINED_TEMPLATE(!C, bool C = IsConst) + TOML_PURE_INLINE_GETTER + explicit operator const const_vector_iterator() const noexcept + { + return iter_; + } + + array_iterator& operator+=(ptrdiff_t rhs) noexcept + { + iter_ += rhs; + return *this; + } + + array_iterator& operator-=(ptrdiff_t rhs) noexcept + { + iter_ -= rhs; + return *this; + } + + TOML_NODISCARD + friend array_iterator operator+(const array_iterator& lhs, ptrdiff_t rhs) noexcept + { + return array_iterator{ lhs.iter_ + rhs }; + } + + TOML_NODISCARD + friend array_iterator operator+(ptrdiff_t lhs, const array_iterator& rhs) noexcept + { + return array_iterator{ rhs.iter_ + lhs }; + } + + TOML_NODISCARD + friend array_iterator operator-(const array_iterator& lhs, ptrdiff_t rhs) noexcept + { + return array_iterator{ lhs.iter_ - rhs }; + } + + TOML_PURE_INLINE_GETTER + friend ptrdiff_t operator-(const array_iterator& lhs, const array_iterator& rhs) noexcept + { + return lhs.iter_ - rhs.iter_; + } + + TOML_PURE_INLINE_GETTER + friend bool operator==(const array_iterator& lhs, const array_iterator& rhs) noexcept + { + return lhs.iter_ == rhs.iter_; + } + + TOML_PURE_INLINE_GETTER + friend bool operator!=(const array_iterator& lhs, const array_iterator& rhs) noexcept + { + return lhs.iter_ != rhs.iter_; + } + + TOML_PURE_INLINE_GETTER + friend bool operator<(const array_iterator& lhs, const array_iterator& rhs) noexcept + { + return lhs.iter_ < rhs.iter_; + } + + TOML_PURE_INLINE_GETTER + friend bool operator<=(const array_iterator& lhs, const array_iterator& rhs) noexcept + { + return lhs.iter_ <= rhs.iter_; + } + + TOML_PURE_INLINE_GETTER + friend bool operator>(const array_iterator& lhs, const array_iterator& rhs) noexcept + { + return lhs.iter_ > rhs.iter_; + } + + TOML_PURE_INLINE_GETTER + friend bool operator>=(const array_iterator& lhs, const array_iterator& rhs) noexcept + { + return lhs.iter_ >= rhs.iter_; + } + + TOML_PURE_INLINE_GETTER + reference operator[](ptrdiff_t idx) const noexcept + { + return *(iter_ + idx)->get(); + } + }; + + struct array_init_elem + { + mutable node_ptr value; + + template + TOML_NODISCARD_CTOR + array_init_elem(T&& val, value_flags flags = preserve_source_value_flags) // + : value{ make_node(static_cast(val), flags) } + {} + }; +} +TOML_IMPL_NAMESPACE_END; +/// \endcond + +TOML_NAMESPACE_START +{ + /// \brief A RandomAccessIterator for iterating over elements in a toml::array. + using array_iterator = POXY_IMPLEMENTATION_DETAIL(impl::array_iterator); + + /// \brief A RandomAccessIterator for iterating over const elements in a toml::array. + using const_array_iterator = POXY_IMPLEMENTATION_DETAIL(impl::array_iterator); + + /// \brief A TOML array. + /// + /// \detail The interface of this type is modeled after std::vector, with some + /// additional considerations made for the heterogeneous nature of a + /// TOML array. + /// + /// \godbolt{sjK4da} + /// + /// \cpp + /// + /// toml::table tbl = toml::parse(R"( + /// arr = [1, 2, 3, 4, 'five'] + /// )"sv); + /// + /// // get the element as an array + /// toml::array& arr = *tbl.get_as("arr"); + /// std::cout << arr << "\n"; + /// + /// // increment each element with visit() + /// for (auto&& elem : arr) + /// { + /// elem.visit([](auto&& el) noexcept + /// { + /// if constexpr (toml::is_number) + /// (*el)++; + /// else if constexpr (toml::is_string) + /// el = "six"sv; + /// }); + /// } + /// std::cout << arr << "\n"; + /// + /// // add and remove elements + /// arr.push_back(7); + /// arr.push_back(8.0f); + /// arr.push_back("nine"sv); + /// arr.erase(arr.cbegin()); + /// std::cout << arr << "\n"; + /// + /// // emplace elements + /// arr.emplace_back("ten"); + /// arr.emplace_back(11, 12.0); + /// std::cout << arr << "\n"; + /// \ecpp + /// + /// \out + /// [ 1, 2, 3, 4, 'five' ] + /// [ 2, 3, 4, 5, 'six' ] + /// [ 3, 4, 5, 'six', 7, 8.0, 'nine' ] + /// [ 3, 4, 5, 'six', 7, 8.0, 'nine', 'ten', [ 11, 12.0 ] ] + /// \eout + class TOML_EXPORTED_CLASS array : public node + { + private: + /// \cond + + using vector_type = std::vector; + using vector_iterator = typename vector_type::iterator; + using const_vector_iterator = typename vector_type::const_iterator; + vector_type elems_; + + TOML_NODISCARD_CTOR + TOML_EXPORTED_MEMBER_FUNCTION + array(const impl::array_init_elem*, const impl::array_init_elem*); + + TOML_NODISCARD_CTOR + array(std::false_type, std::initializer_list elems) // + : array{ elems.begin(), elems.end() } + {} + + TOML_EXPORTED_MEMBER_FUNCTION + void preinsertion_resize(size_t idx, size_t count); + + TOML_EXPORTED_MEMBER_FUNCTION + void insert_at_back(impl::node_ptr&&); + + TOML_EXPORTED_MEMBER_FUNCTION + vector_iterator insert_at(const_vector_iterator, impl::node_ptr&&); + + template + void emplace_back_if_not_empty_view(T&& val, value_flags flags) + { + if constexpr (is_node_view) + { + if (!val) + return; + } + insert_at_back(impl::make_node(static_cast(val), flags)); + } + + TOML_NODISCARD + TOML_EXPORTED_MEMBER_FUNCTION + size_t total_leaf_count() const noexcept; + + TOML_EXPORTED_MEMBER_FUNCTION + void flatten_child(array&& child, size_t& dest_index) noexcept; + + /// \endcond + + public: + using value_type = node; + using size_type = size_t; + using difference_type = ptrdiff_t; + using reference = node&; + using const_reference = const node&; + + /// \brief Default constructor. + TOML_NODISCARD_CTOR + TOML_EXPORTED_MEMBER_FUNCTION + array() noexcept; + + TOML_EXPORTED_MEMBER_FUNCTION + ~array() noexcept; + + /// \brief Copy constructor. + TOML_NODISCARD_CTOR + TOML_EXPORTED_MEMBER_FUNCTION + array(const array&); + + /// \brief Move constructor. + TOML_NODISCARD_CTOR + TOML_EXPORTED_MEMBER_FUNCTION + array(array&& other) noexcept; + + /// \brief Constructs an array with one or more initial elements. + /// + /// \detail \cpp + /// auto arr = toml::array{ 1, 2.0, "three"sv, toml::array{ 4, 5 } }; + /// std::cout << arr << "\n"; + /// \ecpp + /// + /// \out + /// [ 1, 2.0, 'three', [ 4, 5 ] ] + /// \eout + /// + /// \remark \parblock If you need to construct an array with one child array element, the array's move constructor + /// will take precedence and perform a move-construction instead. You can use toml::inserter to + /// suppress this behaviour: \cpp + /// // desired result: [ [ 42 ] ] + /// auto bad = toml::array{ toml::array{ 42 } } + /// auto good = toml::array{ toml::inserter{ toml::array{ 42 } } } + /// std::cout << "bad: " << bad << "\n"; + /// std::cout << "good:" << good << "\n"; + /// \ecpp + /// + /// \out + /// bad: [ 42 ] + /// good: [ [ 42 ] ] + /// \eout + /// + /// \endparblock + /// + /// \tparam ElemType One of the TOML node or value types (or a type promotable to one). + /// \tparam ElemTypes One of the TOML node or value types (or a type promotable to one). + /// \param val The node or value used to initialize element 0. + /// \param vals The nodes or values used to initialize elements 1...N. + TOML_CONSTRAINED_TEMPLATE((sizeof...(ElemTypes) > 0 || !std::is_same_v, array>), + typename ElemType, + typename... ElemTypes) + TOML_NODISCARD_CTOR + explicit array(ElemType&& val, ElemTypes&&... vals) + : array{ std::false_type{}, + std::initializer_list{ static_cast(val), + static_cast(vals)... } } + {} + + /// \brief Copy-assignment operator. + TOML_EXPORTED_MEMBER_FUNCTION + array& operator=(const array&); + + /// \brief Move-assignment operator. + TOML_EXPORTED_MEMBER_FUNCTION + array& operator=(array&& rhs) noexcept; + + /// \name Type checks + /// @{ + + /// \brief Returns #toml::node_type::array. + TOML_CONST_INLINE_GETTER + node_type type() const noexcept final + { + return node_type::array; + } + + TOML_PURE_GETTER + TOML_EXPORTED_MEMBER_FUNCTION + bool is_homogeneous(node_type ntype) const noexcept final; + + TOML_PURE_GETTER + TOML_EXPORTED_MEMBER_FUNCTION + bool is_homogeneous(node_type ntype, node*& first_nonmatch) noexcept final; + + TOML_PURE_GETTER + TOML_EXPORTED_MEMBER_FUNCTION + bool is_homogeneous(node_type ntype, const node*& first_nonmatch) const noexcept final; + + /// \cond + template + TOML_PURE_GETTER + bool is_homogeneous() const noexcept + { + using type = impl::remove_cvref>; + static_assert(std::is_void_v || toml::is_value || toml::is_container, + "The template type argument of array::is_homogeneous() must be void or one " + "of:" TOML_SA_UNWRAPPED_NODE_TYPE_LIST); + + return is_homogeneous(impl::node_type_of); + } + /// \endcond + + /// \brief Returns `false`. + TOML_CONST_INLINE_GETTER + bool is_table() const noexcept final + { + return false; + } + + /// \brief Returns `true`. + TOML_CONST_INLINE_GETTER + bool is_array() const noexcept final + { + return true; + } + + /// \brief Returns `true` if the array contains only tables. + TOML_PURE_GETTER + bool is_array_of_tables() const noexcept final + { + return is_homogeneous(node_type::table); + } + + /// \brief Returns `false`. + TOML_CONST_INLINE_GETTER + bool is_value() const noexcept final + { + return false; + } + + /// \brief Returns `false`. + TOML_CONST_INLINE_GETTER + bool is_string() const noexcept final + { + return false; + } + + /// \brief Returns `false`. + TOML_CONST_INLINE_GETTER + bool is_integer() const noexcept final + { + return false; + } + + /// \brief Returns `false`. + TOML_CONST_INLINE_GETTER + bool is_floating_point() const noexcept final + { + return false; + } + + /// \brief Returns `false`. + TOML_CONST_INLINE_GETTER + bool is_number() const noexcept final + { + return false; + } + + /// \brief Returns `false`. + TOML_CONST_INLINE_GETTER + bool is_boolean() const noexcept final + { + return false; + } + + /// \brief Returns `false`. + TOML_CONST_INLINE_GETTER + bool is_date() const noexcept final + { + return false; + } + + /// \brief Returns `false`. + TOML_CONST_INLINE_GETTER + bool is_time() const noexcept final + { + return false; + } + + /// \brief Returns `false`. + TOML_CONST_INLINE_GETTER + bool is_date_time() const noexcept final + { + return false; + } + + /// @} + + /// \name Type casts + /// @{ + + /// \brief Returns `nullptr`. + TOML_CONST_INLINE_GETTER + table* as_table() noexcept final + { + return nullptr; + } + + /// \brief Returns a pointer to the array. + TOML_CONST_INLINE_GETTER + array* as_array() noexcept final + { + return this; + } + + /// \brief Returns `nullptr`. + TOML_CONST_INLINE_GETTER + toml::value* as_string() noexcept final + { + return nullptr; + } + + /// \brief Returns `nullptr`. + TOML_CONST_INLINE_GETTER + toml::value* as_integer() noexcept final + { + return nullptr; + } + + /// \brief Returns `nullptr`. + TOML_CONST_INLINE_GETTER + toml::value* as_floating_point() noexcept final + { + return nullptr; + } + + /// \brief Returns `nullptr`. + TOML_CONST_INLINE_GETTER + toml::value* as_boolean() noexcept final + { + return nullptr; + } + + /// \brief Returns `nullptr`. + TOML_CONST_INLINE_GETTER + toml::value* as_date() noexcept final + { + return nullptr; + } + + /// \brief Returns `nullptr`. + TOML_CONST_INLINE_GETTER + toml::value