From 4fd5c5c159c0f8d2f848524e98d4cc938e2207e8 Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Thu, 24 Mar 2016 11:18:30 -0700 Subject: 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. --- Library/ENV/4.3/cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'Library/ENV') 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 -- cgit v1.2.3