Skip to content

Commit

Permalink
fix: propagate Ruby gem version to CMake via command line parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx authored and ronaldtse committed Aug 15, 2024
1 parent adfd845 commit 16f5ed6
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ task:
- echo $CC
- cat common.env
- cat .cirrus.yml
- cat lib/tebako/version.rb

# cirrus-ci hash does not work for optimized Ruby patching/build
# most likely it changes file times that causes make do a kind of
# 'random' rebuild
setup_script: |
bundle install
bundle exec rake generate_version_txt
exe/tebako clean_ruby
exe/tebako setup -D -R 3.2.5
Expand Down
3 changes: 1 addition & 2 deletions .github/actions/setup-tebako-development-msys/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ runs:
shell: msys2 {0}
run: |
bundle install
bundle exec rake generate_version_txt
- name: Process cache
uses: actions/cache@v4
with:
path: ${{ inputs.path }}
key: msys-${{ inputs.cc }}-${{ hashFiles('**/common.env', 'CMakeLists.txt', 'version.txt') }}-v${{ inputs.version }}
key: msys-${{ inputs.cc }}-${{ hashFiles('**/common.env', 'CMakeLists.txt', 'lib/tebako/version.rb') }}-v${{ inputs.version }}
3 changes: 1 addition & 2 deletions .github/actions/setup-tebako-development/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ runs:
shell: bash
run: |
bundle install
bundle exec rake generate_version_txt
- name: Process cache
uses: actions/cache@v4
with:
path: ${{ inputs.path }}
key: ${{ inputs.os }}-${{ inputs.cc }}-${{ hashFiles('**/common.env', 'CMakeLists.txt', 'version.txt') }}-v${{ inputs.version }}
key: ${{ inputs.os }}-${{ inputs.cc }}-${{ hashFiles('**/common.env', 'CMakeLists.txt', 'lib/tebako/version.rb') }}-v${{ inputs.version }}
2 changes: 1 addition & 1 deletion .tebako.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
options:
prefix: PWD
Ruby: 3.2.5
# Ruby: 3.2.5
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ if(${CMAKE_VERSION} VERSION_GREATER "3.23.10")
cmake_policy(SET CMP0135 NEW)
endif()

include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake-scripts/version.cmake)
determine_version("${CMAKE_CURRENT_SOURCE_DIR}" TEBAKO)
if ("-${TEBAKO_VERSION}" STREQUAL "-")
message(FATAL_ERROR "Tebako version is not specified.")
endif()

project(tebako_packager VERSION ${TEBAKO_VERSION})

Expand Down
11 changes: 0 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,3 @@ RuboCop::RakeTask.new
RSpec::Core::RakeTask.new(:spec)

task default: %i[rubocop spec]

desc "Generate version.txt"
task "generate_version_txt" do
require_relative "lib/tebako/version"
version_without_rc = Tebako::VERSION.gsub(/\.rc\d+/, "")
File.write(File.join(__dir__, "version.txt"), "#{version_without_rc}\n")
puts "Generating #{File.join(__dir__, "version.txt")}; version = #{version_without_rc}"
end

task build: :generate_version_txt
task release: :generate_version_txt
3 changes: 2 additions & 1 deletion lib/tebako/cli_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def cfg_options
# So we have to use \"xxx\"
@cfg_options ||=
"-DCMAKE_BUILD_TYPE=Release -DRUBY_VER:STRING=\"#{ruby_ver}\" -DRUBY_HASH:STRING=\"#{ruby_hash}\" " \
"-DDEPS:STRING=\"#{deps}\" -G \"#{m_files}\" -B \"#{output_folder}\" -S \"#{source}\""
"-DDEPS:STRING=\"#{deps}\" -G \"#{m_files}\" -B \"#{output_folder}\" -S \"#{source}\" " \
"-DTEBAKO_VERSION:STRING=\"#{Tebako::VERSION}\""
end

def clean_cache
Expand Down
56 changes: 56 additions & 0 deletions spec/cli_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,62 @@
end
end

describe "#cfg_options" do
let(:dummy_class) { Class.new { include Tebako::CliHelpers } }
let(:cli_helpers) { dummy_class.new }
let(:deps) { "/path/to/deps" }
let(:output_folder) { "/path/to/output" }
let(:source) { "/path/to/source" }
let(:m_files) { "Unix Makefiles" }
let(:ruby_ver) { "3.2.5" }
let(:ruby_hash) { "abcdef" }

before do
allow(self).to receive(:deps).and_return(deps)
allow(self).to receive(:output_folder).and_return(output_folder)
allow(self).to receive(:source).and_return(source)
allow(self).to receive(:m_files).and_return(m_files)
allow(self).to receive(:extend_ruby_version).and_return([ruby_ver, ruby_hash])
end

it "returns the correct configuration options string" do
exp_opt = "-DCMAKE_BUILD_TYPE=Release -DRUBY_VER:STRING=\"#{ruby_ver}\" -DRUBY_HASH:STRING=\"#{ruby_hash}\" " \
"-DDEPS:STRING=\"#{deps}\" -G \"#{m_files}\" -B \"#{output_folder}\" -S \"#{source}\" " \
"-DTEBAKO_VERSION:STRING=\"#{Tebako::VERSION}\""
expect(cfg_options).to eq(exp_opt)
end
end

describe "#clean_cache" do
let(:deps) { "/path/to/deps" }
let(:output_folder) { "/path/to/output" }
before do
allow(self).to receive(:deps).and_return(deps)
allow(self).to receive(:output_folder).and_return(output_folder)
end
it "cleans the cache by removing the appropriate directories" do
expect(FileUtils).to receive(:rm_rf).with([File.join(deps, ""), File.join(output_folder, "")], secure: true)
clean_cache
end
end

describe "#clean_output" do
let(:deps) { "/path/to/deps" }
let(:output_folder) { "/path/to/output" }
before do
allow(self).to receive(:deps).and_return(deps)
allow(self).to receive(:output_folder).and_return(output_folder)
end
it "cleans the output by removing the appropriate files and directories" do
nmr = "src/_ruby_*"
nms = "stash_*"
expect(FileUtils).to receive(:rm_rf).with(Dir.glob(File.join(deps, nmr)), secure: true)
expect(FileUtils).to receive(:rm_rf).with(Dir.glob(File.join(deps, nms)), secure: true)
expect(FileUtils).to receive(:rm_rf).with(File.join(output_folder, ""), secure: true)
clean_output
end
end

describe "#l_level" do
context "when log-level option is not set" do
it 'returns "error"' do
Expand Down
2 changes: 0 additions & 2 deletions tebako.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ Gem::Specification.new do |spec|
end
end

spec.files << "version.txt"

spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = %w[cmake exe ext include lib resources src tools/ci-scripts tools/cmake-scripts tools/includes]
Expand Down

0 comments on commit 16f5ed6

Please sign in to comment.