diff --git a/Library/ENV/4.3/cc b/Library/ENV/4.3/cc index 0d07db00f6..28c78b4f53 100755 --- a/Library/ENV/4.3/cc +++ b/Library/ENV/4.3/cc @@ -14,8 +14,8 @@ require "pathname" require "set" class Cmd - attr_reader :config, :prefix, :cellar, :tmpdir, :sysroot - attr_reader :archflags, :optflags + attr_reader :config, :prefix, :cellar, :opt, :tmpdir, :sysroot, :deps + attr_reader :archflags, :optflags, :keg_regex def initialize(arg0, args) @arg0 = arg0 @@ -23,10 +23,14 @@ class Cmd @config = ENV.fetch("HOMEBREW_CCCFG") { "" } @prefix = ENV["HOMEBREW_PREFIX"] @cellar = ENV["HOMEBREW_CELLAR"] + @opt = ENV["HOMEBREW_OPT"] @tmpdir = ENV["HOMEBREW_TEMP"] @sysroot = ENV["HOMEBREW_SDKROOT"] @archflags = ENV.fetch("HOMEBREW_ARCHFLAGS") { "" }.split(" ") @optflags = ENV.fetch("HOMEBREW_OPTFLAGS") { "" }.split(" ") + @deps = Set.new(ENV.fetch("HOMEBREW_DEPENDENCIES") { "" }.split(",")) + # matches opt or cellar prefix and formula name + @keg_regex = %r[(#{Regexp.escape(opt)}|#{Regexp.escape(cellar)})/([\w\-_\+]+)] end def mode @@ -197,7 +201,16 @@ class Cmd end def keep?(path) - path.start_with?(prefix, cellar, tmpdir) || !path.start_with?("/opt", "/sw", "/usr/X11") + # first two paths: reject references to Cellar or opt paths + # for unspecified dependencies + if path.start_with?(cellar) || path.start_with?(opt) + dep = path[keg_regex, 2] + dep && @deps.include?(dep) + elsif path.start_with?(prefix) + true + else + !path.start_with?("/opt", "/sw", "/usr/X11") + end end def cflags diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 747a76956b..ca244849f3 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -53,6 +53,7 @@ module Superenv self["HOMEBREW_BREW_FILE"] = HOMEBREW_BREW_FILE.to_s self["HOMEBREW_PREFIX"] = HOMEBREW_PREFIX.to_s 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 @@ -66,6 +67,7 @@ module Superenv self["HOMEBREW_ISYSTEM_PATHS"] = determine_isystem_paths self["HOMEBREW_INCLUDE_PATHS"] = determine_include_paths self["HOMEBREW_LIBRARY_PATHS"] = determine_library_paths + self["HOMEBREW_DEPENDENCIES"] = determine_dependencies if MacOS::Xcode.without_clt? || (MacOS::Xcode.installed? && MacOS::Xcode.version.to_i >= 7) self["MACOSX_DEPLOYMENT_TARGET"] = MacOS.version.to_s @@ -184,6 +186,10 @@ module Superenv paths.to_path_s end + def determine_dependencies + deps.map {|d| d.name}.join(",") + end + def determine_cmake_prefix_path paths = keg_only_deps.map { |d| d.opt_prefix.to_s } paths << HOMEBREW_PREFIX.to_s