aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/Homebrew/cask/lib/hbc/locations.rb6
-rw-r--r--Library/Homebrew/compat/hbc/cli.rb5
-rw-r--r--Library/Homebrew/dev-cmd/aspell-dictionaries.rb47
-rw-r--r--Library/Homebrew/extend/os/linux/extend/pathname.rb20
-rw-r--r--Library/Homebrew/extend/os/mac/extend/pathname.rb2
-rw-r--r--Library/Homebrew/extend/pathname.rb4
-rw-r--r--Library/Homebrew/os/linux/elf.rb160
-rw-r--r--Library/Homebrew/os/mac/linkage_checker.rb2
-rw-r--r--Library/Homebrew/os/mac/mach.rb2
-rw-r--r--Library/Homebrew/os/mac/xquartz.rb9
-rw-r--r--Library/Homebrew/requirements/x11_requirement.rb33
-rw-r--r--Library/Homebrew/test/cask/artifact/binary_spec.rb4
-rw-r--r--Library/Homebrew/test/dependency_collector_spec.rb8
-rw-r--r--Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb6
-rw-r--r--Library/Homebrew/test/x11_requirement_spec.rb5
15 files changed, 206 insertions, 107 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/locations.rb b/Library/Homebrew/cask/lib/hbc/locations.rb
index e55bdf15d..5c9a28f5d 100644
--- a/Library/Homebrew/cask/lib/hbc/locations.rb
+++ b/Library/Homebrew/cask/lib/hbc/locations.rb
@@ -7,14 +7,10 @@ module Hbc
end
module ClassMethods
- attr_writer :caskroom
-
def caskroom
@caskroom ||= HOMEBREW_PREFIX.join("Caskroom")
end
- attr_writer :cache
-
def cache
@cache ||= HOMEBREW_CACHE.join("Cask")
end
@@ -61,8 +57,6 @@ module Hbc
@servicedir ||= Pathname.new("~/Library/Services").expand_path
end
- attr_writer :binarydir
-
def binarydir
@binarydir ||= HOMEBREW_PREFIX.join("bin")
end
diff --git a/Library/Homebrew/compat/hbc/cli.rb b/Library/Homebrew/compat/hbc/cli.rb
index 60d298ed6..fb17a1d05 100644
--- a/Library/Homebrew/compat/hbc/cli.rb
+++ b/Library/Homebrew/compat/hbc/cli.rb
@@ -11,9 +11,8 @@ module Hbc
EOS
end)
- option "--caskroom=PATH", (lambda do |value|
- Hbc.caskroom = value
- odeprecated "`brew cask` with the `--caskroom` flag", disable_on: Time.utc(2017, 10, 31)
+ option "--caskroom=PATH", (lambda do |*|
+ odisabled "`brew cask` with the `--caskroom` flag"
end)
end
end
diff --git a/Library/Homebrew/dev-cmd/aspell-dictionaries.rb b/Library/Homebrew/dev-cmd/aspell-dictionaries.rb
deleted file mode 100644
index ab0e66d2b..000000000
--- a/Library/Homebrew/dev-cmd/aspell-dictionaries.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-#: @hide_from_man_page
-#: * `aspell_dictionaries`:
-#: Generates the new dictionaries for the `aspell` formula.
-
-require "open-uri"
-require "resource"
-require "formula"
-
-module Homebrew
- module_function
-
- def aspell_dictionaries
- dict_url = "https://ftpmirror.gnu.org/aspell/dict"
- dict_mirror = "https://ftp.gnu.org/gnu/aspell/dict"
- languages = {}
-
- open("#{dict_url}/0index.html") do |content|
- content.each_line do |line|
- break if %r{^</table} =~ line
- next unless /^<tr><td><a/ =~ line
-
- fields = line.split('"')
- lang = fields[1]
- path = fields[3]
- lang.tr!("-", "_")
- languages[lang] = path
- end
- end
-
- languages.each do |lang, path|
- r = Resource.new(lang)
- r.owner = Formulary.factory("aspell")
- r.url "#{dict_url}/#{path}"
- r.mirror "#{dict_mirror}/#{path}"
- r.fetch
- puts <<-EOS
- option "with-lang-#{r.name}", "Install #{r.name} dictionary"
- resource "#{r.name}" do
- url "#{r.url}"
- mirror "#{r.mirrors.first}"
- sha256 "#{r.cached_download.sha256}"
- end
-
- EOS
- end
- end
-end
diff --git a/Library/Homebrew/extend/os/linux/extend/pathname.rb b/Library/Homebrew/extend/os/linux/extend/pathname.rb
index eb6ea409b..604351da7 100644
--- a/Library/Homebrew/extend/os/linux/extend/pathname.rb
+++ b/Library/Homebrew/extend/os/linux/extend/pathname.rb
@@ -1,19 +1,5 @@
-class Pathname
- # @private
- def elf?
- # See: https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header
- read(4) == "\x7fELF"
- end
+require "os/linux/elf"
- # @private
- def dynamic_elf?
- if which "readelf"
- popen_read("readelf", "-l", to_path).include?(" DYNAMIC ")
- elsif which "file"
- !popen_read("file", "-L", "-b", to_path)[/dynamic|shared/].nil?
- else
- raise StandardError, "Neither `readelf` nor `file` is available "\
- "to determine whether '#{self}' is dynamically or statically linked."
- end
- end
+class Pathname
+ prepend ELFShim
end
diff --git a/Library/Homebrew/extend/os/mac/extend/pathname.rb b/Library/Homebrew/extend/os/mac/extend/pathname.rb
index 5fd59e1e7..4ced5a094 100644
--- a/Library/Homebrew/extend/os/mac/extend/pathname.rb
+++ b/Library/Homebrew/extend/os/mac/extend/pathname.rb
@@ -1,5 +1,5 @@
require "os/mac/mach"
class Pathname
- include MachOShim
+ prepend MachOShim
end
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb
index 82cf10be0..32d57c1c4 100644
--- a/Library/Homebrew/extend/pathname.rb
+++ b/Library/Homebrew/extend/pathname.rb
@@ -470,6 +470,10 @@ class Pathname
end
}
end
+
+ def mach_o_bundle?
+ false
+ end
end
require "extend/os/pathname"
diff --git a/Library/Homebrew/os/linux/elf.rb b/Library/Homebrew/os/linux/elf.rb
new file mode 100644
index 000000000..1a53e50f3
--- /dev/null
+++ b/Library/Homebrew/os/linux/elf.rb
@@ -0,0 +1,160 @@
+module ELFShim
+ # See: https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header
+ MAGIC_NUMBER_OFFSET = 0
+ MAGIC_NUMBER_ASCII = "\x7fELF".freeze
+
+ OS_ABI_OFFSET = 0x07
+ OS_ABI_SYSTEM_V = 0
+ OS_ABI_LINUX = 3
+
+ TYPE_OFFSET = 0x10
+ TYPE_EXECUTABLE = 2
+ TYPE_SHARED = 3
+
+ ARCHITECTURE_OFFSET = 0x12
+ ARCHITECTURE_I386 = 0x3
+ ARCHITECTURE_POWERPC = 0x14
+ ARCHITECTURE_ARM = 0x28
+ ARCHITECTURE_X86_64 = 0x62
+ ARCHITECTURE_AARCH64 = 0xB7
+
+ def read_uint8(offset)
+ read(1, offset).unpack("C").first
+ end
+
+ def read_uint16(offset)
+ read(2, offset).unpack("v").first
+ end
+
+ def elf?
+ return @elf if defined? @elf
+ return @elf = false unless read(MAGIC_NUMBER_ASCII.size, MAGIC_NUMBER_OFFSET) == MAGIC_NUMBER_ASCII
+
+ # Check that this ELF file is for Linux or System V.
+ # OS_ABI is often set to 0 (System V), regardless of the target platform.
+ @elf = [OS_ABI_LINUX, OS_ABI_SYSTEM_V].include? read_uint8(OS_ABI_OFFSET)
+ end
+
+ def arch
+ return :dunno unless elf?
+
+ @arch ||= case read_uint16(ARCHITECTURE_OFFSET)
+ when ARCHITECTURE_I386 then :i386
+ when ARCHITECTURE_X86_64 then :x86_64
+ when ARCHITECTURE_POWERPC then :powerpc
+ when ARCHITECTURE_ARM then :arm
+ when ARCHITECTURE_AARCH64 then :arm64
+ else :dunno
+ end
+ end
+
+ def elf_type
+ return :dunno unless elf?
+
+ @elf_type ||= case read_uint16(TYPE_OFFSET)
+ when TYPE_EXECUTABLE then :executable
+ when TYPE_SHARED then :dylib
+ else :dunno
+ end
+ end
+
+ def dylib?
+ elf_type == :dylib
+ end
+
+ def binary_executable?
+ elf_type == :executable
+ end
+
+ def dynamic_elf?
+ return @dynamic_elf if defined? @dynamic_elf
+
+ if which "readelf"
+ Utils.popen_read("readelf", "-l", to_path).include?(" DYNAMIC ")
+ elsif which "file"
+ !Utils.popen_read("file", "-L", "-b", to_path)[/dynamic|shared/].nil?
+ else
+ raise "Please install either readelf (from binutils) or file."
+ end
+ end
+
+ class Metadata
+ attr_reader :path, :dylib_id, :dylibs
+
+ def initialize(path)
+ @path = path
+ @dylibs = []
+ @dylib_id, needed = needed_libraries path
+ return if needed.empty?
+
+ ldd = DevelopmentTools.locate "ldd"
+ ldd_output = Utils.popen_read(ldd, path.expand_path.to_s).split("\n")
+ return unless $CHILD_STATUS.success?
+
+ ldd_paths = ldd_output.map do |line|
+ match = line.match(/\t.+ => (.+) \(.+\)|\t(.+) => not found/)
+ next unless match
+ match.captures.compact.first
+ end.compact
+ @dylibs = ldd_paths.select do |ldd_path|
+ next true unless ldd_path.start_with? "/"
+ needed.include? File.basename(ldd_path)
+ end
+ end
+
+ private
+
+ def needed_libraries(path)
+ if DevelopmentTools.locate "readelf"
+ needed_libraries_using_readelf path
+ elsif DevelopmentTools.locate "patchelf"
+ needed_libraries_using_patchelf path
+ else
+ raise "patchelf must be installed: brew install patchelf"
+ end
+ end
+
+ def needed_libraries_using_patchelf(path)
+ patchelf = DevelopmentTools.locate "patchelf"
+ if path.dylib?
+ command = [patchelf, "--print-soname", path.expand_path.to_s]
+ soname = Utils.popen_read(*command).chomp
+ raise ErrorDuringExecution, command unless $CHILD_STATUS.success?
+ end
+ command = [patchelf, "--print-needed", path.expand_path.to_s]
+ needed = Utils.popen_read(*command).split("\n")
+ raise ErrorDuringExecution, command unless $CHILD_STATUS.success?
+ [soname, needed]
+ end
+
+ def needed_libraries_using_readelf(path)
+ soname = nil
+ needed = []
+ command = ["readelf", "-d", path.expand_path.to_s]
+ lines = Utils.popen_read(*command).split("\n")
+ raise ErrorDuringExecution, command unless $CHILD_STATUS.success?
+ lines.each do |s|
+ filename = s[/\[(.*)\]/, 1]
+ next if filename.nil?
+ if s.include? "(SONAME)"
+ soname = filename
+ elsif s.include? "(NEEDED)"
+ needed << filename
+ end
+ end
+ [soname, needed]
+ end
+ end
+
+ def metadata
+ @metadata ||= Metadata.new(self)
+ end
+
+ def dylib_id
+ metadata.dylib_id
+ end
+
+ def dynamically_linked_libraries(*)
+ metadata.dylibs
+ end
+end
diff --git a/Library/Homebrew/os/mac/linkage_checker.rb b/Library/Homebrew/os/mac/linkage_checker.rb
index f6aa4c2f3..941a5a847 100644
--- a/Library/Homebrew/os/mac/linkage_checker.rb
+++ b/Library/Homebrew/os/mac/linkage_checker.rb
@@ -23,7 +23,7 @@ class LinkageChecker
def check_dylibs
@keg.find do |file|
next if file.symlink? || file.directory?
- next unless file.dylib? || file.mach_o_executable? || file.mach_o_bundle?
+ next unless file.dylib? || file.binary_executable? || file.mach_o_bundle?
# weakly loaded dylibs may not actually exist on disk, so skip them
# when checking for broken linkage
diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb
index 9b53c4979..958618869 100644
--- a/Library/Homebrew/os/mac/mach.rb
+++ b/Library/Homebrew/os/mac/mach.rb
@@ -103,6 +103,8 @@ module MachOShim
mach_data.any? { |m| m.fetch(:type) == :executable }
end
+ alias binary_executable? mach_o_executable?
+
# @private
def mach_o_bundle?
mach_data.any? { |m| m.fetch(:type) == :bundle }
diff --git a/Library/Homebrew/os/mac/xquartz.rb b/Library/Homebrew/os/mac/xquartz.rb
index efbb5b738..9148e178b 100644
--- a/Library/Homebrew/os/mac/xquartz.rb
+++ b/Library/Homebrew/os/mac/xquartz.rb
@@ -51,6 +51,15 @@ module OS
end
end
+ def minimum_version
+ version = guess_system_version
+ return version unless version == "dunno"
+
+ # Update this a little later than latest_version to give people
+ # time to upgrade.
+ "2.7.11"
+ end
+
# https://xquartz.macosforge.org/trac/wiki
# https://xquartz.macosforge.org/trac/wiki/Releases
def latest_version
diff --git a/Library/Homebrew/requirements/x11_requirement.rb b/Library/Homebrew/requirements/x11_requirement.rb
index 03d0382c5..e0974107a 100644
--- a/Library/Homebrew/requirements/x11_requirement.rb
+++ b/Library/Homebrew/requirements/x11_requirement.rb
@@ -2,7 +2,6 @@ require "requirement"
class X11Requirement < Requirement
include Comparable
- attr_reader :min_version
fatal true
cask "xquartz"
@@ -12,36 +11,38 @@ class X11Requirement < Requirement
def initialize(name = "x11", tags = [])
@name = name
- if /(\d\.)+\d/ =~ tags.first
- @min_version = Version.create(tags.shift)
- @min_version_string = " #{@min_version}"
- else
- @min_version = Version.create("0.0.0")
- @min_version_string = ""
- end
+ # no-op on version specified as a tag argument
+ tags.shift if /(\d\.)+\d/ =~ tags.first
super(tags)
end
+ def min_version
+ # TODO: remove in https://github.com/Homebrew/brew/pull/3483
+ return Version::NULL unless OS.mac?
+
+ MacOS::XQuartz.minimum_version
+ end
+
satisfy build_env: false do
- MacOS::XQuartz.installed? && min_version <= Version.create(MacOS::XQuartz.version)
+ # TODO: remove in https://github.com/Homebrew/brew/pull/3483
+ next false unless OS.mac?
+
+ next false unless MacOS::XQuartz.installed?
+ min_version <= MacOS::XQuartz.version
end
def message
- s = "XQuartz#{@min_version_string} is required to install this formula."
+ s = "XQuartz #{min_version} (or newer) is required to install this formula."
s += super
s
end
def <=>(other)
return unless other.is_a? X11Requirement
- min_version <=> other.min_version
- end
-
- def eql?(other)
- super && min_version == other.min_version
+ 0
end
def inspect
- "#<#{self.class.name}: #{name.inspect} #{tags.inspect} min_version=#{min_version}>"
+ "#<#{self.class.name}: #{name.inspect} #{tags.inspect}>"
end
end
diff --git a/Library/Homebrew/test/cask/artifact/binary_spec.rb b/Library/Homebrew/test/cask/artifact/binary_spec.rb
index 6a3f1da34..e9514d9ae 100644
--- a/Library/Homebrew/test/cask/artifact/binary_spec.rb
+++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb
@@ -7,10 +7,6 @@ describe Hbc::Artifact::Binary, :cask do
let(:artifacts) { cask.artifacts.select { |a| a.is_a?(described_class) } }
let(:expected_path) { Hbc.binarydir.join("binary") }
- before(:each) do
- Hbc.binarydir.mkpath
- end
-
after(:each) do
FileUtils.rm expected_path if expected_path.exist?
end
diff --git a/Library/Homebrew/test/dependency_collector_spec.rb b/Library/Homebrew/test/dependency_collector_spec.rb
index 8feeac4a2..3905717ad 100644
--- a/Library/Homebrew/test/dependency_collector_spec.rb
+++ b/Library/Homebrew/test/dependency_collector_spec.rb
@@ -49,9 +49,9 @@ describe DependencyCollector do
expect(find_requirement(X11Requirement).tags).to be_empty
end
- specify "x11 with minimum version" do
+ specify "x11 with (ignored) minimum version" do
subject.add x11: "2.5.1"
- expect(find_requirement(X11Requirement).min_version.to_s).to eq("2.5.1")
+ expect(find_requirement(X11Requirement).min_version.to_s).to_not eq("2.5.1")
end
specify "x11 with tag" do
@@ -59,10 +59,10 @@ describe DependencyCollector do
expect(find_requirement(X11Requirement)).to be_optional
end
- specify "x11 with minimum version and tag" do
+ specify "x11 with (ignored) minimum version and tag" do
subject.add x11: ["2.5.1", :optional]
dep = find_requirement(X11Requirement)
- expect(dep.min_version.to_s).to eq("2.5.1")
+ expect(dep.min_version.to_s).to_not eq("2.5.1")
expect(dep).to be_optional
end
diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb
index fc83149d0..e1afc44bf 100644
--- a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb
+++ b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb
@@ -8,18 +8,17 @@ require "test/support/helper/cask/never_sudo_system_command"
HOMEBREW_CASK_DIRS = [
:appdir,
- :caskroom,
- :cache,
:prefpanedir,
:qlplugindir,
:servicedir,
- :binarydir,
].freeze
RSpec.shared_context "Homebrew-Cask" do
around(:each) do |example|
third_party_tap = Tap.fetch("third-party", "tap")
begin
+ [Hbc.binarydir, Hbc.caskroom, Hbc.cache].each(&:mkpath)
+
dirs = HOMEBREW_CASK_DIRS.map do |dir|
Pathname.new(TEST_TMPDIR).join("cask-#{dir}").tap do |path|
path.mkpath
@@ -40,6 +39,7 @@ RSpec.shared_context "Homebrew-Cask" do
example.run
ensure
FileUtils.rm_rf dirs
+ FileUtils.rm_rf [Hbc.binarydir, Hbc.caskroom, Hbc.cache]
Hbc.default_tap.path.unlink
FileUtils.rm_rf Hbc.default_tap.path.parent
third_party_tap.path.unlink
diff --git a/Library/Homebrew/test/x11_requirement_spec.rb b/Library/Homebrew/test/x11_requirement_spec.rb
index bc02dc75a..ef50fdc76 100644
--- a/Library/Homebrew/test/x11_requirement_spec.rb
+++ b/Library/Homebrew/test/x11_requirement_spec.rb
@@ -19,11 +19,6 @@ describe X11Requirement do
other = described_class.new("foo")
expect(subject).not_to eql(other)
end
-
- it "returns false if the minimum version differs" do
- other = described_class.new(default_name, ["2.5"])
- expect(subject).not_to eql(other)
- end
end
describe "#modify_build_environment" do