From c79d7f5f8e9323a9ffbf7d939d6b235075b6991b Mon Sep 17 00:00:00 2001 From: Andy Pfister Date: Tue, 7 Jan 2025 22:31:19 +0100 Subject: [PATCH] Fix execution of `bin` stuff --- .github/workflows/ci.yml | 4 +- CHANGELOG.md | 1 + ext/tiny_tds/extconf.rb | 5 ++ lib/tiny_tds/bin.rb | 17 ++--- lib/tiny_tds/gem.rb | 16 +--- test/gem_test.rb | 153 --------------------------------------- 6 files changed, 19 insertions(+), 177 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3798885..540ba1e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -371,7 +371,9 @@ jobs: gem update --system 3.3.22 && ${{ matrix.bootstrap }} gem install --no-document ./gems/tiny_tds-$(cat VERSION)-${{ matrix.platform }}.gem && - ruby -e \"require 'tiny_tds'; puts TinyTds::Gem.root_path\" + ruby -e \"require 'tiny_tds'; puts TinyTds::Gem.root_path\" && + tsql-ttds -C && \ + defncopy-ttds" " test-linux: diff --git a/CHANGELOG.md b/CHANGELOG.md index 58b0a33b..afbfd432 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 3.2.0 * Add precompiled gem for Linux (for GLIBC / MUSL, 64-bit x86 and ARM). +* Fix wrappers for `tsql` and `defncopy` utility. ## 3.1.0 diff --git a/ext/tiny_tds/extconf.rb b/ext/tiny_tds/extconf.rb index 08e236c5..01b2d136 100644 --- a/ext/tiny_tds/extconf.rb +++ b/ext/tiny_tds/extconf.rb @@ -98,6 +98,11 @@ def install recipe.cook_and_activate end + ["defncopy", "tsql"].each do |binary_name| + full_binary_name = RUBY_PLATFORM =~ /mingw|mswin/ ? "#{binary_name}.exe" : binary_name + FileUtils.cp("#{freetds_recipe.path}/bin/#{full_binary_name}", "../../../../exe") + end + ENV["LDFLAGS"] = "-Wl,-rpath -Wl,#{openssl_recipe.path}/lib" dir_config('freetds', "#{freetds_recipe.path}/include", "#{freetds_recipe.path}/lib") diff --git a/lib/tiny_tds/bin.rb b/lib/tiny_tds/bin.rb index 832692a3..02dae48d 100644 --- a/lib/tiny_tds/bin.rb +++ b/lib/tiny_tds/bin.rb @@ -25,7 +25,7 @@ def initialize(name) end def run(*args) - with_ports_paths do + with_exe_path do return nil unless path Kernel.system Shellwords.join(args.unshift(path)) $CHILD_STATUS.to_i @@ -43,15 +43,15 @@ def info private def search_paths - ENV['PATH'].split File::PATH_SEPARATOR + ENV['PATH'].split(File::PATH_SEPARATOR) + [Gem.exe_path] end - def with_ports_paths + def with_exe_path old_path = ENV['PATH'] begin ENV['PATH'] = [ - Gem.ports_bin_paths, + Gem.exe_path, old_path ].flatten.join File::PATH_SEPARATOR @@ -66,12 +66,11 @@ def find_bin end def find_exe - Gem.ports_bin_paths.each do |bin| - @exts.each do |ext| - f = File.join bin, "#{name}#{ext}" - return f if File.exist?(f) - end + @exts.each do |ext| + f = File.join Gem.exe_path, "#{name}#{ext}" + return f if File.exist?(f) end + nil end diff --git a/lib/tiny_tds/gem.rb b/lib/tiny_tds/gem.rb index a52f047d..dcfa7b23 100644 --- a/lib/tiny_tds/gem.rb +++ b/lib/tiny_tds/gem.rb @@ -7,20 +7,8 @@ def root_path File.expand_path '../../..', __FILE__ end - def ports_root_path - File.join(root_path,'ports') - end - - def ports_bin_paths - Dir.glob(File.join(ports_root_path,ports_host,'**','bin')) - end - - def ports_lib_paths - Dir.glob(File.join(ports_root_path,ports_host,'**','lib')) - end - - def ports_host - RbConfig::CONFIG["arch"] + def exe_path + File.join(root_path, "exe") end end end diff --git a/test/gem_test.rb b/test/gem_test.rb index 0412a88a..13cab042 100644 --- a/test/gem_test.rb +++ b/test/gem_test.rb @@ -6,17 +6,6 @@ class GemTest < Minitest::Spec gem_root ||= File.expand_path '../..', __FILE__ describe TinyTds::Gem do - - # We're going to muck with some system globals so lets make sure - # they get set back later - original_platform = RbConfig::CONFIG['arch'] - original_pwd = Dir.pwd - - after do - RbConfig::CONFIG['arch'] = original_platform - Dir.chdir original_pwd - end - describe '#root_path' do let(:root_path) { TinyTds::Gem.root_path } @@ -30,147 +19,5 @@ class GemTest < Minitest::Spec _(root_path).must_equal gem_root end end - - describe '#ports_root_path' do - let(:ports_root_path) { TinyTds::Gem.ports_root_path } - - it 'should be the ports path' do - _(ports_root_path).must_equal File.join(gem_root,'ports') - end - - it 'should be the ports path no matter the cwd' do - Dir.chdir '/' - - _(ports_root_path).must_equal File.join(gem_root,'ports') - end - end - - describe '#ports_bin_paths' do - let(:ports_bin_paths) { TinyTds::Gem.ports_bin_paths } - - describe 'when the ports directories exist' do - let(:fake_bin_paths) do - ports_host_root = File.join(gem_root, 'ports', 'fake-host-with-dirs') - [ - File.join('a','bin'), - File.join('a','inner','bin'), - File.join('b','bin') - ].map do |p| - File.join(ports_host_root, p) - end - end - - before do - RbConfig::CONFIG['arch'] = 'fake-host-with-dirs' - fake_bin_paths.each do |path| - FileUtils.mkdir_p(path) - end - end - - after do - FileUtils.remove_entry_secure( - File.join(gem_root, 'ports', 'fake-host-with-dirs'), true - ) - end - - it 'should return all the bin directories' do - _(ports_bin_paths.sort).must_equal fake_bin_paths.sort - end - - it 'should return all the bin directories regardless of cwd' do - Dir.chdir '/' - _(ports_bin_paths.sort).must_equal fake_bin_paths.sort - end - end - - describe 'when the ports directories are missing' do - before do - RbConfig::CONFIG['arch'] = 'fake-host-without-dirs' - end - - it 'should return no directories' do - _(ports_bin_paths).must_be_empty - end - - it 'should return no directories regardless of cwd' do - Dir.chdir '/' - _(ports_bin_paths).must_be_empty - end - end - end - - describe '#ports_lib_paths' do - let(:ports_lib_paths) { TinyTds::Gem.ports_lib_paths } - - describe 'when the ports directories exist' do - let(:fake_lib_paths) do - ports_host_root = File.join(gem_root, 'ports', 'fake-host-with-dirs') - [ - File.join('a','lib'), - File.join('a','inner','lib'), - File.join('b','lib') - ].map do |p| - File.join(ports_host_root, p) - end - end - - before do - RbConfig::CONFIG['arch'] = 'fake-host-with-dirs' - fake_lib_paths.each do |path| - FileUtils.mkdir_p(path) - end - end - - after do - FileUtils.remove_entry_secure( - File.join(gem_root, 'ports', 'fake-host-with-dirs'), true - ) - end - - it 'should return all the lib directories' do - _(ports_lib_paths.sort).must_equal fake_lib_paths.sort - end - - it 'should return all the lib directories regardless of cwd' do - Dir.chdir '/' - _(ports_lib_paths.sort).must_equal fake_lib_paths.sort - end - end - - describe 'when the ports directories are missing' do - before do - RbConfig::CONFIG['arch'] = 'fake-host-without-dirs' - end - - - it 'should return no directories' do - _(ports_lib_paths).must_be_empty - end - - it 'should return no directories regardless of cwd' do - Dir.chdir '/' - _(ports_lib_paths).must_be_empty - end - end - end - - describe '#ports_host' do - { - 'x64-mingw-ucrt' => 'x64-mingw-ucrt', - 'x64-mingw32' => 'x64-mingw32', - 'x86_64-linux' => 'x86_64-linux', - }.each do |host,expected| - describe "on a #{host} architecture" do - before do - RbConfig::CONFIG['arch'] = host - end - - it "should return a #{expected} ports host" do - _(TinyTds::Gem.ports_host).must_equal expected - end - end - end - end end end -