Skip to content

Commit 4282e5c

Browse files
authored
Merge pull request #669 from larskanis/test-rpath
Add tests for rpath or other build related paths
2 parents 63fc155 + 19a3547 commit 4282e5c

File tree

8 files changed

+53
-8
lines changed

8 files changed

+53
-8
lines changed

.github/workflows/binary-gems.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
rcd_build:
2121
name: Build
2222
runs-on: ubuntu-latest
23+
env:
24+
RCD_IMAGE_VERSION: snapshot
2325
strategy:
2426
fail-fast: false
2527
matrix:
@@ -142,12 +144,12 @@ jobs:
142144
- run: echo $env:PATH
143145
- name: Run specs
144146
if: ${{ matrix.os != 'windows-latest' }}
145-
run: ruby -rpg -S rspec -fd spec/**/*_spec.rb
147+
run: ruby -rpg -S rspec -fd spec/*_spec.rb spec/**/*_spec.rb
146148
- name: Run specs
147149
if: ${{ matrix.os == 'windows-latest' }}
148150
run: |
149151
ridk enable
150-
ruby -rpg -S rspec -fd spec/**/*_spec.rb
152+
ruby -rpg -S rspec -fd spec/*_spec.rb spec/**/*_spec.rb
151153
152154
- name: Print logs if job failed
153155
if: ${{ failure() && matrix.os == 'windows-latest' }}

.github/workflows/source-gem.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ jobs:
147147
PG_DEBUG: 0
148148
# Temprary fix only for Truffleruby-24.0.0:
149149
TRUFFLERUBYOPT: --experimental-options --keep-handles-alive
150-
run: ruby -rpg -S rspec spec/**/*_spec.rb -cfdoc
150+
run: ruby -rpg -S rspec spec/*_spec.rb spec/**/*_spec.rb -cfdoc
151151

152152
- name: Print db logs if job failed
153153
if: ${{ failure() && matrix.os == 'windows' }}

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ end
1313
group :test do
1414
gem "bundler", ">= 1.16", "< 3.0"
1515
gem "rake-compiler", "~> 1.0"
16-
gem "rake-compiler-dock", "~> 1.9.1"
16+
gem "rake-compiler-dock", "~> 1.9.1", git: "https://github.com/rake-compiler/rake-compiler-dock"
1717
gem "rspec", "~> 3.5"
1818
# "bigdecimal" is a gem on ruby-3.4+ and it's optional for ruby-pg.
1919
# Specs should succeed without it, but 4 examples are then excluded.

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Rake::ExtensionTask.new do |ext|
7474
# Activate current cross compiled platform only.
7575
# This is to work around the issue that `linux` platform is selected in `linux-musl` image.
7676
ext.cross_platform = CrossLibraries.map(&:platform).select do |pl|
77-
m = ENV["RCD_IMAGE"]&.match(/:(?<ruby_ver>[\d\.]+)-mri-(?<platform>[-\w]+)$/)
77+
m = ENV["RCD_IMAGE"]&.match(/:(?<ruby_ver>[\w\.]+)-mri-(?<platform>[-\w]+)$/)
7878
m && m[:platform] == pl
7979
end
8080

@@ -106,7 +106,7 @@ task 'gem:native:prepare' do
106106
# Copy gem signing key and certs to be accessible from the docker container
107107
mkdir_p 'build/gem'
108108
sh "cp ~/.gem/gem-*.pem build/gem/ || true"
109-
sh "bundle package"
109+
sh "bundle package --all"
110110
begin
111111
OpenSSL::PKey.read(File.read(File.expand_path("~/.gem/gem-private_key.pem")), ENV["GEM_PRIVATE_KEY_PASSPHRASE"] || "")
112112
rescue OpenSSL::PKey::PKeyError

ext/extconf.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,20 @@ module PG
330330
create_header()
331331
create_makefile( "pg_ext" )
332332

