Last active
October 9, 2015 16:45
-
-
Save pikajude/dd63b50d8f28212b0a69 to your computer and use it in GitHub Desktop.
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/ruby | |
| require 'open3' | |
| require 'set' | |
| require 'fileutils' | |
| require 'pathname' | |
| $system_version = %x{/usr/bin/sw_vers -productVersion}.strip | |
| FileUtils.mkdir_p("/nix/var/frameworks/#$system_version") | |
| def deps_filepath(lib) | |
| out_dir = "/nix/var/frameworks/#$system_version/#{normalize(lib)}" | |
| end | |
| def normalize(filepath) | |
| filepath.gsub("-", "--").gsub("/", "-").sub(/^-/, "") | |
| end | |
| def find_impures(derivation) | |
| open(derivation).read.scan(%r{\("__impureHostDeps","([^"]*)"\)}).flatten.map(&:split).flatten | |
| end | |
| fws = find_impures(ARGV[0]) | |
| exit if fws.empty? | |
| def get_all_dependencies(lib, deps = {}, generate = true) | |
| return if deps.key?(lib) | |
| return if lib =~ %r{^/dev} or lib =~ %r{^/bin} | |
| Open3.popen3("otool -L -arch x86_64 #{lib}") do |input,output,error,thread| | |
| if thread.value.success? && output.readline !~ /is not an object file/ | |
| libnames = output.read.split("\n").map{|x|x.split()[0]} | |
| deps[lib] = libnames | |
| libnames.each do |l| | |
| get_all_dependencies(l, deps, false) | |
| end | |
| else | |
| if File.symlink?(lib) | |
| deps[lib] = [Pathname.new(lib).realpath] | |
| end | |
| end | |
| end | |
| Set.new(deps.values.flatten) if generate | |
| end | |
| deps = fws.map do |f| | |
| if File.exists?(deps_filepath(f)) | |
| Set.new(open(deps_filepath(f)).read.split("\n")) | |
| else | |
| $stderr.puts "Finding dynamically-linked dependencies for #{f}" | |
| ds = get_all_dependencies(f) or Set.new | |
| open(deps_filepath(f), 'w').write(ds.to_a.join("\n")) | |
| ds | |
| end | |
| end.reject(&:nil?).reduce(:|).to_a.join("\n") | |
| puts "extra-chroot-dirs" | |
| puts deps | |
| puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment