Module: Tebako::Stripper

Defined in:
lib/tebako/stripper.rb

Overview

Tebako packaging support (stripper)

Constant Summary collapse

DELETE_EXTENSIONS =
%w[o lo obj a la lib].freeze
BIN_FILES =
%w[
  bundle bundler rbs erb gem irb racc racc2y
  rake rdoc ri y2racc rdbg syntax_suggest typeprof
].freeze
CMD_SUFFIX =
".cmd"
BAT_SUFFIX =
".bat"

Class Method Summary collapse

Class Method Details

.resign_macho(file) ⇒ Object

strip drops the Mach-O code signature. On macOS (notably >= 26) the dynamic loader SIGKILLs any dlopen of an unsigned / invalidly-signed .bundle/.dylib with "Code Signature Invalid" — and tebako dlopens native extensions extracted from the memfs at runtime. Re-apply an ad-hoc signature so the stripped extensions still load.



82
83
84
85
# File 'lib/tebako/stripper.rb', line 82

def resign_macho(file)
  _out, st = Open3.capture2e("codesign", "--force", "--sign", "-", file)
  puts "Warning: could not ad-hoc re-sign #{file}" unless st.exitstatus.zero?
end

.strip(scm, src_dir) ⇒ Object

Strip Removes build artefacts, strip shared objects



48
49
50
51
52
53
54
# File 'lib/tebako/stripper.rb', line 48

def strip(scm, src_dir)
  puts "   ... stripping the output"
  strip_bs(src_dir)
  strip_dsym(src_dir) if scm.macos?
  strip_fi(scm, src_dir)
  strip_li(scm, src_dir)
end

.strip_dsym(src_dir) ⇒ Object

Remove macOS .dSYM debug companions before stripping. They are external debug info (useless in the packaged memfs) and the DWARF Mach-O inside them is named ".bundle", so strip_li would try to strip -S it and fail with "string table not at the end of the file (can't be processed)".



60
61
62
# File 'lib/tebako/stripper.rb', line 60

def strip_dsym(src_dir)
  Dir.glob(File.join(src_dir, "**", "*.dSYM")).each { |d| FileUtils.rm_rf(d) }
end

.strip_file(file_in, file_out = nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/tebako/stripper.rb', line 64

def strip_file(file_in, file_out = nil)
  params = ["strip", "-S", file_in]
  params << "-o" << file_out unless file_out.nil?
  out, st = Open3.capture2e(*params)

  # Some gems (well, libmspack) has bundled extensions for several architectures)
  # Getting something like:
  # strip: Unable to recognise the format of the input file
  # `/tmp/cirrus-ci-build/o/s/lib/ruby/gems/3.1.0/gems/libmspack-0.11.0/ext/x86_64-linux/libmspack.so'
  # on aarch64

  puts "Warning: could not strip #{file_in}:\n #{out}" unless st.exitstatus.zero?
end