<commit_before>class Keg
  def fix_install_names
    dylibs.each do |dylib|
      bad_install_names_for dylib do |id, bad_names|
        dylib.ensure_writable do
          system "install_name_tool", "-id", id, dylib
          bad_names.each do |bad_name|
            # we should be more careful here, check the path we point to exists etc.
            system "install_name_tool", "-change", bad_name, "@loader_path/#{bad_name}", dylib
          end
        end
      end
    end
  end

  private

  OTOOL_RX = /\t(.*) \(compatibility version (\d+\.)*\d+, current version (\d+\.)*\d+\)/

  def bad_install_names_for dylib
    dylib = dylib.to_s

    ENV['HOMEBREW_DYLIB'] = dylib # solves all shell escaping problems
    install_names = `otool -L "$HOMEBREW_DYLIB"`.split "\n"

    install_names.shift # first line is fluff
    install_names.map!{ |s| OTOOL_RX =~ s && $1 }
    id = install_names.shift
    install_names.compact!
    install_names.reject!{ |fn| fn =~ /^@(loader|executable)_path/ }
    install_names.reject!{ |fn| fn.start_with? '/' }

    unless install_names.empty? and id == dylib # avoid the work if possible
      yield dylib, install_names
    end
  end

  def dylibs
    if (lib = join 'lib').directory?
      lib.children.select{ |pn| pn.extname == '.dylib' and not pn.symlink? }
    else
      []
    end
  end
end<commit_msg>fix_install_names fix for 10.5<commit_after>class Keg
  def fix_install_names
    dylibs.each do |dylib|
      bad_install_names_for dylib do |id, bad_names|
        dylib.ensure_writable do
          system "install_name_tool", "-id", id, dylib
          bad_names.each do |bad_name|
            # we should be more careful here, check the path we point to exists etc.
            system "install_name_tool", "-change", bad_name, "@loader_path/#{bad_name}", dylib
          end
        end
      end
    end
  end

  private

  OTOOL_RX = /\t(.*) \(compatibility version (\d+\.)*\d+, current version (\d+\.)*\d+\)/

  def bad_install_names_for dylib
    dylib = dylib.to_s

    ENV['HOMEBREW_DYLIB'] = dylib # solves all shell escaping problems
    install_names = `otool -L "$HOMEBREW_DYLIB"`.split "\n"

    install_names.shift # first line is fluff
    install_names.map!{ |s| OTOOL_RX =~ s && $1 }
    id = install_names.shift
    install_names.compact!
    install_names.reject!{ |fn| fn =~ /^@(loader|executable)_path/ }
    install_names.reject!{ |fn| fn[0,1] == '/' }

    unless install_names.empty? and id == dylib # avoid the work if possible
      yield dylib, install_names
    end
  end

  def dylibs
    if (lib = join 'lib').directory?
      lib.children.select{ |pn| pn.extname == '.dylib' and not pn.symlink? }
    else
      []
    end
  end
end
{'fraction_non_alphanumeric': 0.12072138387927861, 'fraction_numerical': 0.002576370997423629, 'mean_word_length': 2.6095617529880477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6527875', 'n_tokens_mistral': 987, 'n_tokens_neox': 944, 'n_words': 252}