diff options
| -rw-r--r-- | examples/example_02_libnebuild/libnebuild.cc | 10 | ||||
| -rw-r--r-- | include/NeBuildKit/Config.h | 21 | ||||
| -rw-r--r-- | include/NeBuildKit/IManifestBuilder.h | 5 | ||||
| -rw-r--r-- | include/NeBuildKit/JSONManifestBuilder.h | 6 | ||||
| -rw-r--r-- | include/NeBuildKit/TOMLManifestBuilder.h | 6 | ||||
| -rw-r--r-- | src/cli/main.cc | 22 | ||||
| -rw-r--r-- | src/lib/JSONManifestBuilder.cc | 8 | ||||
| -rw-r--r-- | src/lib/TOMLManifestBuilder.cc | 7 |
8 files changed, 48 insertions, 37 deletions
diff --git a/examples/example_02_libnebuild/libnebuild.cc b/examples/example_02_libnebuild/libnebuild.cc index c5f13fe..df5258b 100644 --- a/examples/example_02_libnebuild/libnebuild.cc +++ b/examples/example_02_libnebuild/libnebuild.cc @@ -2,14 +2,18 @@ #include <cstdlib> #ifndef _WIN32 -static auto kPath = "./posix.json"; +static constexpr auto kPath = "./posix.json"; #else -static auto kPath = ".\\win64.json"; +static constexpr 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); + NeBuild::BuildConfig config; + config.path_ = kPath; + config.dry_run_ = false; + + return builder->BuildTarget(config); } diff --git a/include/NeBuildKit/Config.h b/include/NeBuildKit/Config.h index 00be9de..915bde4 100644 --- a/include/NeBuildKit/Config.h +++ b/include/NeBuildKit/Config.h @@ -11,13 +11,7 @@ #include <rang/rang.h> #include <cassert> -#include <cstddef> -#include <cstdio> -#include <fstream> #include <iostream> -#include <sstream> -#include <string> -#include <thread> #define LIKELY(ARG) ((ARG) ? assert(false) : ((void) 0)) #define UNLIKELY(ARG) LIKELY(!(ARG)) @@ -34,7 +28,20 @@ #define LIBNEBUILD_UNUSED(X) ((void) X) -namespace NeBuild {} +namespace NeBuild { + struct BuildConfig final { + bool has_failed_{false}; + bool dry_run_{false}; + std::string path_{}; + + explicit operator bool() { + return has_failed_; + } + + BuildConfig() = default; + ~BuildConfig() {} + }; +} namespace NeBuild::Logger { /// @brief replacement for std::cout for NeBuild logging. diff --git a/include/NeBuildKit/IManifestBuilder.h b/include/NeBuildKit/IManifestBuilder.h index 7d3101c..c6a37c9 100644 --- a/include/NeBuildKit/IManifestBuilder.h +++ b/include/NeBuildKit/IManifestBuilder.h @@ -24,12 +24,11 @@ class IManifestBuilder { /// =========================================================== /// /// @brief Builds a TOML target from a file. - /// @param arg_sz filename size (must be 1 or greater). - /// @param arg_val filename path (must be a valid language file). + /// @param config configuration of build. /// @retval true building has succeeded. /// @retval false fail to build, see error message. /// =========================================================== /// - virtual bool BuildTarget(const std::string& arg, const bool dry_run = false) = 0; + virtual bool BuildTarget(BuildConfig& config) = 0; /// =========================================================== /// /// @brief Returns the build system name. diff --git a/include/NeBuildKit/JSONManifestBuilder.h b/include/NeBuildKit/JSONManifestBuilder.h index ccd5f6e..21f5f87 100644 --- a/include/NeBuildKit/JSONManifestBuilder.h +++ b/include/NeBuildKit/JSONManifestBuilder.h @@ -6,7 +6,6 @@ #pragma once #include <NeBuildKit/IManifestBuilder.h> -#include <json/json.h> /// @file JSONManifestBuilder.h /// @brief JSON manifest builder header file. @@ -24,12 +23,11 @@ class JSONManifestBuilder final NEBUILD_MANIFEST_BUILDER { public: /// =========================================================== /// /// @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). + /// @param config configuration of build. /// @retval true building has succeeded. /// @retval false fail to build, see error message. /// =========================================================== /// - bool BuildTarget(const std::string& arg_val, const bool dry_run = false) override; + bool BuildTarget(BuildConfig& config) override; /// =========================================================== /// /// @brief Returns the build system name. diff --git a/include/NeBuildKit/TOMLManifestBuilder.h b/include/NeBuildKit/TOMLManifestBuilder.h index c6a12bc..7caf9d6 100644 --- a/include/NeBuildKit/TOMLManifestBuilder.h +++ b/include/NeBuildKit/TOMLManifestBuilder.h @@ -6,7 +6,6 @@ #pragma once #include <NeBuildKit/IManifestBuilder.h> -#include <toml++/toml.hpp> /// @file TOMLManifestBuilder.h /// @brief TOML manifest builder header file. @@ -24,12 +23,11 @@ class TOMLManifestBuilder final NEBUILD_MANIFEST_BUILDER { public: /// =========================================================== /// /// @brief Builds a TOML target from a TOML file. - /// @param arg_sz filename size (must be 1 or greater). - /// @param arg_val filename path (must be a valid TOML file). + /// @param config configuration of build. /// @retval true building has succeeded. /// @retval false fail to build, see error message. /// =========================================================== /// - bool BuildTarget(const std::string& arg_val, const bool dry_run = false) override; + bool BuildTarget(BuildConfig& config) override; /// =========================================================== /// /// @brief Returns the build system name. diff --git a/src/cli/main.cc b/src/cli/main.cc index 02889ff..e3a17a0 100644 --- a/src/cli/main.cc +++ b/src/cli/main.cc @@ -6,9 +6,9 @@ #include <NeBuildKit/JSONManifestBuilder.h> #include <NeBuildKit/TOMLManifestBuilder.h> +#include <thread> -static bool kFailed = false; -static bool kDryRun = false; +static NeBuild::BuildConfig kConfig; int main(int argc, char** argv) { if (argc <= 1) return EXIT_FAILURE; @@ -23,7 +23,7 @@ int main(int argc, char** argv) { return EXIT_SUCCESS; } else if (index_path == "-dry-run" || index_path == "-n") { - kDryRun = true; + kConfig.dry_run_ = true; continue; } else if (index_path == "-h" || index_path == "-help") { NeBuild::Logger::info() << "usage: nebuild <options> <file>.\n"; @@ -43,7 +43,7 @@ int main(int argc, char** argv) { builder = new NeBuild::JSONManifestBuilder(); if (!builder) { - kFailed = true; + kConfig.has_failed_ = true; return; } } else { @@ -51,16 +51,16 @@ int main(int argc, char** argv) { builder = new NeBuild::TOMLManifestBuilder(); if (index_path.ends_with(kTomlExtension)) { - goto toml_build; + goto nebuild_build_target; } else { NeBuild::Logger::info() << "error: file '" << index_path << "' is not a manifest file!" << std::endl; - kFailed = true; + kConfig.has_failed_ = true; return; } } - toml_build: + nebuild_build_target: std::string next_path; if (argv[index_cpy + 1]) next_path = argv[index_cpy + 1]; @@ -72,8 +72,10 @@ int main(int argc, char** argv) { NeBuild::Logger::info() << "building manifest: " << index_path << std::endl; - if (builder && !builder->BuildTarget(index_path, kDryRun)) { - kFailed = true; + kConfig.path_ = index_path; + + if (builder && !builder->BuildTarget(kConfig)) { + kConfig.has_failed_ = true; } toml_build_done: @@ -84,5 +86,5 @@ int main(int argc, char** argv) { job_build_thread.join(); } - return kFailed ? EXIT_FAILURE : EXIT_SUCCESS; + return !kConfig ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/src/lib/JSONManifestBuilder.cc b/src/lib/JSONManifestBuilder.cc index 9de6608..c6ff4d8 100644 --- a/src/lib/JSONManifestBuilder.cc +++ b/src/lib/JSONManifestBuilder.cc @@ -4,6 +4,8 @@ // ============================================================= // #include <NeBuildKit/JSONManifestBuilder.h> +#include <json/json.h> +#include <fstream> using namespace NeBuild; using namespace nlohmann; @@ -18,14 +20,14 @@ namespace FS = std::filesystem; /// @retval true building has succeeded. /// @retval false fail to build, see error message. /// =========================================================== /// -bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dry_run) { +bool JSONManifestBuilder::BuildTarget(BuildConfig& config) { std::string path; - if (argv_val.empty()) { + if (config.path_.empty()) { NeBuild::Logger::info() << "nebuild: error: file path is empty" << std::endl; return false; } else { - path = argv_val; + path = config.path_; if (!FS::exists(path)) { NeBuild::Logger::info() << "nebuild: error: file '" << path << "' does not exist" diff --git a/src/lib/TOMLManifestBuilder.cc b/src/lib/TOMLManifestBuilder.cc index fc10c88..a58b280 100644 --- a/src/lib/TOMLManifestBuilder.cc +++ b/src/lib/TOMLManifestBuilder.cc @@ -4,6 +4,7 @@ // ============================================================= // #include <NeBuildKit/TOMLManifestBuilder.h> +#include <toml++/toml.hpp> #include <filesystem> using namespace NeBuild; @@ -17,14 +18,14 @@ namespace FS = std::filesystem; /// @retval true building has succeeded. /// @retval false fail to build, see error message. /// =========================================================== /// -bool TOMLManifestBuilder::BuildTarget(const std::string& argv_val, const bool dry_run) { +bool TOMLManifestBuilder::BuildTarget(BuildConfig& config) { std::string path; - if (argv_val.empty()) { + if (config.path_.empty()) { NeBuild::Logger::info() << "nebuild: error: file path is empty" << std::endl; return false; } else { - path = argv_val; + path = config.path_; if (!FS::exists(path)) { NeBuild::Logger::info() << "nebuild: error: file '" << path << "' does not exist" |
