diff --git a/.github/actions/easy_compile/dist/index.js b/.github/actions/easy_compile/dist/index.js index 6d95741..0e41c36 100644 --- a/.github/actions/easy_compile/dist/index.js +++ b/.github/actions/easy_compile/dist/index.js @@ -28211,7 +28211,7 @@ async function run(workingDirectory) { let ccRubies = cp.execSync('easy_compile print_ruby_cc_version', { cwd: workingDirectory, encoding: 'utf-8' }) await downloadRubies(ccRubies.split(':')) - setupRakeCompilerConfig() + setupRakeCompilerConfig(workingDirectory) } async function downloadRubies(rubies) { @@ -28227,11 +28227,11 @@ async function downloadRubies(rubies) { } } -function setupRakeCompilerConfig() { +function setupRakeCompilerConfig(workingDirectory) { let rubiesRbConfig = fs.globSync(`${rubiesPath()}/*/*/lib/ruby/*/*/rbconfig.rb`) let currentRubyVersion = cp.execSync('ruby -v', { encoding: 'utf-8' }).match(/^ruby (\d\.\d\.\d)/)[1] let rbConfigPath = path.join(os.homedir(), ".rake-compiler", "config.yml") - let rubyPlatform = cp.execSync('easy_compile print_normalized_platform', { encoding: 'utf-8' }) + let rubyPlatform = cp.execSync('easy_compile print_normalized_platform', { cwd: workingDirectory, encoding: 'utf-8' }) fs.mkdirSync(`${os.homedir()}/.rake-compiler`) diff --git a/.github/actions/easy_compile/src/index.js b/.github/actions/easy_compile/src/index.js index 60e8533..7c9b265 100644 --- a/.github/actions/easy_compile/src/index.js +++ b/.github/actions/easy_compile/src/index.js @@ -10,7 +10,7 @@ async function run(workingDirectory) { let ccRubies = cp.execSync('easy_compile print_ruby_cc_version', { cwd: workingDirectory, encoding: 'utf-8' }) await downloadRubies(ccRubies.split(':')) - setupRakeCompilerConfig() + setupRakeCompilerConfig(workingDirectory) } async function downloadRubies(rubies) { @@ -26,11 +26,11 @@ async function downloadRubies(rubies) { } } -function setupRakeCompilerConfig() { +function setupRakeCompilerConfig(workingDirectory) { let rubiesRbConfig = fs.globSync(`${rubiesPath()}/*/*/lib/ruby/*/*/rbconfig.rb`) let currentRubyVersion = cp.execSync('ruby -v', { encoding: 'utf-8' }).match(/^ruby (\d\.\d\.\d)/)[1] let rbConfigPath = path.join(os.homedir(), ".rake-compiler", "config.yml") - let rubyPlatform = cp.execSync('easy_compile print_normalized_platform', { encoding: 'utf-8' }) + let rubyPlatform = cp.execSync('easy_compile print_normalized_platform', { cwd: workingDirectory, encoding: 'utf-8' }) fs.mkdirSync(`${os.homedir()}/.rake-compiler`) diff --git a/lib/easy_compile/compilation_tasks.rb b/lib/easy_compile/compilation_tasks.rb index d3642d5..8ff8127 100644 --- a/lib/easy_compile/compilation_tasks.rb +++ b/lib/easy_compile/compilation_tasks.rb @@ -11,6 +11,7 @@ class CompilationTasks def initialize(create_packaging_task = false, gemspec = nil) @gemspec = Bundler.load_gemspec(gemspec || find_gemspec) + verify_gemspec! @create_packaging_task = create_packaging_task end @@ -126,5 +127,14 @@ def find_gemspec(glob = "*.gemspec") Make sure to run any easy_compile commands in the root of your gem folder. EOM end + + def verify_gemspec! + return if gemspec.extensions.any? + + raise GemspecError, <<~EOM + Your gem has no native extention defined in its gemspec. + This tool can't be used on pure Ruby gems. + EOM + end end end diff --git a/test/cli_test.rb b/test/cli_test.rb index 8f36831..74d79e6 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -122,11 +122,9 @@ def test_when_cli_runs_in_project_with_no_gemspec out = nil Dir.chdir("lib") do - Kernel.stub(:exit, ->(_) { raise }) do - out, _ = capture_subprocess_io do - assert_raises(StandardError) do - CLI.start(["print_ruby_cc_version"]) - end + out, _ = capture_subprocess_io do + raise_instead_of_exit do + CLI.start(["print_ruby_cc_version"]) end end end @@ -136,5 +134,30 @@ def test_when_cli_runs_in_project_with_no_gemspec Make sure to run any easy_compile commands in the root of your gem folder. MSG end + + def test_when_cli_runs_in_project_with_no_native_extension + out = nil + + out, _ = capture_subprocess_io do + raise_instead_of_exit do + CLI.start(["print_ruby_cc_version"]) + end + end + + assert_equal(<<~MSG, out) + Your gem has no native extention defined in its gemspec. + This tool can't be used on pure Ruby gems. + MSG + end + + private + + def raise_instead_of_exit(&block) + Kernel.stub(:exit, ->(_) { raise }) do + assert_raises(StandardError) do + block.call + end + end + end end end