From 148617bc1164c919eda86403ce2df197b913cdde Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Wed, 25 Jul 2012 15:04:46 -0500 Subject: [PATCH] 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 | 39 ++++++--------- Library/Homebrew/macos.rb | 27 +--------- Library/Homebrew/{ => macos}/xcode.rb | 0 Library/Homebrew/macos/xquartz.rb | 64 ++++++++++++++++++++++++ 8 files changed, 94 insertions(+), 54 deletions(-) rename Library/Homebrew/{ => macos}/xcode.rb (100%) create mode 100644 Library/Homebrew/macos/xquartz.rb diff --git a/Library/Homebrew/cmd/--config.rb b/Library/Homebrew/cmd/--config.rb index 3b749c5abd..d70af5f996 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 922c9ca700..1b723daaf4 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 e14909496c..a069783980 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 9493c623be..5af3311d58 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 363c6d3566..b6240d8e37 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', ':' - - append 'LDFLAGS', "-L#{MacOS.x11_prefix}/lib" - append 'CMAKE_PREFIX_PATH', MacOS.x11_prefix, ':' - - # 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' + unless MacOS::XQuartz.installed? + opoo "You do not have X11 installed, this formula may not build." end - append 'CPPFLAGS', "-I#{prefix}/include" + # There are some config scripts here that should go in the PATH + prepend 'PATH', MacOS::XQuartz.bin, ':' - append 'CMAKE_PREFIX_PATH', prefix, ':' - append 'CMAKE_INCLUDE_PATH', prefix/'include', ':' + prepend 'PKG_CONFIG_PATH', MacOS::XQuartz.lib/'pkgconfig', ':' + prepend 'PKG_CONFIG_PATH', MacOS::XQuartz.share/'pkgconfig', ':' + + append 'LDFLAGS', "-L#{MacOS::XQuartz.lib}" + append 'CMAKE_PREFIX_PATH', MacOS::XQuartz.prefix, ':' + append 'CMAKE_INCLUDE_PATH', MacOS::XQuartz.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 1db630619d..43f9ab0311 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/xcode.rb b/Library/Homebrew/macos/xcode.rb similarity index 100% rename from Library/Homebrew/xcode.rb rename to Library/Homebrew/macos/xcode.rb diff --git a/Library/Homebrew/macos/xquartz.rb b/Library/Homebrew/macos/xquartz.rb new file mode 100644 index 0000000000..d00c556800 --- /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