Skip to content

Commit

Permalink
fix: correctly name the artefact #274
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Mar 3, 2025
1 parent 9b0aaf6 commit a10f0e3
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 44 deletions.
5 changes: 3 additions & 2 deletions lib/tebako/cli_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2023-2024 [Ribose Inc](https://www.ribose.com).
# Copyright (c) 2023-2025 [Ribose Inc](https://www.ribose.com).
# All rights reserved.
# This file is a part of tebako
#
Expand Down Expand Up @@ -130,7 +130,8 @@ def generate_files(options_manager, scenario_manager)
def finalize(options_manager, scenario_manager)
use_patchelf = options_manager.patchelf? && scenario_manager.linux_gnu?
patchelf = use_patchelf ? "#{options_manager.deps_bin_dir}/patchelf" : nil
Tebako::Packager.finalize(options_manager.ruby_src_dir, options_manager.package, options_manager.rv, patchelf)
Tebako::Packager.finalize(options_manager.ruby_src_dir, options_manager.package,
options_manager.rv, patchelf, options_manager.output_type_first)
end

def options_from_tebafile(tebafile)
Expand Down
10 changes: 9 additions & 1 deletion lib/tebako/options_manager.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2023-2024 [Ribose Inc](https://www.ribose.com).
# Copyright (c) 2023-2025 [Ribose Inc](https://www.ribose.com).
# All rights reserved.
# This file is a part of tebako
#
Expand Down Expand Up @@ -163,6 +163,14 @@ def output_folder
@output_folder ||= File.join(prefix, "o")
end

def output_type_first
@output_type_first ||= %w[both runtime].include?(mode) ? "runtime package" : "package"
end

def output_type_second
"application package"
end

def package
package = if @options["output"].nil?
File.join(Dir.pwd, mode == "runtime" ? "tebako-runtime" : File.basename(fs_entrance, ".*"))
Expand Down
6 changes: 3 additions & 3 deletions lib/tebako/packager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ def do_patch(patch_map, root)
patch_map.each { |fname, mapping| PatchHelpers.patch_file("#{root}/#{fname}", mapping) }
end

def finalize(src_dir, app_name, ruby_ver, patchelf)
def finalize(src_dir, app_name, ruby_ver, patchelf, output_type)
puts "-- Running finalize script"

RubyBuilder.new(ruby_ver, src_dir).target_build
RubyBuilder.new(ruby_ver, src_dir).target_build(output_type)
exe_suffix = ScenarioManagerBase.new.exe_suffix
src_name = File.join(src_dir, "ruby#{exe_suffix}")
patchelf(src_name, patchelf)
package_name = "#{app_name}#{exe_suffix}"
# strip_or_copy(os_type, src_name, package_name)
Tebako::Stripper.strip_file(src_name, package_name)
puts "Created tebako package at \"#{package_name}\""
puts "Created tebako #{output_type} at \"#{package_name}\""
end

# Init
Expand Down
4 changes: 2 additions & 2 deletions lib/tebako/packager_lite.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2023-2024 [Ribose Inc](https://www.ribose.com).
# Copyright (c) 2023-2025 [Ribose Inc](https://www.ribose.com).
# All rights reserved.
# This file is a part of tebako
#
Expand Down Expand Up @@ -61,7 +61,7 @@ def create_package
deploy
FileUtils.rm_f(name)
Tebako::Packager.mkdwarfs(@opts.deps_bin_dir, name, @opts.data_src_dir, codegen)
puts "Created tebako package at \"#{name}\""
puts "Created tebako #{@opts.output_type_second} at \"#{name}\""
end

def deploy
Expand Down
6 changes: 3 additions & 3 deletions lib/tebako/ruby_builder.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2024 [Ribose Inc](https://www.ribose.com).
# Copyright (c) 2024-2025 [Ribose Inc](https://www.ribose.com).
# All rights reserved.
# This file is a part of tebako
#
Expand Down Expand Up @@ -50,8 +50,8 @@ def toolchain_build
end

# Final build of tebako package
def target_build
puts " ... building tebako package"
def target_build(output_type)
puts " ... building tebako #{output_type}"
Dir.chdir(@src_dir) do
BuildHelpers.run_with_capture(["make", "ruby", "-j#{@ncores}"]) if @ruby_ver.ruby3x?
BuildHelpers.run_with_capture(["make", "-j#{@ncores}"])
Expand Down
11 changes: 7 additions & 4 deletions spec/cli_helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2024 [Ribose Inc](https://www.ribose.com).
# Copyright (c) 2024-2025 [Ribose Inc](https://www.ribose.com).
# All rights reserved.
# This file is a part of tebako
#
Expand Down Expand Up @@ -234,7 +234,8 @@
options_manager.ruby_src_dir,
options_manager.package,
options_manager.rv,
patchelf_path
patchelf_path,
"package"
)
finalize(options_manager, scenario_manager)
end
Expand All @@ -251,7 +252,8 @@
options_manager.ruby_src_dir,
options_manager.package,
options_manager.rv,
nil
nil,
"package"
)
finalize(options_manager, scenario_manager)
end
Expand All @@ -268,7 +270,8 @@
options_manager.ruby_src_dir,
options_manager.package,
options_manager.rv,
nil
nil,
"package"
)
finalize(options_manager, scenario_manager)
end
Expand Down
37 changes: 37 additions & 0 deletions spec/options_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,43 @@
end
end
end

describe "#output_type_first" do
context "when mode is 'both'" do
let(:options) { { "mode" => "both" } }
let(:options_manager) { Tebako::OptionsManager.new(options) }

it "returns 'runtime package'" do
expect(options_manager.output_type_first).to eq("runtime package")
end
end

context "when mode is 'runtime'" do
let(:options) { { "mode" => "runtime" } }
let(:options_manager) { Tebako::OptionsManager.new(options) }

it "returns 'runtime package'" do
expect(options_manager.output_type_first).to eq("runtime package")
end
end

context "when mode is anything else" do
let(:options) { { "mode" => "bundle" } }
let(:options_manager) { Tebako::OptionsManager.new(options) }

it "returns 'package'" do
expect(options_manager.output_type_first).to eq("package")
end
end
end

describe "#output_type_second" do
let(:options_manager) { Tebako::OptionsManager.new({}) }

it "returns 'application package'" do
expect(options_manager.output_type_second).to eq("application package")
end
end
end

# rubocop:enable Metrics/BlockLength
18 changes: 14 additions & 4 deletions spec/packager_lite_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2024 [Ribose Inc](https://www.ribose.com).
# Copyright (c) 2024-2025 [Ribose Inc](https://www.ribose.com).
# All rights reserved.
# This file is a part of tebako
#
Expand Down Expand Up @@ -35,7 +35,7 @@
double("OptionsManager", stash_dir: "/tmp/stash", data_src_dir: "/tmp/src", data_pre_dir: "/tmp/pre",
data_bin_dir: "/tmp/bin", deps_bin_dir: "/tmp/deps_bin", mode: "both",
package: "test_package", rv: "3.2.5", ruby_ver: "3.2.5", root: "/", cwd: "/app",
ruby_src_dir: "/tmp/ruby_src")
ruby_src_dir: "/tmp/ruby_src", output_type_second: "application package")
end
let(:scenario_manager) { double("ScenarioManager", fs_entrance: "/entry") }

Expand Down Expand Up @@ -66,17 +66,27 @@
end

describe "#create_package" do
it "calls Packager methods to create the package" do
packager_lite = described_class.new(options_manager, scenario_manager)
let(:packager_lite) { described_class.new(options_manager, scenario_manager) }

before do
allow(packager_lite).to receive(:codegen).and_return("codegen_result")
allow(scenario_manager).to receive(:msys?).and_return(true)
allow(Tebako::Packager).to receive(:create_def)
allow(Tebako::Packager).to receive(:create_implib)
end

it "calls Packager methods to create the package" do
packager_lite.create_package
expect(FileUtils).to have_received(:rm_f).with("test_package.tebako")
expect(Tebako::Packager).to have_received(:mkdwarfs).with("/tmp/deps_bin", "test_package.tebako", "/tmp/src",
"codegen_result")
end

it "prints the correct completion message" do
expect { packager_lite.create_package }.to output(
/Created tebako application package at "test_package\.tebako"/
).to_stdout
end
end

describe "#deploy" do
Expand Down
26 changes: 18 additions & 8 deletions spec/packager_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2024 [Ribose Inc](https://www.ribose.com).
# Copyright (c) 2024-2025 [Ribose Inc](https://www.ribose.com).
# All rights reserved.
# This file is a part of tebako
#
Expand All @@ -27,6 +27,7 @@

require "fileutils"
require_relative "../lib/tebako/packager"
require_relative "../lib/tebako/ruby_version"

# rubocop:disable Metrics/BlockLength
RSpec.describe Tebako::Packager do
Expand Down Expand Up @@ -102,35 +103,43 @@
let(:patchelf) { "/usr/bin/patchelf" }
let(:ruby_builder) { instance_double(Tebako::RubyBuilder) }

let(:output_type) { "runtime package" }

before do
allow(Tebako::RubyBuilder).to receive(:new).and_return(ruby_builder)
allow(ruby_builder).to receive(:target_build)
allow_any_instance_of(Tebako::ScenarioManagerBase).to receive(:exe_suffix).and_return("")
allow(Tebako::Packager).to receive(:patchelf)
allow(Tebako::Stripper).to receive(:strip)
allow(Tebako::Stripper).to receive(:strip_file)
end

it "creates a new RubyBuilder with the correct parameters" do
expect(Tebako::RubyBuilder).to receive(:new).with(ruby_ver, src_dir).and_return(ruby_builder)
Tebako::Packager.finalize(src_dir, app_name, ruby_ver, patchelf)
Tebako::Packager.finalize(src_dir, app_name, ruby_ver, patchelf, output_type)
end

it "calls target_build on the RubyBuilder" do
expect(ruby_builder).to receive(:target_build)
Tebako::Packager.finalize(src_dir, app_name, ruby_ver, patchelf)
it "calls target_build on the RubyBuilder with correct output_type" do
expect(ruby_builder).to receive(:target_build).with(output_type)
Tebako::Packager.finalize(src_dir, app_name, ruby_ver, patchelf, output_type)
end

it "calls patchelf with the correct parameters" do
src_name = File.join(src_dir, "ruby")
expect(Tebako::Packager).to receive(:patchelf).with(src_name, patchelf)
Tebako::Packager.finalize(src_dir, app_name, ruby_ver, patchelf)
Tebako::Packager.finalize(src_dir, app_name, ruby_ver, patchelf, output_type)
end

it "calls strip_file with the correct parameters" do
src_name = File.join(src_dir, "ruby")
package_name = app_name.to_s
expect(Tebako::Stripper).to receive(:strip_file).with(src_name, package_name)
Tebako::Packager.finalize(src_dir, app_name, ruby_ver, patchelf)
Tebako::Packager.finalize(src_dir, app_name, ruby_ver, patchelf, output_type)
end

it "prints the correct completion message" do
expect { Tebako::Packager.finalize(src_dir, app_name, ruby_ver, patchelf, output_type) }.to output(
/Created tebako #{output_type} at "#{app_name}"/
).to_stdout
end
end

Expand Down Expand Up @@ -262,6 +271,7 @@
before do
allow(Tebako::Packager::PatchHelpers).to receive(:recreate)
allow(FileUtils).to receive(:cp_r)
allow_any_instance_of(Tebako::ScenarioManagerBase).to receive(:ncores).and_return(4)
end

it "recreates the source directory" do
Expand Down
41 changes: 26 additions & 15 deletions spec/ruby_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2024 [Ribose Inc](https://www.ribose.com).
# Copyright (c) 2024-2025 [Ribose Inc](https://www.ribose.com).
# All rights reserved.
# This file is a part of tebako
#
Expand Down Expand Up @@ -37,32 +37,43 @@
let(:src_dir) { "/path/to/src" }
let(:ncores) { 4 }
let(:builder) { described_class.new(Tebako::RubyVersion.new(ruby_ver), src_dir) }
let(:output_type) { "package" }

before do
allow_any_instance_of(Tebako::ScenarioManagerBase).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.target_build }.to output(/building tebako package/).to_stdout
end
shared_examples "build behavior" do |type|
it "prints the correct building message" do
expect { builder.target_build(type) }.to output(/building tebako #{type}/).to_stdout
end

it "changes to the source directory" do
expect(Dir).to receive(:chdir).with(src_dir).and_yield
builder.target_build
end
it "changes to the source directory" do
expect(Dir).to receive(:chdir).with(src_dir).and_yield
builder.target_build(type)
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.target_build
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.target_build(type)
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.target_build(type)
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.target_build
context "with 'package' output type" do
include_examples "build behavior", "package"
end

context "with 'runtime package' output type" do
include_examples "build behavior", "runtime package"
end
end

Expand Down
4 changes: 2 additions & 2 deletions tests/scripts/functional-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ press_runner_app() {
fi

# Check the first and the last messages expected from CMake script
assertContains "$result" "Created tebako package at"
assertContains "$result" "Created tebako application package at"
}


Expand Down Expand Up @@ -217,7 +217,7 @@ test_AU_runtime() {

assertEquals 0 "${PIPESTATUS[0]}"
assertContains "$result" "Running tebako press script"
assertContains "$result" "Created tebako package at"
assertContains "$result" "Created tebako runtime package at"
fi
}

Expand Down

0 comments on commit a10f0e3

Please sign in to comment.