diff --git a/.tebako.yml b/.tebako.yml index 00b19dff..3f75d567 100644 --- a/.tebako.yml +++ b/.tebako.yml @@ -1 +1,3 @@ -prefix: PWD +options: + prefix: PWD + Ruby: 3.2.4 diff --git a/README.adoc b/README.adoc index 34740db1..ce2d8434 100644 --- a/README.adoc +++ b/README.adoc @@ -86,8 +86,8 @@ with debug information unstripped. You can opt to run 'strip -S' manually, it mo | 2.7.8 | Linux, macOS | 3.0.7 | Linux, macOS -| 3.1.{4,5,6} | Linux, macOS, Windows -| 3.2.{3,4} | Linux, macOS, Windows +| 3.1.6 | Linux, macOS, Windows +| 3.2.4 | Linux, macOS, Windows | 3.3.{3,4} | Linux, macOS, Windows |=== @@ -232,8 +232,6 @@ Displays the Tebako version. Displays the help message. - - == Usage === General @@ -291,9 +289,6 @@ docker run -v :/mnt/w \ tebako {command} {parameters} ---- - - - ==== Packaging from outside the container To package your application from outside the container, just run a single Docker @@ -625,7 +620,8 @@ tebako press \ [-R|--Ruby=] \ [-o|--output=] \ [-l|--log-level=] \ - [-D|--devmode] + [-D|--devmode] \ + [-t|--tebafile=] ---- Where: @@ -634,7 +630,7 @@ Where: the Tebako root folder (see details in the Tebako Root Folder Selection section) `Ruby`:: -This parameter defines Ruby version that will be packaged (optional, defaults to +this parameter defines Ruby version that will be packaged (optional, defaults to `3.1.6`) ``:: @@ -651,11 +647,16 @@ the output file name (optional, defaults to `/] \ [-R|--Ruby=] \ - [-D|--devmode] + [-D|--devmode] \ + [-t|--tebafile=] ---- Where: ``:: the Tebako root folder (see details in the Tebako Root Folder Selection section) -`Ruby` parameter defines Ruby version that will be packaged (optional, defaults to 3.1.6) +`Ruby`:: parameter defines Ruby version that will be packaged (optional, defaults to 3.1.6) + +`tebafile`:: +the tebako configuration file (optional, defaults to `$PWD/.tebako.yml`). +Please refer to the separate section below for tebafile description. -`devmode` flag activates development mode, in which Tebako's cache and packaging consistency checks are relaxed. +`devmode`:: flag activates development mode, in which Tebako's cache and packaging consistency checks are relaxed. Please note that this mode is not intended for production use and should only be used during development. ==== Clean @@ -712,13 +718,18 @@ Normally you do not need to do it since tebako packager optimizes artifacts life [source,sh] ---- $ tebako clean \ - [-p|--prefix=] + [-p|--prefix=] \ + [-t|--tebafile=] ---- Where: ``:: the Tebako root folder (see details in the Tebako Root Folder Selection section) +`tebafile`:: +the tebako configuration file (optional, defaults to `$PWD/.tebako.yml`). +Please refer to the separate section below for tebafile description. + [example] ==== [source,sh] @@ -743,7 +754,9 @@ NOTE: Compiled DwarFS libraries are not cleaned. ---- $ tebako clean_ruby [-p|--prefix=] \ - [-R|--Ruby=] + [-R|--Ruby=] \ + [-t|--tebafile=] + ---- Where: @@ -754,6 +767,10 @@ the Tebako setup folder (optional, defaults to current folder) `Ruby`:: defines Ruby version that will cleaned (optional, cleans all versions by default) +`tebafile`:: +the tebako configuration file (optional, defaults to `$PWD/.tebako.yml`). +Please refer to the separate section below for tebafile description. + [example] ==== [source,sh] @@ -772,6 +789,26 @@ as a cache key in CI/CD pipelines. $ tebako hash ---- +=== Tebako configuration file + +It is possible to provide all or some options for the `tebako setup/press/clean/clean_ruby` commands via Tebako configuration file ('tebafile'). +Tebafile is a YAML file with a single section 'options'. The options are the same as long names for the command line. For, example for the prefix option + +[source] +---- +-p|--prefix= +---- +the key in the YAML file would be 'prefix'. + +Below is an example tebafile that sets values for prefix and Ruby options +[source,yaml] +---- +options: + prefix: /tmp/tebako + Ruby: 3.2.4 +---- + +Please note that the options provided on the command line have preference over tebafile settings. === Image extraction diff --git a/lib/tebako/cli.rb b/lib/tebako/cli.rb index 47db2323..0bb87270 100755 --- a/lib/tebako/cli.rb +++ b/lib/tebako/cli.rb @@ -40,7 +40,7 @@ # Tebako - an executable packager # Implementation of tebako command-line interface module Tebako - OPTIONS_FILE = ".tebako.yml" + DEFAULT_TEBAFILE = ".tebako.yml" # Tebako packager front-end class Cli < Thor package_name "Tebako" @@ -48,7 +48,8 @@ class Cli < Thor desc: "A path to tebako packaging environment, '~/.tebako' ('$HOME/.tebako') by default" class_option :devmode, type: :boolean, aliases: "-D", required: false, desc: "Developer mode, please do not use if unsure" - + class_option :tebafile, type: :string, aliases: "-t", required: false, + desc: "tebako configuration file 'tebafile', '$PWD/.tebako.yml' by default" desc "clean", "Clean tebako packaging environment" def clean clean_cache @@ -123,35 +124,19 @@ def initialize(*args) def options original_options = super - - return original_options unless File.exist?(OPTIONS_FILE) - - defaults = ::YAML.load_file(OPTIONS_FILE) || {} - Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options)) + tebafile = original_options["tebafile"].nil? ? DEFAULT_TEBAFILE : original_options["tebafile"] + if File.exist?(tebafile) + Thor::CoreExt::HashWithIndifferentAccess.new(options_from_tebafile(tebafile).merge(original_options)) + else + puts "Warning: Tebako configuration file '#{tebafile}' not found." unless original_options["tebafile"].nil? + original_options + end end end - private - no_commands do - def do_press - cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=OFF #{cfg_options} #{press_options}" - build_cmd = "cmake --build #{output} --target tebako --parallel #{Etc.nprocessors}" - merged_env = ENV.to_h.merge(b_env) - Tebako.packaging_error(103) unless system(merged_env, cfg_cmd) - Tebako.packaging_error(104) unless system(merged_env, build_cmd) - end - - def do_setup - cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=ON #{cfg_options}" - build_cmd = "cmake --build \"#{output}\" --target setup --parallel #{Etc.nprocessors}" - merged_env = ENV.to_h.merge(b_env) - Tebako.packaging_error(101) unless system(merged_env, cfg_cmd) - Tebako.packaging_error(102) unless system(merged_env, build_cmd) - end + include Tebako::CliHelpers + include Tebako::CliRubies end - - include Tebako::CliHelpers - include Tebako::CliRubies end end diff --git a/lib/tebako/cli_helpers.rb b/lib/tebako/cli_helpers.rb index 16f6f2cc..77e36a3f 100644 --- a/lib/tebako/cli_helpers.rb +++ b/lib/tebako/cli_helpers.rb @@ -80,6 +80,22 @@ def deps @deps ||= File.join(prefix, "deps") end + def do_press + cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=OFF #{cfg_options} #{press_options}" + build_cmd = "cmake --build #{output} --target tebako --parallel #{Etc.nprocessors}" + merged_env = ENV.to_h.merge(b_env) + Tebako.packaging_error(103) unless system(merged_env, cfg_cmd) + Tebako.packaging_error(104) unless system(merged_env, build_cmd) + end + + def do_setup + cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=ON #{cfg_options}" + build_cmd = "cmake --build \"#{output}\" --target setup --parallel #{Etc.nprocessors}" + merged_env = ENV.to_h.merge(b_env) + Tebako.packaging_error(101) unless system(merged_env, cfg_cmd) + Tebako.packaging_error(102) unless system(merged_env, build_cmd) + end + def ensure_version_file version_file_path = File.join(deps, E_VERSION_FILE) @@ -128,6 +144,18 @@ def m_files end # rubocop:enable Metrics/MethodLength + def options_from_tebafile(tebafile) + ::YAML.load_file(tebafile)["options"] || {} + rescue Psych::SyntaxError => e + puts "Warning: The tebafile '#{tebafile}' contains invalid YAML syntax." + puts e.message + {} + rescue StandardError => e + puts "An unexpected error occurred while loading the tebafile '#{tebafile}'." + puts e.message + {} + end + def output @output ||= File.join(prefix, "o") end diff --git a/src/tebako-main.cpp b/src/tebako-main.cpp index 985577a4..293f7693 100644 --- a/src/tebako-main.cpp +++ b/src/tebako-main.cpp @@ -145,6 +145,8 @@ extern "C" int tebako_main(int* argc, char*** argv) { // Nested error, no recovery :( } } + + // tebako_chdir("/__tebako_memfs__/local"); } return ret; }