From 258d70028f359e88b3300fdd1b8442428ef75826 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Sun, 10 Mar 2013 17:33:06 +0000 Subject: Portability fixes to run Homebrew on Linux systems Closes Homebrew/homebrew#16344. Signed-off-by: Mike McQuaid --- Library/Homebrew/formula_installer.rb | 2 +- Library/Homebrew/hardware.rb | 64 ++------- Library/Homebrew/mach.rb | 2 + Library/Homebrew/macos.rb | 6 +- Library/Homebrew/macos/version.rb | 16 --- Library/Homebrew/macos/xcode.rb | 173 ----------------------- Library/Homebrew/macos/xquartz.rb | 101 ------------- Library/Homebrew/os/linux/hardware.rb | 25 ++++ Library/Homebrew/os/mac/hardware.rb | 57 ++++++++ Library/Homebrew/os/mac/version.rb | 16 +++ Library/Homebrew/os/mac/xcode.rb | 173 +++++++++++++++++++++++ Library/Homebrew/os/mac/xquartz.rb | 101 +++++++++++++ Library/Homebrew/test/test_version_subclasses.rb | 2 +- 13 files changed, 388 insertions(+), 350 deletions(-) delete mode 100644 Library/Homebrew/macos/version.rb delete mode 100644 Library/Homebrew/macos/xcode.rb delete mode 100644 Library/Homebrew/macos/xquartz.rb create mode 100644 Library/Homebrew/os/linux/hardware.rb create mode 100644 Library/Homebrew/os/mac/hardware.rb create mode 100644 Library/Homebrew/os/mac/version.rb create mode 100644 Library/Homebrew/os/mac/xcode.rb create mode 100644 Library/Homebrew/os/mac/xquartz.rb (limited to 'Library') diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index a84502ed8..9251fe487 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -284,7 +284,7 @@ class FormulaInstaller fork do begin read.close - exec '/usr/bin/nice', + exec 'nice', RUBY_PATH, '-W0', '-I', Pathname.new(__FILE__).dirname, diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index 20794be0a..ded0c9ccb 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -1,47 +1,15 @@ class Hardware - # These methods use info spewed out by sysctl. - # Look in for decoding info. - - def self.cpu_type - @@cpu_type ||= `/usr/sbin/sysctl -n hw.cputype`.to_i - - case @@cpu_type - when 7 - :intel - when 18 - :ppc - else - :dunno - end - end - - def self.intel_family - @@intel_family ||= `/usr/sbin/sysctl -n hw.cpufamily`.to_i - - case @@intel_family - when 0x73d67300 # Yonah: Core Solo/Duo - :core - when 0x426f69ef # Merom: Core 2 Duo - :core2 - when 0x78ea4fbc # Penryn - :penryn - when 0x6b5a4cd2 # Nehalem - :nehalem - when 0x573B5EEC # Arrandale - :arrandale - when 0x5490B78C # Sandy Bridge - :sandybridge - when 0x1F65E835 # Ivy Bridge - :ivybridge - else - :dunno - end + case RUBY_PLATFORM.downcase + when /darwin/ + require 'os/mac/hardware' + extend MacOSHardware + when /linux/ + require 'os/linux/hardware' + extend LinuxHardware + else + raise "The system `#{`uname`.chomp}' is not supported." end - def self.processor_count - @@processor_count ||= `/usr/sbin/sysctl -n hw.ncpu`.to_i - end - def self.cores_as_words case Hardware.processor_count when 1 then 'single' @@ -56,21 +24,7 @@ class Hardware not self.is_64_bit? end - def self.is_64_bit? - return @@is_64_bit if defined? @@is_64_bit - @@is_64_bit = self.sysctl_bool("hw.cpu64bit_capable") - end - def self.bits Hardware.is_64_bit? ? 64 : 32 end - -protected - def self.sysctl_bool(property) - result = nil - IO.popen("/usr/sbin/sysctl -n #{property} 2>/dev/null") do |f| - result = f.gets.to_i # should be 0 or 1 - end - $?.success? && result == 1 # sysctl call succeded and printed 1 - end end diff --git a/Library/Homebrew/mach.rb b/Library/Homebrew/mach.rb index be93aca57..537b2588e 100644 --- a/Library/Homebrew/mach.rb +++ b/Library/Homebrew/mach.rb @@ -40,6 +40,8 @@ module MachO end when 0xcefaedfe, 0xcffaedfe, 0xfeedface, 0xfeedfacf # Single arch offsets << 0 + when 0x7f454c46 # ELF + mach_data << { :arch => :x86_64, :type => :executable } else raise "Not a Mach-O binary." end diff --git a/Library/Homebrew/macos.rb b/Library/Homebrew/macos.rb index b28be62dc..2d378932c 100644 --- a/Library/Homebrew/macos.rb +++ b/Library/Homebrew/macos.rb @@ -1,4 +1,4 @@ -require 'macos/version' +require 'os/mac/version' module MacOS extend self @@ -238,5 +238,5 @@ module MacOS extend self end end -require 'macos/xcode' -require 'macos/xquartz' +require 'os/mac/xcode' +require 'os/mac/xquartz' diff --git a/Library/Homebrew/macos/version.rb b/Library/Homebrew/macos/version.rb deleted file mode 100644 index 090b1ffb7..000000000 --- a/Library/Homebrew/macos/version.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'version' - -module MacOS - class Version < ::Version - def <=>(other) - v = case other - when :mountain_lion then 10.8 - when :lion then 10.7 - when :snow_leopard then 10.6 - when :leopard then 10.5 - else other.to_s - end - super(Version.new(v)) - end - end -end diff --git a/Library/Homebrew/macos/xcode.rb b/Library/Homebrew/macos/xcode.rb deleted file mode 100644 index 0bb68636a..000000000 --- a/Library/Homebrew/macos/xcode.rb +++ /dev/null @@ -1,173 +0,0 @@ -module MacOS::Xcode extend self - - V4_BUNDLE_ID = "com.apple.dt.Xcode" - V3_BUNDLE_ID = "com.apple.Xcode" - V4_BUNDLE_PATH = Pathname.new("/Applications/Xcode.app") - V3_BUNDLE_PATH = Pathname.new("/Developer/Applications/Xcode.app") - - # Locate the "current Xcode folder" via xcode-select. See: - # man xcode-select - # NOTE!! use Xcode.prefix rather than this generally! - def folder - @folder ||= `xcode-select -print-path 2>/dev/null`.strip - end - - # Xcode 4.3 tools hang if "/" is set - def bad_xcode_select_path? - folder == "/" - end - - def latest_version - case MacOS.version - when 10.5 then "3.1.4" - when 10.6 then "3.2.6" - else - if MacOS.version >= 10.7 - "4.6" - else - raise "Mac OS X `#{MacOS.version}' is invalid" - end - end - end - - def prefix - @prefix ||= begin - path = Pathname.new(folder) - if path.absolute? and (path/'usr/bin/make').executable? - path - elsif File.executable? '/Developer/usr/bin/make' - # we do this to support cowboys who insist on installing - # only a subset of Xcode - Pathname.new '/Developer' - elsif (V4_BUNDLE_PATH/'Contents/Developer/usr/bin/make').executable? - # fallback for broken Xcode 4.3 installs - V4_BUNDLE_PATH/'Contents/Developer' - else - # Ask Spotlight where Xcode is. If the user didn't install the - # helper tools and installed Xcode in a non-conventional place, this - # is our only option. See: http://superuser.com/questions/390757 - path = MacOS.app_with_bundle_id(V4_BUNDLE_ID) || - MacOS.app_with_bundle_id(V3_BUNDLE_ID) - - unless path.nil? - path += "Contents/Developer" - path if (path/'usr/bin/make').executable? - end - end - end - end - - def installed? - not prefix.nil? - end - - def version - # may return a version string - # that is guessed based on the compiler, so do not - # use it in order to check if Xcode is installed. - @version ||= uncached_version - end - - def uncached_version - # This is a separate function as you can't cache the value out of a block - # if return is used in the middle, which we do many times in here. - - return "0" unless MACOS - - # this shortcut makes version work for people who don't realise you - # need to install the CLI tools - xcode43build = V4_BUNDLE_PATH/'Contents/Developer/usr/bin/xcodebuild' - if xcode43build.file? - `#{xcode43build} -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/ - return $1 if $1 - end - - # Xcode 4.3 xc* tools hang indefinately if xcode-select path is set thus - raise if bad_xcode_select_path? - - raise unless which "xcodebuild" - `xcodebuild -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/ - raise if $1.nil? or not $?.success? - $1 - rescue - # For people who's xcode-select is unset, or who have installed - # xcode-gcc-installer or whatever other combinations we can try and - # supprt. See https://github.com/mxcl/homebrew/wiki/Xcode - case MacOS.llvm_build_version.to_i - when 1..2063 then "3.1.0" - when 2064..2065 then "3.1.4" - when 2366..2325 - # we have no data for this range so we are guessing - "3.2.0" - when 2326 - # also applies to "3.2.3" - "3.2.4" - when 2327..2333 then "3.2.5" - when 2335 - # this build number applies to 3.2.6, 4.0 and 4.1 - # https://github.com/mxcl/homebrew/wiki/Xcode - "4.0" - else - case (MacOS.clang_version.to_f * 10).to_i - when 0 then "dunno" - when 1..14 then "3.2.2" - when 15 then "3.2.4" - when 16 then "3.2.5" - when 17..20 then "4.0" - when 21 then "4.1" - when 22..30 then "4.2" - when 31 then "4.3" - when 40 then "4.4" - when 41 then "4.5" - when 42 then "4.6" - else "4.6" - end - end - end - - def provides_autotools? - version.to_f < 4.3 - end - - def provides_gcc? - version.to_f < 4.3 - end - - def default_prefix? - if version.to_f < 4.3 - %r{^/Developer} === prefix - else - %r{^/Applications/Xcode.app} === prefix - end - end -end - -module MacOS::CLT extend self - STANDALONE_PKG_ID = "com.apple.pkg.DeveloperToolsCLILeo" - FROM_XCODE_PKG_ID = "com.apple.pkg.DeveloperToolsCLI" - - # This is true ift he standard UNIX tools are present under /usr. For - # Xcode < 4.3, this is the standard location. Otherwise, it means that - # the user has installed the "Command Line Tools for Xcode" package. - def installed? - MacOS.dev_tools_path == Pathname.new("/usr/bin") - end - - def latest_version? - `/usr/bin/clang --version` =~ %r{clang-(\d+)\.(\d+)\.(\d+)} - $1.to_i >= 425 and $3.to_i >= 24 - end - - def version - # The pkgutils calls are slow, don't repeat if no CLT installed. - return @version if @version_determined - - @version_determined = true - # Version string (a pretty damn long one) of the CLT package. - # Note, that different ways to install the CLTs lead to different - # version numbers. - @version ||= [STANDALONE_PKG_ID, FROM_XCODE_PKG_ID].find do |id| - MacOS.pkgutil_info(id) =~ /version: (.+)$/ - end && $1 - end -end diff --git a/Library/Homebrew/macos/xquartz.rb b/Library/Homebrew/macos/xquartz.rb deleted file mode 100644 index a515d8915..000000000 --- a/Library/Homebrew/macos/xquartz.rb +++ /dev/null @@ -1,101 +0,0 @@ -module MacOS::XQuartz extend self - FORGE_BUNDLE_ID = "org.macosforge.xquartz.X11" - APPLE_BUNDLE_ID = "org.x.X11" - FORGE_PKG_ID = "org.macosforge.xquartz.pkg" - - # This returns the version number of XQuartz, not of the upstream X.org. - # The X11.app distributed by Apple is also XQuartz, and therefore covered - # by this method. - def version - @version ||= begin - path = MacOS.app_with_bundle_id(FORGE_BUNDLE_ID) || MacOS.app_with_bundle_id(APPLE_BUNDLE_ID) - if not path.nil? and path.exist? - `mdls -raw -name kMDItemVersion "#{path}" 2>/dev/null`.strip - elsif prefix.to_s == "/usr/X11" - # Some users disable Spotlight indexing. If we're working with the - # system X11 distribution, we can't get the version from pkgutil, so - # just use the expected version. - case MacOS.version - when 10.5 then "2.1.6" - when 10.6 then "2.3.6" - when 10.7 then "2.6.3" - else "dunno" - end - else - # Finally, try to find it via pkgutil. This is slow, and only works - # for the upstream XQuartz package, so use it as a last resort. - MacOS.pkgutil_info(FORGE_PKG_ID) =~ /version: (\d\.\d\.\d).+$/ and $1 - end - end - end - - def latest_version - "2.7.4" - end - - def provided_by_apple? - [FORGE_BUNDLE_ID, APPLE_BUNDLE_ID].find do |id| - MacOS.app_with_bundle_id(id) - end == APPLE_BUNDLE_ID - end - - # This should really be private, but for compatibility reasons it must - # remain public. New code should use MacOS::X11.{bin,lib,include} - # instead, as that accounts for Xcode-only systems. - def prefix - @prefix ||= if Pathname.new('/opt/X11/lib/libpng.dylib').exist? - Pathname.new('/opt/X11') - elsif Pathname.new('/usr/X11/lib/libpng.dylib').exist? - Pathname.new('/usr/X11') - end - end - - def installed? - !version.nil? && !prefix.nil? - end -end - -module MacOS::X11 extend self - def prefix - MacOS::XQuartz.prefix - end - - def installed? - MacOS::XQuartz.installed? - end - - # If XQuartz and/or the CLT are installed, headers will be found under - # /opt/X11/include or /usr/X11/include. For Xcode-only systems, they are - # found in the SDK, so we use sdk_path for both the headers and libraries. - # Confusingly, executables (e.g. config scripts) are only found under - # /opt/X11/bin or /usr/X11/bin in all cases. - def bin - prefix/'bin' - end - - def include - @include ||= if use_sdk? - MacOS.sdk_path/'usr/X11/include' - else - prefix/'include' - end - end - - def lib - @lib ||= if use_sdk? - MacOS.sdk_path/'usr/X11/lib' - else - prefix/'lib' - end - end - - def share - prefix/'share' - end - - private - - def use_sdk? - not (prefix.to_s == '/opt/X11' or MacOS::CLT.installed?) - end -end diff --git a/Library/Homebrew/os/linux/hardware.rb b/Library/Homebrew/os/linux/hardware.rb new file mode 100644 index 000000000..8fd4b09b9 --- /dev/null +++ b/Library/Homebrew/os/linux/hardware.rb @@ -0,0 +1,25 @@ +module LinuxHardware + def cpu_type + @@cpu_type ||= case `uname -m` + when /x86_64/ + :intel + when /i386/ + :intel + else + :dunno + end + end + + def intel_family + :dunno + end + + def processor_count + `grep -c ^processor /proc/cpuinfo`.to_i + end + + def is_64_bit? + return @@is_64_bit if defined? @@is_64_bit + @@is_64_bit = /64/ === `uname -m` + end +end diff --git a/Library/Homebrew/os/mac/hardware.rb b/Library/Homebrew/os/mac/hardware.rb new file mode 100644 index 000000000..ffdc6246c --- /dev/null +++ b/Library/Homebrew/os/mac/hardware.rb @@ -0,0 +1,57 @@ +module MacOSHardware + # These methods use info spewed out by sysctl. + # Look in for decoding info. + def cpu_type + @@cpu_type ||= `/usr/sbin/sysctl -n hw.cputype`.to_i + + case @@cpu_type + when 7 + :intel + when 18 + :ppc + else + :dunno + end + end + + def intel_family + @@intel_family ||= `/usr/sbin/sysctl -n hw.cpufamily`.to_i + + case @@intel_family + when 0x73d67300 # Yonah: Core Solo/Duo + :core + when 0x426f69ef # Merom: Core 2 Duo + :core2 + when 0x78ea4fbc # Penryn + :penryn + when 0x6b5a4cd2 # Nehalem + :nehalem + when 0x573B5EEC # Arrandale + :arrandale + when 0x5490B78C # Sandy Bridge + :sandybridge + when 0x1F65E835 # Ivy Bridge + :ivybridge + else + :dunno + end + end + + def processor_count + @@processor_count ||= `/usr/sbin/sysctl -n hw.ncpu`.to_i + end + + def is_64_bit? + return @@is_64_bit if defined? @@is_64_bit + @@is_64_bit = sysctl_bool("hw.cpu64bit_capable") + end + +protected + def sysctl_bool(property) + result = nil + IO.popen("/usr/sbin/sysctl -n #{property} 2>/dev/null") do |f| + result = f.gets.to_i # should be 0 or 1 + end + $?.success? && result == 1 # sysctl call succeded and printed 1 + end +end diff --git a/Library/Homebrew/os/mac/version.rb b/Library/Homebrew/os/mac/version.rb new file mode 100644 index 000000000..090b1ffb7 --- /dev/null +++ b/Library/Homebrew/os/mac/version.rb @@ -0,0 +1,16 @@ +require 'version' + +module MacOS + class Version < ::Version + def <=>(other) + v = case other + when :mountain_lion then 10.8 + when :lion then 10.7 + when :snow_leopard then 10.6 + when :leopard then 10.5 + else other.to_s + end + super(Version.new(v)) + end + end +end diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb new file mode 100644 index 000000000..0bb68636a --- /dev/null +++ b/Library/Homebrew/os/mac/xcode.rb @@ -0,0 +1,173 @@ +module MacOS::Xcode extend self + + V4_BUNDLE_ID = "com.apple.dt.Xcode" + V3_BUNDLE_ID = "com.apple.Xcode" + V4_BUNDLE_PATH = Pathname.new("/Applications/Xcode.app") + V3_BUNDLE_PATH = Pathname.new("/Developer/Applications/Xcode.app") + + # Locate the "current Xcode folder" via xcode-select. See: + # man xcode-select + # NOTE!! use Xcode.prefix rather than this generally! + def folder + @folder ||= `xcode-select -print-path 2>/dev/null`.strip + end + + # Xcode 4.3 tools hang if "/" is set + def bad_xcode_select_path? + folder == "/" + end + + def latest_version + case MacOS.version + when 10.5 then "3.1.4" + when 10.6 then "3.2.6" + else + if MacOS.version >= 10.7 + "4.6" + else + raise "Mac OS X `#{MacOS.version}' is invalid" + end + end + end + + def prefix + @prefix ||= begin + path = Pathname.new(folder) + if path.absolute? and (path/'usr/bin/make').executable? + path + elsif File.executable? '/Developer/usr/bin/make' + # we do this to support cowboys who insist on installing + # only a subset of Xcode + Pathname.new '/Developer' + elsif (V4_BUNDLE_PATH/'Contents/Developer/usr/bin/make').executable? + # fallback for broken Xcode 4.3 installs + V4_BUNDLE_PATH/'Contents/Developer' + else + # Ask Spotlight where Xcode is. If the user didn't install the + # helper tools and installed Xcode in a non-conventional place, this + # is our only option. See: http://superuser.com/questions/390757 + path = MacOS.app_with_bundle_id(V4_BUNDLE_ID) || + MacOS.app_with_bundle_id(V3_BUNDLE_ID) + + unless path.nil? + path += "Contents/Developer" + path if (path/'usr/bin/make').executable? + end + end + end + end + + def installed? + not prefix.nil? + end + + def version + # may return a version string + # that is guessed based on the compiler, so do not + # use it in order to check if Xcode is installed. + @version ||= uncached_version + end + + def uncached_version + # This is a separate function as you can't cache the value out of a block + # if return is used in the middle, which we do many times in here. + + return "0" unless MACOS + + # this shortcut makes version work for people who don't realise you + # need to install the CLI tools + xcode43build = V4_BUNDLE_PATH/'Contents/Developer/usr/bin/xcodebuild' + if xcode43build.file? + `#{xcode43build} -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/ + return $1 if $1 + end + + # Xcode 4.3 xc* tools hang indefinately if xcode-select path is set thus + raise if bad_xcode_select_path? + + raise unless which "xcodebuild" + `xcodebuild -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/ + raise if $1.nil? or not $?.success? + $1 + rescue + # For people who's xcode-select is unset, or who have installed + # xcode-gcc-installer or whatever other combinations we can try and + # supprt. See https://github.com/mxcl/homebrew/wiki/Xcode + case MacOS.llvm_build_version.to_i + when 1..2063 then "3.1.0" + when 2064..2065 then "3.1.4" + when 2366..2325 + # we have no data for this range so we are guessing + "3.2.0" + when 2326 + # also applies to "3.2.3" + "3.2.4" + when 2327..2333 then "3.2.5" + when 2335 + # this build number applies to 3.2.6, 4.0 and 4.1 + # https://github.com/mxcl/homebrew/wiki/Xcode + "4.0" + else + case (MacOS.clang_version.to_f * 10).to_i + when 0 then "dunno" + when 1..14 then "3.2.2" + when 15 then "3.2.4" + when 16 then "3.2.5" + when 17..20 then "4.0" + when 21 then "4.1" + when 22..30 then "4.2" + when 31 then "4.3" + when 40 then "4.4" + when 41 then "4.5" + when 42 then "4.6" + else "4.6" + end + end + end + + def provides_autotools? + version.to_f < 4.3 + end + + def provides_gcc? + version.to_f < 4.3 + end + + def default_prefix? + if version.to_f < 4.3 + %r{^/Developer} === prefix + else + %r{^/Applications/Xcode.app} === prefix + end + end +end + +module MacOS::CLT extend self + STANDALONE_PKG_ID = "com.apple.pkg.DeveloperToolsCLILeo" + FROM_XCODE_PKG_ID = "com.apple.pkg.DeveloperToolsCLI" + + # This is true ift he standard UNIX tools are present under /usr. For + # Xcode < 4.3, this is the standard location. Otherwise, it means that + # the user has installed the "Command Line Tools for Xcode" package. + def installed? + MacOS.dev_tools_path == Pathname.new("/usr/bin") + end + + def latest_version? + `/usr/bin/clang --version` =~ %r{clang-(\d+)\.(\d+)\.(\d+)} + $1.to_i >= 425 and $3.to_i >= 24 + end + + def version + # The pkgutils calls are slow, don't repeat if no CLT installed. + return @version if @version_determined + + @version_determined = true + # Version string (a pretty damn long one) of the CLT package. + # Note, that different ways to install the CLTs lead to different + # version numbers. + @version ||= [STANDALONE_PKG_ID, FROM_XCODE_PKG_ID].find do |id| + MacOS.pkgutil_info(id) =~ /version: (.+)$/ + end && $1 + end +end diff --git a/Library/Homebrew/os/mac/xquartz.rb b/Library/Homebrew/os/mac/xquartz.rb new file mode 100644 index 000000000..a515d8915 --- /dev/null +++ b/Library/Homebrew/os/mac/xquartz.rb @@ -0,0 +1,101 @@ +module MacOS::XQuartz extend self + FORGE_BUNDLE_ID = "org.macosforge.xquartz.X11" + APPLE_BUNDLE_ID = "org.x.X11" + FORGE_PKG_ID = "org.macosforge.xquartz.pkg" + + # This returns the version number of XQuartz, not of the upstream X.org. + # The X11.app distributed by Apple is also XQuartz, and therefore covered + # by this method. + def version + @version ||= begin + path = MacOS.app_with_bundle_id(FORGE_BUNDLE_ID) || MacOS.app_with_bundle_id(APPLE_BUNDLE_ID) + if not path.nil? and path.exist? + `mdls -raw -name kMDItemVersion "#{path}" 2>/dev/null`.strip + elsif prefix.to_s == "/usr/X11" + # Some users disable Spotlight indexing. If we're working with the + # system X11 distribution, we can't get the version from pkgutil, so + # just use the expected version. + case MacOS.version + when 10.5 then "2.1.6" + when 10.6 then "2.3.6" + when 10.7 then "2.6.3" + else "dunno" + end + else + # Finally, try to find it via pkgutil. This is slow, and only works + # for the upstream XQuartz package, so use it as a last resort. + MacOS.pkgutil_info(FORGE_PKG_ID) =~ /version: (\d\.\d\.\d).+$/ and $1 + end + end + end + + def latest_version + "2.7.4" + end + + def provided_by_apple? + [FORGE_BUNDLE_ID, APPLE_BUNDLE_ID].find do |id| + MacOS.app_with_bundle_id(id) + end == APPLE_BUNDLE_ID + end + + # This should really be private, but for compatibility reasons it must + # remain public. New code should use MacOS::X11.{bin,lib,include} + # instead, as that accounts for Xcode-only systems. + def prefix + @prefix ||= if Pathname.new('/opt/X11/lib/libpng.dylib').exist? + Pathname.new('/opt/X11') + elsif Pathname.new('/usr/X11/lib/libpng.dylib').exist? + Pathname.new('/usr/X11') + end + end + + def installed? + !version.nil? && !prefix.nil? + end +end + +module MacOS::X11 extend self + def prefix + MacOS::XQuartz.prefix + end + + def installed? + MacOS::XQuartz.installed? + end + + # If XQuartz and/or the CLT are installed, headers will be found under + # /opt/X11/include or /usr/X11/include. For Xcode-only systems, they are + # found in the SDK, so we use sdk_path for both the headers and libraries. + # Confusingly, executables (e.g. config scripts) are only found under + # /opt/X11/bin or /usr/X11/bin in all cases. + def bin + prefix/'bin' + end + + def include + @include ||= if use_sdk? + MacOS.sdk_path/'usr/X11/include' + else + prefix/'include' + end + end + + def lib + @lib ||= if use_sdk? + MacOS.sdk_path/'usr/X11/lib' + else + prefix/'lib' + end + end + + def share + prefix/'share' + end + + private + + def use_sdk? + not (prefix.to_s == '/opt/X11' or MacOS::CLT.installed?) + end +end diff --git a/Library/Homebrew/test/test_version_subclasses.rb b/Library/Homebrew/test/test_version_subclasses.rb index 93711ac44..6b18246ba 100644 --- a/Library/Homebrew/test/test_version_subclasses.rb +++ b/Library/Homebrew/test/test_version_subclasses.rb @@ -1,6 +1,6 @@ require 'testing_env' require 'version' -require 'macos/version' +require 'os/mac/version' class MacOSVersionTests < Test::Unit::TestCase def setup -- cgit v1.2.3