Skip to content

Commit

Permalink
superenv: port to generic OS. (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcQuaid committed Jul 12, 2016
1 parent 498e81c commit 0d189fa
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/sh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def sh
ENV.activate_extensions!

if superenv?
ENV.x11 = MacOS::X11.installed?
ENV.set_x11_env_if_installed
ENV.deps = Formula.installed.select { |f| f.keg_only? && f.opt_prefix.directory? }
end
ENV.setup_build_environment
Expand Down
110 changes: 58 additions & 52 deletions Library/Homebrew/extend/ENV/super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def self.extended(base)

# @private
def self.bin
return unless DevelopmentTools.installed?

bin = HOMEBREW_ENV_PATH.subdirs.reject { |d| d.basename.to_s > MacOS::Xcode.version }.max
bin.realpath unless bin.nil?
end

def reset
Expand All @@ -56,7 +52,6 @@ def setup_build_environment(formula = nil)
self["HOMEBREW_CELLAR"] = HOMEBREW_CELLAR.to_s
self["HOMEBREW_OPT"] = "#{HOMEBREW_PREFIX}/opt"
self["HOMEBREW_TEMP"] = HOMEBREW_TEMP.to_s
self["HOMEBREW_SDKROOT"] = effective_sysroot
self["HOMEBREW_OPTFLAGS"] = determine_optflags
self["HOMEBREW_ARCHFLAGS"] = ""
self["CMAKE_PREFIX_PATH"] = determine_cmake_prefix_path
Expand All @@ -73,15 +68,6 @@ def setup_build_environment(formula = nil)
self["HOMEBREW_FORMULA_PREFIX"] = formula.prefix
end

if MacOS::Xcode.without_clt? || (MacOS::Xcode.installed? && MacOS::Xcode.version.to_i >= 7)
self["MACOSX_DEPLOYMENT_TARGET"] = MacOS.version.to_s
self["SDKROOT"] = MacOS.sdk_path
end

# On 10.9, the tools in /usr/bin proxy to the active developer directory.
# This means we can use them for any combination of CLT and Xcode.
self["HOMEBREW_PREFER_CLT_PROXIES"] = "1" if MacOS.version >= "10.9"

# The HOMEBREW_CCCFG ENV variable is used by the ENV/cc tool to control
# compiler flag stripping. It consists of a string of characters which act
# as flags. Some of these flags are mutually exclusive.
Expand All @@ -97,6 +83,7 @@ def setup_build_environment(formula = nil)
# s - apply fix for sed's Unicode support
# a - apply fix for apr-1-config path
end
alias_method :generic_setup_build_environment, :setup_build_environment

private

Expand All @@ -109,27 +96,23 @@ def cxx=(val)
end

def effective_sysroot
MacOS::Xcode.without_clt? ? MacOS.sdk_path.to_s : nil
end

def determine_cxx
determine_cc.to_s.gsub("gcc", "g++").gsub("clang", "clang++")
end

def homebrew_extra_paths
[]
end

def determine_path
paths = [Superenv.bin]

# Formula dependencies can override standard tools.
paths += deps.map { |d| d.opt_bin.to_s }

# On 10.9, there are shims for all tools in /usr/bin.
# On 10.7 and 10.8 we need to add these directories ourselves.
if MacOS::Xcode.without_clt? && MacOS.version <= "10.8"
paths << "#{MacOS::Xcode.prefix}/usr/bin"
paths << "#{MacOS::Xcode.toolchain_path}/usr/bin"
end

paths << MacOS::X11.bin.to_s if x11?
paths += homebrew_extra_paths
paths += %w[/usr/bin /bin /usr/sbin /sbin]

# Homebrew's apple-gcc42 will be outside the PATH in superenv,
Expand All @@ -149,44 +132,54 @@ def determine_path
paths.to_path_s
end

def homebrew_extra_pkg_config_paths
[]
end

def determine_pkg_config_path
paths = deps.map { |d| "#{d.opt_lib}/pkgconfig" }
paths += deps.map { |d| "#{d.opt_share}/pkgconfig" }
paths.to_path_s
end

def determine_pkg_config_libdir
paths = %W[/usr/lib/pkgconfig #{HOMEBREW_ENV_PATH}/pkgconfig/#{MacOS.version}]
paths << "#{MacOS::X11.lib}/pkgconfig" << "#{MacOS::X11.share}/pkgconfig" if x11?
paths = %W[/usr/lib/pkgconfig]
paths += homebrew_extra_pkg_config_paths
paths.to_path_s
end

def homebrew_extra_aclocal_paths
[]
end

def determine_aclocal_path
paths = keg_only_deps.map { |d| "#{d.opt_share}/aclocal" }
paths << "#{HOMEBREW_PREFIX}/share/aclocal"
paths << "#{MacOS::X11.share}/aclocal" if x11?
paths += homebrew_extra_aclocal_paths
paths.to_path_s
end

def homebrew_extra_isystem_paths
[]
end

def determine_isystem_paths
paths = []
paths << "#{HOMEBREW_PREFIX}/include"
paths << "#{effective_sysroot}/usr/include/libxml2" unless deps.any? { |d| d.name == "libxml2" }
paths << "#{effective_sysroot}/usr/include/apache2" if MacOS::Xcode.without_clt?
paths << MacOS::X11.include.to_s << "#{MacOS::X11.include}/freetype2" if x11?
paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers"
paths = ["#{HOMEBREW_PREFIX}/include"]
paths += homebrew_extra_isystem_paths
paths.to_path_s
end

def determine_include_paths
keg_only_deps.map { |d| d.opt_include.to_s }.to_path_s
end

def homebrew_extra_library_paths
[]
end

def determine_library_paths
paths = keg_only_deps.map { |d| d.opt_lib.to_s }
paths << "#{HOMEBREW_PREFIX}/lib"
paths << MacOS::X11.lib.to_s if x11?
paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries"
paths += homebrew_extra_library_paths
paths.to_path_s
end

Expand All @@ -200,25 +193,34 @@ def determine_cmake_prefix_path
paths.to_path_s
end

def homebrew_extra_cmake_include_paths
[]
end

def determine_cmake_include_path
paths = []
paths << "#{effective_sysroot}/usr/include/libxml2" unless deps.any? { |d| d.name == "libxml2" }
paths << "#{effective_sysroot}/usr/include/apache2" if MacOS::Xcode.without_clt?
paths << MacOS::X11.include.to_s << "#{MacOS::X11.include}/freetype2" if x11?
paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers"
paths += homebrew_extra_cmake_include_paths
paths.to_path_s
end

def homebrew_extra_cmake_library_paths
[]
end

def determine_cmake_library_path
paths = []
paths << MacOS::X11.lib.to_s if x11?
paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries"
paths += homebrew_extra_cmake_library_paths
paths.to_path_s
end

def homebrew_extra_cmake_frameworks_paths
[]
end

def determine_cmake_frameworks_path
paths = deps.map { |d| d.opt_frameworks.to_s }
paths << "#{effective_sysroot}/System/Library/Frameworks" if MacOS::Xcode.without_clt?
paths += homebrew_extra_cmake_frameworks_paths
paths.to_path_s
end

Expand All @@ -245,12 +247,7 @@ def determine_optflags
end

def determine_cccfg
s = ""
# Fix issue with sed barfing on unicode characters on Mountain Lion
s << "s" if MacOS.version >= :mountain_lion
# Fix issue with >= 10.8 apr-1-config having broken paths
s << "a" if MacOS.version >= :mountain_lion
s
""
end

public
Expand Down Expand Up @@ -333,23 +330,32 @@ def refurbish_args
end
end

def set_x11_env_if_installed
end

# @private
def noop(*_args); end
noops = []

# These methods are no longer necessary under superenv, but are needed to
# maintain an interface compatible with stdenv.
noops.concat %w[fast O4 Og libxml2 set_cpu_flags macosxsdk remove_macosxsdk]
alias_method :fast, :noop
alias_method :O4, :noop
alias_method :Og, :noop
alias_method :libxml2, :noop
alias_method :set_cpu_flags, :noop

# These methods provide functionality that has not yet been ported to
# superenv.
noops.concat %w[gcc_4_0_1 minimal_optimization no_optimization enable_warnings]

noops.each { |m| alias_method m, :noop }
alias_method :gcc_4_0_1, :noop
alias_method :minimal_optimization, :noop
alias_method :no_optimization, :noop
alias_method :enable_warnings, :noop
end

class Array
def to_path_s
map(&:to_s).uniq.select { |s| File.directory? s }.join(File::PATH_SEPARATOR).chuzzle
end
end

require "extend/os/extend/ENV/super"
5 changes: 5 additions & 0 deletions Library/Homebrew/extend/os/extend/ENV/super.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "extend/ENV/super"

if OS.mac?
require "extend/os/mac/extend/ENV/super"
end
105 changes: 105 additions & 0 deletions Library/Homebrew/extend/os/mac/extend/ENV/super.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
module Superenv
# @private
def self.bin
return unless DevelopmentTools.installed?

bin = HOMEBREW_ENV_PATH.subdirs.reject { |d| d.basename.to_s > MacOS::Xcode.version }.max
bin.realpath unless bin.nil?
end

def homebrew_extra_paths
paths = []
# On 10.9, there are shims for all tools in /usr/bin.
# On 10.7 and 10.8 we need to add these directories ourselves.
if MacOS::Xcode.without_clt? && MacOS.version <= "10.8"
paths << "#{MacOS::Xcode.prefix}/usr/bin"
paths << "#{MacOS::Xcode.toolchain_path}/usr/bin"
end

paths << MacOS::X11.bin.to_s if x11?
paths
end

# @private
def homebrew_extra_pkg_config_paths
paths = ["#{HOMEBREW_ENV_PATH}/pkgconfig/#{MacOS.version}"]
paths << "#{MacOS::X11.lib}/pkgconfig" << "#{MacOS::X11.share}/pkgconfig" if x11?
paths
end

def homebrew_extra_aclocal_paths
paths = []
paths << "#{MacOS::X11.share}/aclocal" if x11?
paths
end

def homebrew_extra_isystem_paths
paths = []
paths << "#{effective_sysroot}/usr/include/libxml2" unless deps.any? { |d| d.name == "libxml2" }
paths << "#{effective_sysroot}/usr/include/apache2" if MacOS::Xcode.without_clt?
paths << MacOS::X11.include.to_s << "#{MacOS::X11.include}/freetype2" if x11?
paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers"
paths
end

def homebrew_extra_library_paths
paths = []
paths << MacOS::X11.lib.to_s if x11?
paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries"
paths
end

def homebrew_extra_cmake_include_paths
paths = []
paths << "#{effective_sysroot}/usr/include/apache2" if MacOS::Xcode.without_clt?
paths << MacOS::X11.include.to_s << "#{MacOS::X11.include}/freetype2" if x11?
paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers"
paths
end

def homebrew_extra_cmake_library_paths
paths = []
paths << MacOS::X11.lib.to_s if x11?
paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries"
paths
end

def homebrew_extra_cmake_frameworks_paths
paths = []
paths << "#{effective_sysroot}/System/Library/Frameworks" if MacOS::Xcode.without_clt?
paths
end

def determine_cccfg
s = ""
# Fix issue with sed barfing on unicode characters on Mountain Lion
s << "s" if MacOS.version >= :mountain_lion
# Fix issue with >= 10.8 apr-1-config having broken paths
s << "a" if MacOS.version >= :mountain_lion
s
end

# @private
def setup_build_environment(formula = nil)
generic_setup_build_environment(formula)
self["HOMEBREW_SDKROOT"] = effective_sysroot

if MacOS::Xcode.without_clt? || (MacOS::Xcode.installed? && MacOS::Xcode.version.to_i >= 7)
self["MACOSX_DEPLOYMENT_TARGET"] = MacOS.version.to_s
self["SDKROOT"] = MacOS.sdk_path
end

# On 10.9, the tools in /usr/bin proxy to the active developer directory.
# This means we can use them for any combination of CLT and Xcode.
self["HOMEBREW_PREFER_CLT_PROXIES"] = "1" if MacOS.version >= "10.9"
end

def set_x11_env_if_installed
ENV.x11 = MacOS::X11.installed?
end

# These methods are no longer necessary under superenv, but are needed to
# maintain an interface compatible with stdenv.
alias_method :macosxsdk, :noop
alias_method :remove_macosxsdk, :noop
end

0 comments on commit 0d189fa

Please sign in to comment.