From 148617bc1164c919eda86403ce2df197b913cdde Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Wed, 25 Jul 2012 15:04:46 -0500 Subject: Move X11 machinery into MacOS::XQuartz namespace In order to better support Xcode-only systems, where X11 libs and executables live under /usr/X11 but headers live in the SDK, move the x11_* helper methods into a new module. This allows us to keep some of the CLT/Xcode-only and Apple X11/XQuartz logic hidden from outside code, like ENV.x11. Since Apple's X11 is actually XQuartz, name the module "MacOS::XQuartz". --- Library/Homebrew/cmd/--config.rb | 4 +- Library/Homebrew/cmd/doctor.rb | 2 +- Library/Homebrew/compat/compatibility.rb | 10 +- Library/Homebrew/dependencies.rb | 2 +- Library/Homebrew/extend/ENV.rb | 37 +++---- Library/Homebrew/macos.rb | 27 +----- Library/Homebrew/macos/xcode.rb | 161 +++++++++++++++++++++++++++++++ Library/Homebrew/macos/xquartz.rb | 64 ++++++++++++ Library/Homebrew/xcode.rb | 161 ------------------------------- 9 files changed, 254 insertions(+), 214 deletions(-) create mode 100644 Library/Homebrew/macos/xcode.rb create mode 100644 Library/Homebrew/macos/xquartz.rb delete mode 100644 Library/Homebrew/xcode.rb (limited to 'Library') diff --git a/Library/Homebrew/cmd/--config.rb b/Library/Homebrew/cmd/--config.rb index 3b749c5ab..d70af5f99 100644 --- a/Library/Homebrew/cmd/--config.rb +++ b/Library/Homebrew/cmd/--config.rb @@ -59,8 +59,8 @@ module Homebrew extend self end def describe_x11 - return "N/A" unless MacOS.x11_installed? - return "#{MacOS.xquartz_version} @ " + describe_path(MacOS.x11_prefix) + return "N/A" unless MacOS::XQuartz.installed? + return "#{MacOS::XQuartz.version} @ " + describe_path(MacOS::XQuartz.prefix) end def describe_perl diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb index 922c9ca70..1b723daaf 100644 --- a/Library/Homebrew/cmd/doctor.rb +++ b/Library/Homebrew/cmd/doctor.rb @@ -168,7 +168,7 @@ def check_for_stray_las end def check_for_x11 - unless MacOS.x11_installed? then <<-EOS.undent + unless MacOS::XQuartz.installed? then <<-EOS.undent X11 is not installed. You don't have X11 installed as part of your OS X installation. This is not required for all formulae, but is expected by some. diff --git a/Library/Homebrew/compat/compatibility.rb b/Library/Homebrew/compat/compatibility.rb index e14909496..a06978398 100644 --- a/Library/Homebrew/compat/compatibility.rb +++ b/Library/Homebrew/compat/compatibility.rb @@ -34,7 +34,7 @@ def llvm_build end def x11_installed? - MacOS.x11_installed? + MacOS::XQuartz.installed? end def macports_or_fink_installed? @@ -189,4 +189,12 @@ module MacOS extend self def clt_version? CLT.version end + + def x11_installed? + XQuartz.installed? + end + + def x11_prefix + XQuartz.prefix + end end diff --git a/Library/Homebrew/dependencies.rb b/Library/Homebrew/dependencies.rb index 9493c623b..5af3311d5 100644 --- a/Library/Homebrew/dependencies.rb +++ b/Library/Homebrew/dependencies.rb @@ -189,7 +189,7 @@ class X11Dependency < Requirement def fatal?; true; end def satisfied? - MacOS.x11_installed? and (@min_version == nil or @min_version <= MacOS.xquartz_version) + MacOS::XQuartz.installed? and (@min_version.nil? or @min_version <= MacOS::XQuartz.version) end def message; <<-EOS.undent diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb index 363c6d356..b6240d8e3 100644 --- a/Library/Homebrew/extend/ENV.rb +++ b/Library/Homebrew/extend/ENV.rb @@ -310,35 +310,26 @@ Please take one of the following actions: end def x11 - opoo "You do not have X11 installed, this formula may not build." unless MacOS.x11_installed? - - # There are some config scripts here that should go in the PATH. This - # path is always under MacOS.x11_prefix, even for Xcode-only systems. - prepend 'PATH', MacOS.x11_prefix/'bin', ':' - - # Similarily, pkgconfig files are only found under MacOS.x11_prefix. - prepend 'PKG_CONFIG_PATH', MacOS.x11_prefix/'lib/pkgconfig', ':' - prepend 'PKG_CONFIG_PATH', MacOS.x11_prefix/'share/pkgconfig', ':' + unless MacOS::XQuartz.installed? + opoo "You do not have X11 installed, this formula may not build." + end - append 'LDFLAGS', "-L#{MacOS.x11_prefix}/lib" - append 'CMAKE_PREFIX_PATH', MacOS.x11_prefix, ':' + # There are some config scripts here that should go in the PATH + prepend 'PATH', MacOS::XQuartz.bin, ':' - # We prefer XQuartz if it is installed. Otherwise, we look for Apple's - # X11. For Xcode-only systems, the headers are found in the SDK. - prefix = if MacOS.x11_prefix.to_s == '/opt/X11' or MacOS::CLT.installed? - MacOS.x11_prefix - else - MacOS.sdk_path/'usr/X11' - end + prepend 'PKG_CONFIG_PATH', MacOS::XQuartz.lib/'pkgconfig', ':' + prepend 'PKG_CONFIG_PATH', MacOS::XQuartz.share/'pkgconfig', ':' - append 'CPPFLAGS', "-I#{prefix}/include" + append 'LDFLAGS', "-L#{MacOS::XQuartz.lib}" + append 'CMAKE_PREFIX_PATH', MacOS::XQuartz.prefix, ':' + append 'CMAKE_INCLUDE_PATH', MacOS::XQuartz.include, ':' - append 'CMAKE_PREFIX_PATH', prefix, ':' - append 'CMAKE_INCLUDE_PATH', prefix/'include', ':' + append 'CPPFLAGS', "-I#{MacOS::XQuartz.include}" unless MacOS::CLT.installed? - append 'CPPFLAGS', "-I#{prefix}/include/freetype2" - append 'CFLAGS', "-I#{prefix}/include" + append 'CMAKE_PREFIX_PATH', MacOS.sdk_path/'usr/X11', ':' + append 'CPPFLAGS', "-I#{MacOS::XQuartz.include}/freetype2" + append 'CFLAGS', "-I#{MacOS::XQuartz.include}" end end alias_method :libpng, :x11 diff --git a/Library/Homebrew/macos.rb b/Library/Homebrew/macos.rb index 1db630619..43f9ab031 100644 --- a/Library/Homebrew/macos.rb +++ b/Library/Homebrew/macos.rb @@ -1,8 +1,6 @@ module MacOS extend self MDITEM_BUNDLE_ID_KEY = "kMDItemCFBundleIdentifier" - APPLE_X11_BUNDLE_ID = "org.x.X11" - XQUARTZ_BUNDLE_ID = "org.macosforge.xquartz.X11" def version MACOS_VERSION @@ -168,28 +166,6 @@ module MacOS extend self end end - def xquartz_version - # This returns the version number of XQuartz, not of the upstream X.org - # (which is why it is not called x11_version). Note that the X11.app - # distributed by Apple is also XQuartz, and therefore covered by this method. - path = app_with_bundle_id(XQUARTZ_BUNDLE_ID) || app_with_bundle_id(APPLE_X11_BUNDLE_ID) - version = if not path.nil? and path.exist? - `mdls -raw -name kMDItemVersion "#{path}" 2>/dev/null`.strip - end - end - - def x11_prefix - @x11_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 x11_installed? - not x11_prefix.nil? - end - def macports_or_fink_installed? # See these issues for some history: # http://github.com/mxcl/homebrew/issues/#issue/13 @@ -278,4 +254,5 @@ module MacOS extend self end end -require 'xcode' +require 'macos/xcode' +require 'macos/xquartz' diff --git a/Library/Homebrew/macos/xcode.rb b/Library/Homebrew/macos/xcode.rb new file mode 100644 index 000000000..0c8139c62 --- /dev/null +++ b/Library/Homebrew/macos/xcode.rb @@ -0,0 +1,161 @@ +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 + 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 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? + # Telling us whether the Xcode.app is installed or not. + @installed ||= V4_BUNDLE_PATH.exist? || + V3_BUNDLE_PATH.exist? || + MacOS.app_with_bundle_id(V4_BUNDLE_ID) || + MacOS.app_with_bundle_id(V3_BUNDLE_ID) || + false + 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 ||= begin + 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 + "dunno" + when 1..14 + "3.2.2" + when 15 + "3.2.4" + when 16 + "3.2.5" + when 17..20 + "4.0" + when 21 + "4.1" + when 22..30 + "4.2" + when 31 + "4.3" + when 40 + "4.4" + else + "4.4" + end + end + end + end + + def provides_autotools? + version.to_f < 4.3 + end + + def provides_gcc? + version.to_f < 4.3 + 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 version + # 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 ||= begin + standalone = MacOS.pkgutil_info(STANDALONE_PKG_ID) + from_xcode = MacOS.pkgutil_info(FROM_XCODE_PKG_ID) + + if not standalone.empty? + standalone =~ /version: (.*)$/ + $1 + elsif not from_xcode.empty? + from_xcode =~ /version: (.*)$/ + $1 + else + nil + end + end + end +end diff --git a/Library/Homebrew/macos/xquartz.rb b/Library/Homebrew/macos/xquartz.rb new file mode 100644 index 000000000..d00c55680 --- /dev/null +++ b/Library/Homebrew/macos/xquartz.rb @@ -0,0 +1,64 @@ +module MacOS::XQuartz extend self + FORGE_BUNDLE_ID = "org.macosforge.xquartz.X11" + APPLE_BUNDLE_ID = "org.x.X11" + + # 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 + path = MacOS.app_with_bundle_id(FORGE_BUNDLE_ID) || MacOS.app_with_bundle_id(APPLE_BUNDLE_ID) + version = if not path.nil? and path.exist? + `mdls -raw -name kMDItemVersion "#{path}" 2>/dev/null`.strip + end + end + + # This should really be private, but for compatibility reasons it must + # remain public. New code should use MacOS::XQuartz.{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? + not prefix.nil? + 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/xcode.rb b/Library/Homebrew/xcode.rb deleted file mode 100644 index 0c8139c62..000000000 --- a/Library/Homebrew/xcode.rb +++ /dev/null @@ -1,161 +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 - 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 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? - # Telling us whether the Xcode.app is installed or not. - @installed ||= V4_BUNDLE_PATH.exist? || - V3_BUNDLE_PATH.exist? || - MacOS.app_with_bundle_id(V4_BUNDLE_ID) || - MacOS.app_with_bundle_id(V3_BUNDLE_ID) || - false - 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 ||= begin - 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 - "dunno" - when 1..14 - "3.2.2" - when 15 - "3.2.4" - when 16 - "3.2.5" - when 17..20 - "4.0" - when 21 - "4.1" - when 22..30 - "4.2" - when 31 - "4.3" - when 40 - "4.4" - else - "4.4" - end - end - end - end - - def provides_autotools? - version.to_f < 4.3 - end - - def provides_gcc? - version.to_f < 4.3 - 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 version - # 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 ||= begin - standalone = MacOS.pkgutil_info(STANDALONE_PKG_ID) - from_xcode = MacOS.pkgutil_info(FROM_XCODE_PKG_ID) - - if not standalone.empty? - standalone =~ /version: (.*)$/ - $1 - elsif not from_xcode.empty? - from_xcode =~ /version: (.*)$/ - $1 - else - nil - end - end - end -end -- cgit v1.2.3