diff --git a/CMakeLists.txt b/CMakeLists.txt index f3c05980..c670f970 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -462,7 +462,6 @@ else (${SETUP_MODE}) ) add_custom_target(packaged_filesystem - COMMAND ruby ${EXE}/tebako-packager strip ${OSTYPE_TXT} ${DATA_SRC_DIR} COMMAND ${GNU_BASH} -c "chmod +x ${DEPS_BIN_DIR}/mkdwarfs${EXE_SUFFIX}" # No progress below is critical since in reporting mode mkdwarfs tries to work directly with terminal # and it creates issues for stderr redirects (&2 > 1) used by Ninja and our test srcipts @@ -487,22 +486,18 @@ else (${SETUP_MODE}) add_dependencies(tebako-fs packaged_filesystem) if (${RUBY_VER} VERSION_LESS "3.0.0") - add_custom_target(patched_ruby + add_custom_target(tebako COMMAND ${CMAKE_COMMAND} -E chdir ${RUBY_SOURCE_DIR} make ${RUBY_MAKEFILE} -j${NCORES} - ) + COMMAND ruby ${EXE}/tebako-packager finalize ${OSTYPE_TXT} ${RUBY_SOURCE_DIR} ${APP_NAME} + ) else() - add_custom_target(patched_ruby + add_custom_target(tebako COMMAND ${CMAKE_COMMAND} -E chdir ${RUBY_SOURCE_DIR} make ruby ${RUBY_MAKEFILE} -j${NCORES} COMMAND ${CMAKE_COMMAND} -E chdir ${RUBY_SOURCE_DIR} make ${RUBY_MAKEFILE} -j${NCORES} - ) + COMMAND ruby ${EXE}/tebako-packager finalize ${OSTYPE_TXT} ${RUBY_SOURCE_DIR} ${APP_NAME} + ) endif() - add_dependencies(patched_ruby setup tebako-fs) - - add_custom_target(tebako ALL - COMMAND ${CMAKE_COMMAND} -E copy ${RUBY_SOURCE_DIR}/ruby${RUBY_SUFFIX}${EXE_SUFFIX} ${APP_NAME}${EXE_SUFFIX} - COMMAND ${CMAKE_COMMAND} -E echo "Tebako packaging has completed" - DEPENDS patched_ruby - ) + add_dependencies(tebako setup tebako-fs) endif(${SETUP_MODE}) diff --git a/exe/tebako-packager b/exe/tebako-packager index 20844ddf..1be0723a 100755 --- a/exe/tebako-packager +++ b/exe/tebako-packager @@ -48,26 +48,7 @@ begin end Tebako::Packager.pass1(ARGV[1], ARGV[2], ARGV[3], ARGV[4], ARGV[5]) - when "stash" - # ARGV[0] -- command - # ARGV[1] -- DATA_SRC_DIR - # ARGV[2] -- RUBY_STASH_DIR - unless ARGV.length == 3 - raise Tebako::Error, - "tebako-packager stash command expects 3 arguments, #{ARGV.length} has been provided." - end - - Tebako::Packager.stash(ARGV[1], ARGV[2]) - when "strip" - # ARGV[0] -- command - # ARGV[1] -- OSTYPE - # ARGV[2] -- DATA_SRC_DIR - unless ARGV.length == 3 - raise Tebako::Error, - "tebako-packager strip command expects 3 arguments, #{ARGV.length} has been provided." - end - Tebako::Stripper.strip(ARGV[1], ARGV[2]) when "pass1a" # ARGV[0] -- command # ARGV[1] -- RUBY_SOURCE_DIR @@ -114,6 +95,16 @@ begin # That shall match CMakeLists.txt settings Tebako::Packager.deploy(ARGV[1], ARGV[4], ARGV[5], ARGV[11], ARGV[7], ARGV[8], ARGV[9]) + when "finalize" + # ARGV[0] -- command + # ARGV[1] -- OSTYPE + # ARGV[2] -- RUBY_SOURCE_DIR + # ARGV[3] -- APP_NAME + unless ARGV.length == 4 + raise Tebako::Error, + "tebako-packager finalize command expects 4 arguments, #{ARGV.length} has been provided." + end + Tebako::Packager.finalize(ARGV[1], ARGV[2], ARGV[3]) else raise Tebako::Error, "tebako-packager cannot process #{ARGV[0]} command" end @@ -121,5 +112,4 @@ rescue Tebako::Error => e puts "tebako-packager failed: #{e.message} [#{e.error_code}]" exit(e.error_code) end - exit(0) diff --git a/lib/tebako/deploy_helper.rb b/lib/tebako/deploy_helper.rb index ad17e0ba..dbe4d18c 100644 --- a/lib/tebako/deploy_helper.rb +++ b/lib/tebako/deploy_helper.rb @@ -29,6 +29,7 @@ require "find" require_relative "error" +require_relative "packager/patch_helpers" # Tebako - an executable packager module Tebako @@ -65,11 +66,16 @@ def config(os_type, ruby_ver) end def deploy - system("#{gem_command} env") - install_gem("tebako-runtime") - install_gem("bundler", Tebako::BUNDLER_VERSION) if needs_bundler? - - deploy_solution + Packager::PatchHelpers.with_env(deploy_env) do + unless Packager::PatchHelpers.ruby31?(@ruby_ver) + update_rubygems + patch_after_rubygems_update(@target_dir, @ruby_api_version) + end + system("#{gem_command} env") + install_gem("tebako-runtime") + install_gem("bundler", BUNDLER_VERSION) if needs_bundler? + deploy_solution + end end def deploy_env @@ -264,6 +270,13 @@ def ncores end end + def patch_after_rubygems_update(target_dir, ruby_api_ver) + # Autoload cannot handle statically linked openssl extension + # Changing it to require seems to be the simplest solution + Packager::PatchHelpers.patch_file("#{target_dir}/lib/ruby/site_ruby/#{ruby_api_ver}/rubygems/openssl.rb", + { "autoload :OpenSSL, \"openssl\"" => "require \"openssl\"" }) + end + def run_with_capture(args) puts " ... @ #{args.join(" ")}" out, st = Open3.capture2e(*args) diff --git a/lib/tebako/packager.rb b/lib/tebako/packager.rb index dbbc5052..f47d25c9 100644 --- a/lib/tebako/packager.rb +++ b/lib/tebako/packager.rb @@ -31,6 +31,7 @@ require_relative "error" require_relative "deploy_helper" +require_relative "stripper" require_relative "packager/pass1" require_relative "packager/pass1a" require_relative "packager/pass2" @@ -79,14 +80,17 @@ def deploy(os_type, target_dir, pre_dir, ruby_ver, fs_root, fs_entrance, fs_moun deploy_helper = Tebako::DeployHelper.new(fs_root, fs_entrance, fs_mount_point, target_dir, pre_dir) deploy_helper.config(os_type, ruby_ver) + deploy_helper.deploy + Tebako::Stripper.strip(os_type, target_dir) + end - PatchHelpers.with_env(deploy_helper.deploy_env) do - unless PatchHelpers.ruby31?(ruby_ver) - deploy_helper.update_rubygems - patch_after_rubygems_update(target_dir, deploy_helper.ruby_api_version) - end - deploy_helper.deploy - end + def finalize(os_type, src_dir, app_name) + puts "-- Finalizing packaging" + exe_suffix = Packager::PatchHelpers.exe_suffix(os_type) + package_name = "#{app_name}#{exe_suffix}" + Tebako::Stripper.strip_file(File.join(src_dir, "ruby#{exe_suffix}"), package_name) + + puts "Created tebako package at \"#{package_name}\"" end # Init @@ -188,13 +192,6 @@ def ruby_version(tbd) end ruby_version end - - def patch_after_rubygems_update(target_dir, ruby_api_ver) - # Autoload cannot handle statically linked openssl extension - # Changing it to require seems to be the simplest solution - PatchHelpers.patch_file("#{target_dir}/lib/ruby/site_ruby/#{ruby_api_ver}/rubygems/openssl.rb", - { "autoload :OpenSSL, \"openssl\"" => "require \"openssl\"" }) - end end end end diff --git a/lib/tebako/packager/patch_helpers.rb b/lib/tebako/packager/patch_helpers.rb index d05ac164..13413690 100755 --- a/lib/tebako/packager/patch_helpers.rb +++ b/lib/tebako/packager/patch_helpers.rb @@ -62,6 +62,10 @@ def get_prefix_linux(package) out end + def exe_suffix(ostype) + msys?(ostype) ? ".exe" : "" + end + def msys?(ostype) ostype =~ /msys|cygwin|mingw/ end diff --git a/lib/tebako/packager/patch_libraries.rb b/lib/tebako/packager/patch_libraries.rb index 6110bba3..c948203a 100644 --- a/lib/tebako/packager/patch_libraries.rb +++ b/lib/tebako/packager/patch_libraries.rb @@ -40,13 +40,12 @@ class << self DARWIN_BREW_LIBS = [ ["zlib", "z"], ["gdbm", "gdbm"], ["readline", "readline"], ["libffi", "ffi"], ["ncurses", "ncurses"], ["fmt", "fmt"], ["lz4", "lz4"], ["xz", "lzma"], - ["libyaml", "yaml"], ["boost", "boost_chrono"], - ["double-conversion", "double-conversion"] + ["libyaml", "yaml"], ["boost", "boost_chrono"], ["double-conversion", "double-conversion"] ].freeze DARWIN_BREW_LIBS_PRE_31 = [["openssl@1.1", "ssl"], ["openssl@1.1", "crypto"]].freeze - DARWIN_BREW_LIBS_31 = [["libyaml", "yaml"], ["openssl@3", "ssl"], ["openssl@3", "crypto"]].freeze + DARWIN_BREW_LIBS_31 = [["openssl@3", "ssl"], ["openssl@3", "crypto"]].freeze DARWIN_DEP_LIBS = ["glog", "gflags", "brotlienc", "brotlidec", "brotlicommon"].freeze # rubocop:enable Style/WordArray diff --git a/lib/tebako/stripper.rb b/lib/tebako/stripper.rb index 5b1bc723..a6949570 100644 --- a/lib/tebako/stripper.rb +++ b/lib/tebako/stripper.rb @@ -28,12 +28,14 @@ require "fileutils" require "find" +require_relative "packager/patch_helpers" + # Tebako - an executable packager module Tebako # Tebako packaging support (stripper) module Stripper DELETE_EXTENSIONS = %w[o lo obj a lib].freeze - STRIP_EXTENSIONS = %w[dll so].freeze + STRIP_EXTENSIONS = %w[dll so bundle dylib].freeze BIN_FILES = %w[ bundle bundler rbs erb gem irb racc racc2y rake rdoc ri y2racc rdbg typeprof ].freeze @@ -47,15 +49,22 @@ class << self # from memfs or not. For debugging purposes it is very handy to have it here def strip(ostype, src_dir) puts " ... stripping the output" - strip_bs(ostype, src_dir) + strip_bs(src_dir) strip_fi(ostype, src_dir) - strip_li(ostype, src_dir) + strip_li(src_dir) + end + + def strip_file(file_in, file_out = nil) + params = ["strip", "-S", file_in] + params << "-o" << file_out unless file_out.nil? + out, st = Open3.capture2e(*params) + raise Tebako::Error, "Failed to strip #{file_in}:\n #{out}" unless st.exitstatus.zero? end private def get_files(ostype) - exe_suffix = ostype =~ /msys/ ? ".exe" : "" + exe_suffix = Packager::PatchHelpers.exe_suffix(ostype) files = BIN_FILES.flat_map do |f| [f, "#{f}#{CMD_SUFFIX}", "#{f}#{BAT_SUFFIX}"] end @@ -64,7 +73,7 @@ def get_files(ostype) files end - def strip_bs(_ostype, src_dir) + def strip_bs(src_dir) FileUtils.rm_rf([ File.join(src_dir, "share"), File.join(src_dir, "include"), @@ -77,7 +86,7 @@ def strip_fi(ostype, src_dir) FileUtils.rm(files, force: true) end - def strip_li(ostype, src_dir) + def strip_li(src_dir) Find.find(src_dir) do |file| next if File.directory?(file) @@ -85,7 +94,7 @@ def strip_li(ostype, src_dir) if DELETE_EXTENSIONS.include?(extension) FileUtils.rm(file) elsif STRIP_EXTENSIONS.include?(extension) - system("strip \"#{file}\"") unless ostype =~ /darwin/ + strip_file(file) end end end diff --git a/lib/tebako/version.rb b/lib/tebako/version.rb index b3fc9f16..91aec1e9 100644 --- a/lib/tebako/version.rb +++ b/lib/tebako/version.rb @@ -26,5 +26,5 @@ # POSSIBILITY OF SUCH DAMAGE. module Tebako - VERSION = "0.7.3" + VERSION = "0.7.4" end diff --git a/tests/scripts/functional-tests.sh b/tests/scripts/functional-tests.sh index c4d1a83e..4e647ce1 100755 --- a/tests/scripts/functional-tests.sh +++ b/tests/scripts/functional-tests.sh @@ -44,7 +44,7 @@ press_runner() { # Check the first and the last messages expected from CMake script assertContains "$result" "Running tebako press script" - assertContains "$result" "packaging has completed" + assertContains "$result" "Created tebako package at" } package_runner() { @@ -178,7 +178,7 @@ test_AUC_extract() { assertEquals 0 "${PIPESTATUS[0]}" assertContains "$result" "Running tebako press script" - assertContains "$result" "packaging has completed" + assertContains "$result" "Created tebako package at" ./test-AUC-package --tebako-extract assertEquals 0 "${PIPESTATUS[0]}"