From e931297fe40f36f351a2befd0897ce46b8bf8cb7 Mon Sep 17 00:00:00 2001 From: "Maxim [maxirmx] Samsonov" Date: Fri, 17 Jan 2025 21:28:24 +0300 Subject: [PATCH] fix: squash Ruby build sequence --- CMakeLists.txt | 9 ++++----- exe/tebako-packager | 11 ++--------- lib/tebako/packager.rb | 19 ++++++------------- lib/tebako/ruby_builder.rb | 11 ++++++++++- lib/tebako/version.rb | 2 +- spec/packager_spec.rb | 14 +++++++++----- spec/ruby_builder_spec.rb | 38 +++++++++++++++++++++++++++++++++----- 7 files changed, 65 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd31e976..ea39b199 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -361,7 +361,8 @@ ExternalProject_Add(${RUBY_PRJ} DOWNLOAD_NO_PROGRESS true SOURCE_DIR ${RUBY_SOURCE_DIR} BUILD_IN_SOURCE true - CONFIGURE_COMMAND ruby ${EXE}/tebako-packager pass1 ${OSTYPE_TXT} ${RUBY_SOURCE_DIR} ${FS_MOUNT_POINT} ${DATA_SRC_DIR} ${RUBY_VER} + CONFIGURE_COMMAND "" + BUILD_COMMAND ruby ${EXE}/tebako-packager pass1 ${OSTYPE_TXT} ${RUBY_SOURCE_DIR} ${FS_MOUNT_POINT} ${DATA_SRC_DIR} ${RUBY_VER} # Make it for MacOS otherwise LDFLAGS are invalid COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_LIB_DIR} COMMAND ${GNU_BASH} -c "${RUBY_SOURCE_DIR}/configure ${OPENSSL_RUBY_OPTION} ${LIBYAML_RUBY_OPTION} \ @@ -375,10 +376,8 @@ ExternalProject_Add(${RUBY_PRJ} --prefix=${DATA_SRC_DIR} \ ${C_FLAGS_DEST}=\"${RUBY_C_FLAGS}\" \ LDFLAGS=\"${RUBY_L_FLAGS}\"" - COMMAND ruby ${EXE}/tebako-packager pass1a ${RUBY_SOURCE_DIR} - BUILD_COMMAND make -j${NCORES} - INSTALL_COMMAND make install -j${NCORES} - COMMAND ${GNU_BASH} -c "ruby ${EXE}/tebako-packager pass2 ${OSTYPE_TXT} ${RUBY_SOURCE_DIR} ${DEPS_LIB_DIR} ${DATA_SRC_DIR} ${RUBY_STASH_DIR} ${RUBY_VER}" + COMMAND ruby ${EXE}/tebako-packager pass2 ${OSTYPE_TXT} ${RUBY_SOURCE_DIR} ${DEPS_LIB_DIR} ${DATA_SRC_DIR} ${RUBY_STASH_DIR} ${RUBY_VER} + INSTALL_COMMAND "" ) # add_dependencies(${RUBY_PRJ} ${DWARFS_WR_PRJ}) diff --git a/exe/tebako-packager b/exe/tebako-packager index 90f14aa6..af0d228c 100755 --- a/exe/tebako-packager +++ b/exe/tebako-packager @@ -51,14 +51,6 @@ begin ruby_ver = Tebako::RubyVersion.new(ARGV[5]) Tebako::Packager.pass1(ARGV[1], ARGV[2], ARGV[3], ARGV[4], ruby_ver) - when "pass1a" - # ARGV[0] -- command - # ARGV[1] -- RUBY_SOURCE_DIR - unless ARGV.length == 2 - raise Tebako::Error, - "tebako-packager pass1a command expects 2 arguments, #{ARGV.length} has been provided." - end - Tebako::Packager.pass1a(ARGV[1]) when "pass2" # ARGV[0] -- command # ARGV[1] -- OSTYPE @@ -72,7 +64,8 @@ begin "tebako-packager pass2 command expects 7 arguments, #{ARGV.length} has been provided." end ruby_ver = Tebako::RubyVersion.new(ARGV[6]) - Tebako::Packager.stash(ARGV[4], ARGV[5]) + Tebako::Packager.pass1a(ARGV[2]) + Tebako::Packager.stash(ARGV[4], ARGV[5], ARGV[2], ruby_ver) Tebako::Packager.pass2(ARGV[1], ARGV[2], ARGV[3], ruby_ver) when "finalize" diff --git a/lib/tebako/packager.rb b/lib/tebako/packager.rb index 2a6b5cb0..249c18a4 100644 --- a/lib/tebako/packager.rb +++ b/lib/tebako/packager.rb @@ -92,7 +92,7 @@ def deploy(target_dir, pre_dir, ruby_ver, fs_root, fs_entrance, cwd) # rubocop:d def finalize(os_type, src_dir, app_name, ruby_ver, patchelf) puts "-- Running finalize script" - RubyBuilder.new(ruby_ver, src_dir).final_build + RubyBuilder.new(ruby_ver, src_dir).target_build exe_suffix = Packager::PatchHelpers.exe_suffix(os_type) src_name = File.join(src_dir, "ruby#{exe_suffix}") patchelf(src_name, patchelf) @@ -149,19 +149,12 @@ def pass2(ostype, ruby_source_dir, deps_lib_dir, ruby_ver) end # Stash - # Saves pristine Ruby environment that is used to deploy applications for packaging - def stash(src_dir, stash_dir) + # Created and saves pristine Ruby environment that is used to deploy applications for packaging + def stash(src_dir, stash_dir, ruby_source_dir, ruby_ver) puts "-- Running stash script" - # .... this code snippet is executed 'outside' of Ruby scripts - # shall be reconsidered - # FileUtils.cd ruby_source_dir do - # puts " ... creating pristine ruby environment at #{src_dir} [patience, it will take some time]" - # out, st = Open3.capture2e("cmake", "-E", "chdir", ruby_source_dir, "make", "install") - # print out if st.exitstatus != 0 || verbose - # raise Tebako::Error.new("stash [make install] failed with code #{st.exitstatus}") if st.exitstatus != 0 - # end - - puts " ... saving pristine ruby environment to #{stash_dir}" + RubyBuilder.new(ruby_ver, ruby_source_dir).toolchain_build + + puts " ... saving pristine Ruby environment to #{stash_dir}" PatchHelpers.recreate(stash_dir) FileUtils.cp_r "#{src_dir}/.", stash_dir end diff --git a/lib/tebako/ruby_builder.rb b/lib/tebako/ruby_builder.rb index 86d5870d..abc5b456 100644 --- a/lib/tebako/ruby_builder.rb +++ b/lib/tebako/ruby_builder.rb @@ -41,7 +41,16 @@ def initialize(ruby_ver, src_dir) end # Final build of tebako package - def final_build + def toolchain_build + puts " ... building toolchain Ruby" + Dir.chdir(@src_dir) do + BuildHelpers.run_with_capture(["make", "-j#{@ncores}"]) + BuildHelpers.run_with_capture(["make", "install", "-j#{@ncores}"]) + end + end + + # Final build of tebako package + def target_build puts " ... building tebako package" Dir.chdir(@src_dir) do BuildHelpers.run_with_capture(["make", "ruby", "-j#{@ncores}"]) if @ruby_ver.ruby3x? diff --git a/lib/tebako/version.rb b/lib/tebako/version.rb index af4cb8c1..f062a223 100644 --- a/lib/tebako/version.rb +++ b/lib/tebako/version.rb @@ -26,5 +26,5 @@ # POSSIBILITY OF SUCH DAMAGE. module Tebako - VERSION = "0.12.3" + VERSION = "0.12.4" end diff --git a/spec/packager_spec.rb b/spec/packager_spec.rb index 5a87a2fb..2205e3a1 100644 --- a/spec/packager_spec.rb +++ b/spec/packager_spec.rb @@ -105,7 +105,7 @@ before do allow(Tebako::RubyBuilder).to receive(:new).and_return(ruby_builder) - allow(ruby_builder).to receive(:final_build) + allow(ruby_builder).to receive(:target_build) allow(Tebako::Packager::PatchHelpers).to receive(:exe_suffix).and_return("") allow(Tebako::Packager).to receive(:patchelf) allow(Tebako::Packager).to receive(:strip_or_copy) @@ -116,8 +116,8 @@ Tebako::Packager.finalize(os_type, src_dir, app_name, ruby_ver, patchelf) end - it "calls final_build on the RubyBuilder" do - expect(ruby_builder).to receive(:final_build) + it "calls target_build on the RubyBuilder" do + expect(ruby_builder).to receive(:target_build) Tebako::Packager.finalize(os_type, src_dir, app_name, ruby_ver, patchelf) end @@ -257,6 +257,8 @@ describe "#stash" do let(:stash_dir) { "/path/to/stash" } let(:src_dir) { "/path/to/src" } + let(:ruby_source_dir) { "/path/to/ruby_source" } + let(:ruby_ver) { Tebako::RubyVersion.new("3.2.6") } before do allow(Tebako::Packager::PatchHelpers).to receive(:recreate) @@ -265,12 +267,14 @@ it "recreates the source directory" do expect(Tebako::Packager::PatchHelpers).to receive(:recreate).with(src_dir) - described_class.stash(stash_dir, src_dir) + expect_any_instance_of(Tebako::RubyBuilder).to receive(:toolchain_build) + described_class.stash(stash_dir, src_dir, ruby_source_dir, ruby_ver) end it "copies the stash directory to the source directory" do expect(FileUtils).to receive(:cp_r).with("#{stash_dir}/.", src_dir) - described_class.stash(stash_dir, src_dir) + expect_any_instance_of(Tebako::RubyBuilder).to receive(:toolchain_build) + described_class.stash(stash_dir, src_dir, ruby_source_dir, ruby_ver) end end diff --git a/spec/ruby_builder_spec.rb b/spec/ruby_builder_spec.rb index fcd08143..cc494c95 100644 --- a/spec/ruby_builder_spec.rb +++ b/spec/ruby_builder_spec.rb @@ -32,7 +32,7 @@ # rubocop:disable Metrics/BlockLength RSpec.describe Tebako::RubyBuilder do - describe "#final_build" do + describe "#target_build" do let(:ruby_ver) { "3.1.6" } let(:src_dir) { "/path/to/src" } let(:ncores) { 4 } @@ -45,24 +45,52 @@ end it "prints the building message" do - expect { builder.final_build }.to output(/building tebako package/).to_stdout + expect { builder.target_build }.to output(/building tebako package/).to_stdout end it "changes to the source directory" do expect(Dir).to receive(:chdir).with(src_dir).and_yield - builder.final_build + builder.target_build end context "when ruby version is 3.x" do it "runs make ruby with the correct number of cores" do expect(Tebako::BuildHelpers).to receive(:run_with_capture).with(["make", "ruby", "-j#{ncores}"]) - builder.final_build + builder.target_build end end it "runs make with the correct number of cores" do expect(Tebako::BuildHelpers).to receive(:run_with_capture).with(["make", "-j#{ncores}"]) - builder.final_build + builder.target_build + end + end + + describe "#toochain_build" do + let(:ruby_ver) { "3.1.6" } + let(:src_dir) { "/path/to/src" } + let(:ncores) { 4 } + let(:builder) { described_class.new(Tebako::RubyVersion.new(ruby_ver), src_dir) } + + before do + allow(Tebako::BuildHelpers).to receive(:ncores).and_return(ncores) + allow(Tebako::BuildHelpers).to receive(:run_with_capture) + allow(Dir).to receive(:chdir).with(src_dir).and_yield + end + + it "prints the building message" do + expect { builder.toolchain_build }.to output(/building toolchain Ruby/).to_stdout + end + + it "changes to the source directory" do + expect(Dir).to receive(:chdir).with(src_dir).and_yield + builder.toolchain_build + end + + it "runs make with the correct number of cores" do + expect(Tebako::BuildHelpers).to receive(:run_with_capture).with(["make", "-j#{ncores}"]) + expect(Tebako::BuildHelpers).to receive(:run_with_capture).with(["make", "install", "-j#{ncores}"]) + builder.toolchain_build end end end