diff options
| author | Josh Hagins | 2016-10-23 23:48:07 -0400 |
|---|---|---|
| committer | Josh Hagins | 2016-10-24 16:21:08 -0400 |
| commit | fab2cffe5de82b6d540fcf3f4f8873f7cd89af34 (patch) | |
| tree | 4228093e30d00c9568538342adf8ef10c55377cd /Library/Homebrew | |
| parent | adc4b1f0c73fc549f63e44118b49fdecd32b9394 (diff) | |
| download | brew-fab2cffe5de82b6d540fcf3f4f8873f7cd89af34.tar.bz2 | |
keg_relocate: wrap relocation locations in struct
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/extend/os/mac/keg_relocate.rb | 12 | ||||
| -rw-r--r-- | Library/Homebrew/keg_relocate.rb | 55 |
2 files changed, 43 insertions, 24 deletions
diff --git a/Library/Homebrew/extend/os/mac/keg_relocate.rb b/Library/Homebrew/extend/os/mac/keg_relocate.rb index 33ee149ce..8f73daba5 100644 --- a/Library/Homebrew/extend/os/mac/keg_relocate.rb +++ b/Library/Homebrew/extend/os/mac/keg_relocate.rb @@ -17,19 +17,19 @@ class Keg generic_fix_dynamic_linkage end - def relocate_dynamic_linkage(old_prefix, new_prefix, old_cellar, new_cellar) + def relocate_dynamic_linkage(relocation) mach_o_files.each do |file| file.ensure_writable do if file.dylib? - id = dylib_id_for(file).sub(old_prefix, new_prefix) + id = dylib_id_for(file).sub(relocation.old_prefix, relocation.new_prefix) change_dylib_id(id, file) end each_install_name_for(file) do |old_name| - if old_name.start_with? old_cellar - new_name = old_name.sub(old_cellar, new_cellar) - elsif old_name.start_with? old_prefix - new_name = old_name.sub(old_prefix, new_prefix) + if old_name.start_with? relocation.old_cellar + new_name = old_name.sub(relocation.old_cellar, relocation.new_cellar) + elsif old_name.start_with? relocation.old_prefix + new_name = old_name.sub(relocation.old_prefix, relocation.new_prefix) end change_install_name(old_name, new_name, file) if new_name diff --git a/Library/Homebrew/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb index cc40615b2..712408b8b 100644 --- a/Library/Homebrew/keg_relocate.rb +++ b/Library/Homebrew/keg_relocate.rb @@ -3,6 +3,14 @@ class Keg CELLAR_PLACEHOLDER = "@@HOMEBREW_CELLAR@@".freeze REPOSITORY_PLACEHOLDER = "@@HOMEBREW_REPOSITORY@@".freeze + Relocation = Struct.new(:old_prefix, :old_cellar, :old_repository, + :new_prefix, :new_cellar, :new_repository) do + # Use keyword args instead of positional args for initialization + def initialize(**kwargs) + super(*members.map { |k| kwargs[k] }) + end + end + def fix_dynamic_linkage symlink_files.each do |file| link = file.readlink @@ -15,38 +23,49 @@ class Keg end alias generic_fix_dynamic_linkage fix_dynamic_linkage - def relocate_dynamic_linkage(_old_prefix, _new_prefix, _old_cellar, _new_cellar) + def relocate_dynamic_linkage(_relocation) [] end def replace_locations_with_placeholders - relocate_dynamic_linkage(HOMEBREW_PREFIX.to_s, PREFIX_PLACEHOLDER, - HOMEBREW_CELLAR.to_s, CELLAR_PLACEHOLDER) - replacements = { - HOMEBREW_PREFIX.to_s => PREFIX_PLACEHOLDER, - HOMEBREW_CELLAR.to_s => CELLAR_PLACEHOLDER, - HOMEBREW_REPOSITORY.to_s => REPOSITORY_PLACEHOLDER, - } - replace_text_in_files(replacements) + relocation = Relocation.new( + old_prefix: HOMEBREW_PREFIX.to_s, + old_cellar: HOMEBREW_CELLAR.to_s, + old_repository: HOMEBREW_REPOSITORY.to_s, + new_prefix: PREFIX_PLACEHOLDER, + new_cellar: CELLAR_PLACEHOLDER, + new_repository: REPOSITORY_PLACEHOLDER + ) + relocate_dynamic_linkage(relocation) + replace_text_in_files(relocation) end def replace_placeholders_with_locations(files) - relocate_dynamic_linkage(PREFIX_PLACEHOLDER, HOMEBREW_PREFIX.to_s, - CELLAR_PLACEHOLDER, HOMEBREW_CELLAR.to_s) - replacements = { - PREFIX_PLACEHOLDER => HOMEBREW_PREFIX.to_s, - CELLAR_PLACEHOLDER => HOMEBREW_CELLAR.to_s, - REPOSITORY_PLACEHOLDER => HOMEBREW_REPOSITORY.to_s, - } - replace_text_in_files(replacements, files) + relocation = Relocation.new( + old_prefix: PREFIX_PLACEHOLDER, + old_cellar: CELLAR_PLACEHOLDER, + old_repository: REPOSITORY_PLACEHOLDER, + new_prefix: HOMEBREW_PREFIX.to_s, + new_cellar: HOMEBREW_CELLAR.to_s, + new_repository: HOMEBREW_REPOSITORY.to_s + ) + relocate_dynamic_linkage(relocation) + replace_text_in_files(relocation, files: files) end - def replace_text_in_files(replacements, files = nil) + def replace_text_in_files(relocation, files: nil) files ||= text_files | libtool_files changed_files = [] files.map(&path.method(:join)).group_by { |f| f.stat.ino }.each_value do |first, *rest| s = first.open("rb", &:read) + + replacements = { + relocation.old_prefix => relocation.new_prefix, + relocation.old_cellar => relocation.new_cellar, + relocation.old_repository => relocation.new_repository, + } + regexp = Regexp.union(replacements.keys) changed = s.gsub!(regexp, replacements) |
