aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMisty De Meo2016-03-24 11:18:30 -0700
committerMisty De Meo2016-04-04 15:30:22 -0700
commit4fd5c5c159c0f8d2f848524e98d4cc938e2207e8 (patch)
treed0275f9243e26782756b3995ce8641020a847705 /Library
parentfa3c55aa650e815ce548e1276845171def2847f4 (diff)
downloadbrew-4fd5c5c159c0f8d2f848524e98d4cc938e2207e8.tar.bz2
superenv: filter -I/-L paths on dependencies
Previously, superenv did not try to filter -I or -L flags based on the list of requested dependencies; as a result, buildsystems which opportunistically discover Homebrew-installed libraries were able to link against them even under superenv. This adds a list of all requested dependencies to the superenv environment, and compares all -I and -L flags against those; any Cellar and opt paths found which resolve to unrequested dependencies are filtered out.
Diffstat (limited to 'Library')
-rwxr-xr-xLibrary/ENV/4.3/cc19
-rw-r--r--Library/Homebrew/extend/ENV/super.rb6
2 files changed, 22 insertions, 3 deletions
diff --git a/Library/ENV/4.3/cc b/Library/ENV/4.3/cc
index 0d07db00f..28c78b4f5 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 747a76956..ca244849f 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