333+
if gem_platform
334+
# exercise the strip command on native binary gems
335+
# This approach borrowed from
336+
# https://github.com/rake-compiler/rake-compiler-dock/blob/38066d479050f4fdb3956469255b35a05e5949ef/test/rcd_test/ext/mri/extconf.rb#L97C1-L110C42
337+
strip_tool = RbConfig::CONFIG['STRIP']
338+
strip_tool += ' -x' if RUBY_PLATFORM =~ /darwin/
339+
File.open('Makefile.new', 'w') do |o|
340+
o.puts 'hijack: all strip'
341+
o.puts
342+
o.write(File.read('Makefile'))
343+
o.puts
344+
o.puts 'strip: $(DLLIB)'
345+
o.puts "\t$(ECHO) Stripping $(DLLIB)"
346+
o.puts "\t$(Q) #{strip_tool} $(DLLIB)"
347+
end
348+
File.rename('Makefile.new', 'Makefile')
349+
end

spec/env/Dockerfile.alpine

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ CMD ruby -v && \
2525
bundle config set --local without 'development' && \
2626
bundle install && \
2727
sudo -u postgres ruby -rpg -e "p RUBY_DESCRIPTION, PG::VERSION, PG::POSTGRESQL_LIB_PATH, PG::IS_BINARY_GEM, PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET; puts PG.connect.exec('SELECT version()').values; p PG.connect.host" && \
28-
sudo -u postgres ruby -rpg -S rspec -fd spec/**/*_spec.rb
28+
sudo -u postgres ruby -rpg -S rspec -fd spec/*_spec.rb spec/**/*_spec.rb

spec/env/Dockerfile.centos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ CMD ruby -v && \
2424
bundle config set --local without 'development' && \
2525
bundle install && \
2626
sudo -u postgres ruby -rpg -e "p RUBY_DESCRIPTION, PG::VERSION, PG::POSTGRESQL_LIB_PATH, PG::IS_BINARY_GEM, PG::BUNDLED_LIBPQ_WITH_UNIXSOCKET; puts PG.connect.exec('SELECT version()').values; p PG.connect.host" && \
27-
sudo -u postgres ruby -rpg -S rspec -fd spec/**/*_spec.rb
27+
sudo -u postgres ruby -rpg -S rspec -fd spec/*_spec.rb spec/**/*_spec.rb

spec/pg_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,30 @@
6767
[PG.library_version, PG.version_string, PG.threadsafe?, PG::VERSION, PG::POSTGRESQL_LIB_PATH]
6868
)
6969
end
70+
71+
it "native gem's C-ext file shouldn't contain any rpath or other build-related paths" do
72+
skip "applies to native binary gems only" unless PG::IS_BINARY_GEM
73+
cext_fname = $LOADED_FEATURES.grep(/pg_ext/).first
74+
expect(cext_fname).not_to be_nil
75+
cext_text = File.binread(cext_fname)
76+
expect(cext_text).to match(/Init_pg_ext/) # C-ext shoud contain the init function
77+
expect(cext_text).not_to match(/usr\/local/) # there should be no rpath to /usr/local/rake-compiler/ruby/x86_64-unknown-linux-musl/ruby-3.4.5/lib or so
78+
expect(cext_text).not_to match(/home\//) # there should be no path to /home/ or so
79+
end
80+
81+
it "native gem's libpq file shouldn't contain any rpath or other build-related paths" do
82+
skip "applies to native binary gems only" unless PG::IS_BINARY_GEM
83+
84+
libpq_fname = case RUBY_PLATFORM
85+
when /mingw|mswin/ then "libpq.dll"
86+
when /linux/ then "libpq-ruby-pg.so.1"
87+
when /darwin/ then "libpq-ruby-pg.1.dylib"
88+
end
89+
90+
path = File.join(PG::POSTGRESQL_LIB_PATH, libpq_fname)
91+
text = File.binread(path)
92+
expect(text).to match(/PQconnectdb/) # libpq shoud contain the connect function
93+
expect(text).not_to match(/usr\/local/) # there should be no rpath to build dirs
94+
expect(text).not_to match(/home\//) # there should be no path to /home/.../ports/ or so
95+
end
7096
end

0 commit comments

Comments
 (0)