From 558d9d273844a88b105d444983c7e624be5fac82 Mon Sep 17 00:00:00 2001 From: Chris Punches Date: Fri, 14 Mar 2025 02:50:24 -0400 Subject: [PATCH] implemented better options availability for build stage --- modules/build/include/cli_parsers.hpp | 6 ++++- modules/build/src/cli_parsers.cpp | 36 ++++++++++++++++++++++++++- modules/build/src/commands.cpp | 34 ++++++++++++++++++------- 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/modules/build/include/cli_parsers.hpp b/modules/build/include/cli_parsers.hpp index 479d97a..3b5c37b 100644 --- a/modules/build/include/cli_parsers.hpp +++ b/modules/build/include/cli_parsers.hpp @@ -27,17 +27,21 @@ struct BuildOptions { std::string hooks_dir; /**< Directory with package hooks */ std::string package_name; /**< Name of the package to build */ std::string package_version; /**< Version of the package to build */ + std::string architecture; /**< Architecture of the package (e.g., x86_64, aarch64) */ + std::string os; /**< Optional OS of the package (e.g., dhl2) */ bool force; /**< Flag to force package creation even if warnings occur */ bool verbose; /**< Flag for verbose output */ bool show_help; /**< Flag to show help information */ - // Constructor with only force and verbose defaulted + // Constructor with defaults BuildOptions() : output_dir(""), contents_dir(""), hooks_dir(""), package_name(""), package_version(""), + architecture(""), + os(""), force(false), verbose(false), show_help(false) {} diff --git a/modules/build/src/cli_parsers.cpp b/modules/build/src/cli_parsers.cpp index 4e9c1be..ea30314 100644 --- a/modules/build/src/cli_parsers.cpp +++ b/modules/build/src/cli_parsers.cpp @@ -16,6 +16,8 @@ int parse_create_options(int argc, char** argv, BuildOptions& options) { bool hooks_dir_provided = false; bool package_name_provided = false; bool package_version_provided = false; + bool architecture_provided = false; + bool os_provided = false; bool force_provided = false; bool verbose_provided = false; bool help_provided = false; @@ -54,6 +56,12 @@ int parse_create_options(int argc, char** argv, BuildOptions& options) { } else if (option == "--version") { options.package_version = value; package_version_provided = true; + } else if (option == "--architecture") { + options.architecture = value; + architecture_provided = true; + } else if (option == "--os") { + options.os = value; + os_provided = true; } else if (option == "--force") { // Parse the boolean value options.force = (value == "true" || value == "1" || value == "yes"); @@ -79,6 +87,8 @@ int parse_create_options(int argc, char** argv, BuildOptions& options) { {"hooks", required_argument, 0, 'H'}, {"name", required_argument, 0, 'n'}, {"version", required_argument, 0, 'V'}, + {"architecture", required_argument, 0, 'a'}, + {"os", required_argument, 0, 'O'}, {"force", no_argument, 0, 'f'}, {"verbose", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, @@ -93,7 +103,7 @@ int parse_create_options(int argc, char** argv, BuildOptions& options) { int opt; int option_index = 0; - while ((opt = getopt_long(argc, argv, "o:c:H:n:V:fvh", long_options, &option_index)) != -1) { + while ((opt = getopt_long(argc, argv, "o:c:H:n:V:a:O:fvh", long_options, &option_index)) != -1) { switch (opt) { case 'o': options.output_dir = optarg; @@ -115,6 +125,14 @@ int parse_create_options(int argc, char** argv, BuildOptions& options) { options.package_version = optarg; package_version_provided = true; break; + case 'a': + options.architecture = optarg; + architecture_provided = true; + break; + case 'O': + options.os = optarg; + os_provided = true; + break; case 'f': options.force = true; force_provided = true; @@ -177,6 +195,16 @@ int parse_create_options(int argc, char** argv, BuildOptions& options) { any_options_provided = true; } + if (architecture_provided) { + dpm_log(LOG_DEBUG, (" architecture=" + options.architecture).c_str()); + any_options_provided = true; + } + + if (os_provided) { + dpm_log(LOG_DEBUG, (" os=" + options.os).c_str()); + any_options_provided = true; + } + if (force_provided) { dpm_log(LOG_DEBUG, (" force=" + std::string(options.force ? "true" : "false")).c_str()); any_options_provided = true; @@ -249,6 +277,12 @@ int validate_build_options(const BuildOptions& options) { return 1; } + // Check if architecture is provided + if (options.architecture.empty()) { + dpm_log(LOG_ERROR, "Architecture is required (--architecture)"); + return 1; + } + // Check if hooks directory exists if provided if (!options.hooks_dir.empty() && !std::filesystem::exists(options.hooks_dir)) { dpm_log(LOG_ERROR, ("Hooks directory does not exist: " + options.hooks_dir).c_str()); diff --git a/modules/build/src/commands.cpp b/modules/build/src/commands.cpp index abe7618..eb81b86 100644 --- a/modules/build/src/commands.cpp +++ b/modules/build/src/commands.cpp @@ -1,6 +1,5 @@ #include "commands.hpp" - int cmd_stage(int argc, char** argv) { // Announce that the stage step is being executed (debug level) dpm_log(LOG_DEBUG, "Executing stage command"); @@ -24,6 +23,19 @@ int cmd_stage(int argc, char** argv) { dpm_set_logging_level(LOG_DEBUG); } + // If OS is not supplied, try to get it from config + if (options.os.empty()) { + const char* config_os = dpm_get_config("build", "os"); + if (config_os != nullptr) { + options.os = config_os; + dpm_log(LOG_DEBUG, ("Using OS from config: " + options.os).c_str()); + } else { + dpm_log(LOG_ERROR, "OS not specified and not found in configuration"); + dpm_log(LOG_ERROR, "Please specify OS with --os or set a default in /etc/dpm/conf.d/build.conf"); + return 1; + } + } + // Validate options int validate_result = validate_build_options(options); if (validate_result != 0) { @@ -36,6 +48,8 @@ int cmd_stage(int argc, char** argv) { dpm_log(LOG_DEBUG, (" Contents directory: " + options.contents_dir).c_str()); dpm_log(LOG_DEBUG, (" Package name: " + options.package_name).c_str()); dpm_log(LOG_DEBUG, (" Package version: " + options.package_version).c_str()); + dpm_log(LOG_DEBUG, (" Architecture: " + options.architecture).c_str()); + dpm_log(LOG_DEBUG, (" OS: " + options.os).c_str()); if (!options.hooks_dir.empty()) { dpm_log(LOG_DEBUG, (" Hooks directory: " + options.hooks_dir).c_str()); @@ -80,13 +94,15 @@ int cmd_stage_help(int argc, char** argv) { dpm_log(LOG_INFO, "Usage: dpm build stage [options]"); dpm_log(LOG_INFO, ""); dpm_log(LOG_INFO, "Options:"); - dpm_log(LOG_INFO, " -o, --output-dir DIR Directory to save the staged package (required)"); - dpm_log(LOG_INFO, " -c, --contents DIR Directory with package contents (required)"); - dpm_log(LOG_INFO, " -H, --hooks DIR Directory with package hooks (optional)"); - dpm_log(LOG_INFO, " -n, --name NAME Package name (required)"); - dpm_log(LOG_INFO, " -V, --version VERSION Package version (required)"); - dpm_log(LOG_INFO, " -f, --force Force package staging even if warnings occur"); - dpm_log(LOG_INFO, " -v, --verbose Enable verbose output"); - dpm_log(LOG_INFO, " -h, --help Display this help message"); + dpm_log(LOG_INFO, " -o, --output-dir DIR Directory to save the staged package (required)"); + dpm_log(LOG_INFO, " -c, --contents DIR Directory with package contents (required)"); + dpm_log(LOG_INFO, " -H, --hooks DIR Directory with package hooks (optional)"); + dpm_log(LOG_INFO, " -n, --name NAME Package name (required)"); + dpm_log(LOG_INFO, " -V, --version VERSION Package version (required)"); + dpm_log(LOG_INFO, " -a, --architecture ARCH Package architecture (required, e.g., x86_64)"); + dpm_log(LOG_INFO, " -O, --os OS Package OS (optional, e.g., dhl2)"); + dpm_log(LOG_INFO, " -f, --force Force package staging even if warnings occur"); + dpm_log(LOG_INFO, " -v, --verbose Enable verbose output"); + dpm_log(LOG_INFO, " -h, --help Display this help message"); return 0; } \ No newline at end of file