Skip to content

Commit

Permalink
fix: squash Ruby build sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Jan 17, 2025
1 parent ac2aed9 commit e931297
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 39 deletions.
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand All @@ -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})
Expand Down
11 changes: 2 additions & 9 deletions exe/tebako-packager
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
19 changes: 6 additions & 13 deletions lib/tebako/packager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion lib/tebako/ruby_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/tebako/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
# POSSIBILITY OF SUCH DAMAGE.

module Tebako
VERSION = "0.12.3"
VERSION = "0.12.4"
end
14 changes: 9 additions & 5 deletions spec/packager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
38 changes: 33 additions & 5 deletions spec/ruby_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand Down

0 comments on commit e931297

Please sign in to comment.