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.
This commit is contained in:
parent
fa3c55aa65
commit
4fd5c5c159
@ -14,8 +14,8 @@ require "pathname"
|
|||||||
require "set"
|
require "set"
|
||||||
|
|
||||||
class Cmd
|
class Cmd
|
||||||
attr_reader :config, :prefix, :cellar, :tmpdir, :sysroot
|
attr_reader :config, :prefix, :cellar, :opt, :tmpdir, :sysroot, :deps
|
||||||
attr_reader :archflags, :optflags
|
attr_reader :archflags, :optflags, :keg_regex
|
||||||
|
|
||||||
def initialize(arg0, args)
|
def initialize(arg0, args)
|
||||||
@arg0 = arg0
|
@arg0 = arg0
|
||||||
@ -23,10 +23,14 @@ class Cmd
|
|||||||
@config = ENV.fetch("HOMEBREW_CCCFG") { "" }
|
@config = ENV.fetch("HOMEBREW_CCCFG") { "" }
|
||||||
@prefix = ENV["HOMEBREW_PREFIX"]
|
@prefix = ENV["HOMEBREW_PREFIX"]
|
||||||
@cellar = ENV["HOMEBREW_CELLAR"]
|
@cellar = ENV["HOMEBREW_CELLAR"]
|
||||||
|
@opt = ENV["HOMEBREW_OPT"]
|
||||||
@tmpdir = ENV["HOMEBREW_TEMP"]
|
@tmpdir = ENV["HOMEBREW_TEMP"]
|
||||||
@sysroot = ENV["HOMEBREW_SDKROOT"]
|
@sysroot = ENV["HOMEBREW_SDKROOT"]
|
||||||
@archflags = ENV.fetch("HOMEBREW_ARCHFLAGS") { "" }.split(" ")
|
@archflags = ENV.fetch("HOMEBREW_ARCHFLAGS") { "" }.split(" ")
|
||||||
@optflags = ENV.fetch("HOMEBREW_OPTFLAGS") { "" }.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
|
end
|
||||||
|
|
||||||
def mode
|
def mode
|
||||||
@ -197,7 +201,16 @@ class Cmd
|
|||||||
end
|
end
|
||||||
|
|
||||||
def keep?(path)
|
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
|
end
|
||||||
|
|
||||||
def cflags
|
def cflags
|
||||||
|
|||||||
@ -53,6 +53,7 @@ module Superenv
|
|||||||
self["HOMEBREW_BREW_FILE"] = HOMEBREW_BREW_FILE.to_s
|
self["HOMEBREW_BREW_FILE"] = HOMEBREW_BREW_FILE.to_s
|
||||||
self["HOMEBREW_PREFIX"] = HOMEBREW_PREFIX.to_s
|
self["HOMEBREW_PREFIX"] = HOMEBREW_PREFIX.to_s
|
||||||
self["HOMEBREW_CELLAR"] = HOMEBREW_CELLAR.to_s
|
self["HOMEBREW_CELLAR"] = HOMEBREW_CELLAR.to_s
|
||||||
|
self["HOMEBREW_OPT"] = "#{HOMEBREW_PREFIX}/opt"
|
||||||
self["HOMEBREW_TEMP"] = HOMEBREW_TEMP.to_s
|
self["HOMEBREW_TEMP"] = HOMEBREW_TEMP.to_s
|
||||||
self["HOMEBREW_SDKROOT"] = effective_sysroot
|
self["HOMEBREW_SDKROOT"] = effective_sysroot
|
||||||
self["HOMEBREW_OPTFLAGS"] = determine_optflags
|
self["HOMEBREW_OPTFLAGS"] = determine_optflags
|
||||||
@ -66,6 +67,7 @@ module Superenv
|
|||||||
self["HOMEBREW_ISYSTEM_PATHS"] = determine_isystem_paths
|
self["HOMEBREW_ISYSTEM_PATHS"] = determine_isystem_paths
|
||||||
self["HOMEBREW_INCLUDE_PATHS"] = determine_include_paths
|
self["HOMEBREW_INCLUDE_PATHS"] = determine_include_paths
|
||||||
self["HOMEBREW_LIBRARY_PATHS"] = determine_library_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)
|
if MacOS::Xcode.without_clt? || (MacOS::Xcode.installed? && MacOS::Xcode.version.to_i >= 7)
|
||||||
self["MACOSX_DEPLOYMENT_TARGET"] = MacOS.version.to_s
|
self["MACOSX_DEPLOYMENT_TARGET"] = MacOS.version.to_s
|
||||||
@ -184,6 +186,10 @@ module Superenv
|
|||||||
paths.to_path_s
|
paths.to_path_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def determine_dependencies
|
||||||
|
deps.map {|d| d.name}.join(",")
|
||||||
|
end
|
||||||
|
|
||||||
def determine_cmake_prefix_path
|
def determine_cmake_prefix_path
|
||||||
paths = keg_only_deps.map { |d| d.opt_prefix.to_s }
|
paths = keg_only_deps.map { |d| d.opt_prefix.to_s }
|
||||||
paths << HOMEBREW_PREFIX.to_s
|
paths << HOMEBREW_PREFIX.to_s
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user