Merge pull request #4185 from sjackman/superenv-linux

Add superenv for Linux
This commit is contained in:
Mike McQuaid 2018-05-31 19:56:16 +01:00 committed by GitHub
commit 054866653d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 183 additions and 24 deletions

View File

@ -68,6 +68,7 @@ class Build
def install
formula_deps = deps.map(&:to_formula)
keg_only_deps = formula_deps.select(&:keg_only?)
run_time_deps = deps.reject(&:build?).map(&:to_formula)
formula_deps.each do |dep|
fixopt(dep) unless dep.opt_prefix.directory?
@ -78,6 +79,7 @@ class Build
if superenv?
ENV.keg_only_deps = keg_only_deps
ENV.deps = formula_deps
ENV.run_time_deps = run_time_deps
ENV.x11 = reqs.any? { |rq| rq.is_a?(X11Requirement) }
ENV.setup_build_environment(formula)
post_superenv_hacks

View File

@ -15,12 +15,13 @@ module Superenv
include SharedEnvExtension
# @private
attr_accessor :keg_only_deps, :deps
attr_accessor :keg_only_deps, :deps, :run_time_deps
attr_accessor :x11
def self.extended(base)
base.keg_only_deps = []
base.deps = []
base.run_time_deps = []
end
# @private
@ -178,16 +179,6 @@ module Superenv
keg_only_deps.map(&:opt_lib),
HOMEBREW_PREFIX/"lib",
]
if compiler == :llvm_clang
if MacOS::CLT.installed?
paths << "/usr/lib"
else
paths << "#{MacOS.sdk_path}/usr/lib"
end
paths << Formula["llvm"].opt_lib.to_s
end
paths += homebrew_extra_library_paths
PATH.new(paths).existing
end

View File

@ -1 +1,5 @@
require "extend/os/mac/extend/ENV/super" if OS.mac?
if OS.mac?
require "extend/os/mac/extend/ENV/super"
elsif OS.linux?
require "extend/os/linux/extend/ENV/super"
end

View File

@ -0,0 +1,40 @@
module Superenv
# @private
def self.bin
(HOMEBREW_SHIMS_PATH/"linux/super").realpath
end
# @private
def setup_build_environment(formula = nil)
generic_setup_build_environment(formula)
self["HOMEBREW_DYNAMIC_LINKER"] = determine_dynamic_linker_path
self["HOMEBREW_RPATH_PATHS"] = determine_rpath_paths(formula)
end
def homebrew_extra_paths
paths = []
paths += %w[binutils make].map do |f|
begin
bin = Formula[f].opt_bin
bin if bin.directory?
rescue FormulaUnavailableError
nil
end
end.compact
paths
end
def determine_rpath_paths(formula)
PATH.new(
formula&.lib,
"#{HOMEBREW_PREFIX}/lib",
PATH.new(run_time_deps.map { |dep| dep.opt_lib.to_s }).existing,
)
end
def determine_dynamic_linker_path
path = "#{HOMEBREW_PREFIX}/lib/ld.so"
return unless File.readable? path
path
end
end

View File

@ -58,6 +58,14 @@ module Superenv
def homebrew_extra_library_paths
paths = []
if compiler == :llvm_clang
if MacOS::CLT.installed?
paths << "/usr/lib"
else
paths << "#{MacOS.sdk_path}/usr/lib"
end
paths << Formula["llvm"].opt_lib.to_s
end
paths << MacOS::X11.lib.to_s if x11?
paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries"
paths

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
../../super/cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
../../scm/git

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
cc

View File

@ -0,0 +1 @@
../../scm/svn

View File

@ -0,0 +1 @@
cc

View File

@ -13,6 +13,14 @@ exec "$HOMEBREW_RUBY_PATH" -x "$0" "$@"
require "pathname"
require "set"
def mac?
RUBY_PLATFORM[/darwin/]
end
def linux?
RUBY_PLATFORM[/linux/]
end
class Cmd
attr_reader :config, :prefix, :cellar, :opt, :tmpdir, :sysroot, :deps
attr_reader :archflags, :optflags, :keg_regex, :formula_prefix
@ -35,8 +43,10 @@ class Cmd
end
def mode
if @arg0 == "cpp" || @arg0 == "ld"
@arg0.to_sym
if @arg0 == "cpp"
:cpp
elsif ["ld", "ld.gold", "gold"].include? @arg0
:ld
elsif @args.include? "-c"
if @arg0 =~ /(?:c|g|clang)\+\+/
:cxx
@ -59,6 +69,7 @@ class Cmd
def tool
@tool ||= case @arg0
when "ld" then "ld"
when "gold", "ld.gold" then "ld.gold"
when "cpp" then "cpp"
when /llvm_(clang(\+\+)?)/
"#{ENV["HOMEBREW_PREFIX"]}/opt/llvm/bin/#{$1}"
@ -190,9 +201,13 @@ class Cmd
when "-undefineddynamic_lookup"
args << "-Wl,-undefined,dynamic_lookup"
when /^-isysroot/, /^--sysroot/
if mac?
sdk = enum.next
# We set the sysroot for macOS SDKs
args << "-isysroot" << sdk unless sdk.downcase.include? "osx"
else
args << arg << enum.next
end
when "-dylib"
args << "-Wl,#{arg}"
when /^-I(.+)?/
@ -220,11 +235,15 @@ class Cmd
elsif path.start_with?(cellar) || path.start_with?(opt)
dep = path[keg_regex, 2]
dep && @deps.include?(dep)
elsif path.start_with?(prefix)
elsif path.start_with?(prefix, tmpdir)
true
elsif path.start_with?("/opt/local", "/opt/boxen/homebrew", "/opt/X11", "/sw", "/usr/X11")
# ignore MacPorts, Boxen's Homebrew, X11, fink
false
elsif mac?
true
else
# ignore MacPorts, Boxen's Homebrew, X11, fink
!path.start_with?("/opt/local", "/opt/boxen/homebrew", "/opt/X11", "/sw", "/usr/X11")
false
end
end
@ -254,8 +273,7 @@ class Cmd
path_flags("-isystem", isystem_paths) + path_flags("-I", include_paths)
end
def ldflags
args = path_flags("-L", library_paths)
def ldflags_mac(args)
case mode
when :ld
args << "-headerpad_max_install_names"
@ -267,6 +285,27 @@ class Cmd
args
end
def ldflags_linux(args)
unless mode == :ld
wl = "-Wl,"
args << "-B#{@opt}/glibc/lib"
end
args += rpath_flags("#{wl}-rpath=", rpath_paths)
args += ["#{wl}--dynamic-linker=#{dynamic_linker_path}"] if dynamic_linker_path
args
end
def ldflags
args = path_flags("-L", library_paths)
if mac?
ldflags_mac(args)
elsif linux?
ldflags_linux(args)
else
args
end
end
def isystem_paths
path_split("HOMEBREW_ISYSTEM_PATHS")
end
@ -279,6 +318,14 @@ class Cmd
path_split("HOMEBREW_LIBRARY_PATHS")
end
def rpath_paths
path_split("HOMEBREW_RPATH_PATHS")
end
def dynamic_linker_path
chuzzle(ENV["HOMEBREW_DYNAMIC_LINKER"])
end
def system_library_paths
paths = ["#{sysroot}/usr/lib"]
paths << "/usr/local/lib" unless sysroot || ENV["SDKROOT"]
@ -325,6 +372,12 @@ class Cmd
paths.map! { |path| prefix + path }
end
# Unlike path_flags, do not prune non-existant directories.
# formula.lib for example does not yet exist, but should not be pruned.
def rpath_flags(prefix, paths)
paths.uniq.map { |path| prefix + path }
end
def path_split(key)
ENV.fetch(key) { "" }.split(File::PATH_SEPARATOR)
end
@ -350,6 +403,14 @@ def log(basename, argv, tool, args)
File.open("#{ENV["HOMEBREW_CC_LOG_PATH"]}.cc", "a+") { |f| f.write(s) }
end
def remove_superbin_from_path(paths)
superbin = Pathname.new(__FILE__).dirname.realpath
paths.reject do |x|
path = Pathname.new(x)
path.directory? && path.realpath == superbin
end
end
if __FILE__ == $PROGRAM_NAME
##################################################################### sanity
@ -369,5 +430,13 @@ if __FILE__ == $PROGRAM_NAME
log(basename, ARGV, tool, args)
args << { :close_others => false }
if mac?
exec "#{dirname}/xcrun", tool, *args
else
paths = ENV["PATH"].split(":")
paths = remove_superbin_from_path(paths)
paths.unshift "#{ENV["HOMEBREW_PREFIX"]}/bin"
ENV["PATH"] = paths.join(":")
exec tool, *args
end
end

View File

@ -177,7 +177,7 @@ describe "brew install", :integration_test do
it "succeeds when a non-fatal requirement isn't satisfied" do
setup_test_formula "testball1", <<~EOS
class NonFatalRequirement < Requirement
satisfy { false }
satisfy(build_env: false) { false }
end
depends_on NonFatalRequirement