Last active
September 20, 2019 12:17
-
-
Save dynamicdispatch/42d03fffbc64cfea75ed2e42b3adf519 to your computer and use it in GitHub Desktop.
Simple ruby script to check that Objective-C static libraries are built with the latest ObjC ABI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'optparse' | |
require 'pathname' | |
require 'open3' | |
# This tool checks an input path for all static libraries *.a files | |
# and makes sure they were built with the most modern ObjC ABI version. | |
# Parse command line options. | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = 'Usage: staticlibchecker.rb [options]' | |
opts.on('-i', '--input-path FOLDER', 'Input path') { |v| options[:input_path] = v } | |
end.parse! | |
input_path = "" | |
if options[:input_path].nil? | |
raise "No input path specified" | |
else | |
input_path = options[:input_path] | |
end | |
all_static_libs = Dir["#{input_path}/**/*.a"] | |
puts all_static_libs | |
category_class_var_flag = 1<<6 | |
all_static_libs.each { |path| | |
# Run otool against the static lib | |
command = "otool -o #{path}" | |
stdout, stderr, status = Open3.capture3(command) | |
if !status.success? | |
puts "Failed with output: #{stderr}" | |
exit status.exitstatus | |
end | |
# extract 'flags' value | |
match = stdout.match /^\s+flags\s+(0x[\d]+)$/ | |
if match | |
flags = Integer(match[1]) | |
if (flags & category_class_var_flag) == category_class_var_flag | |
puts "File: #{File.basename(path)} is ok" | |
else | |
puts "File: #{File.basename(path)} was built with an old ABI version! #{flags} #{category_class_var_flag}" | |
end | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment