Pull common stdlib checking code into a method

This commit is contained in:
Jack Nagel 2014-08-22 22:18:03 -05:00
parent f936b33279
commit 3d26b75847
3 changed files with 27 additions and 35 deletions

View File

@ -182,25 +182,11 @@ class Build
def detect_stdlibs
keg = Keg.new(f.prefix)
# This first test includes executables because we still
# want to record the stdlib for something that installs no
# dylibs.
stdlibs = keg.detect_cxx_stdlibs
# This currently only tracks a single C++ stdlib per dep,
# though it's possible for different libs/executables in
# a given formula to link to different ones.
stdlib_in_use = CxxStdlib.create(stdlibs.first, ENV.compiler)
begin
stdlib_in_use.check_dependencies(f, deps)
rescue IncompatibleCxxStdlibs => e
opoo e.message
end
CxxStdlib.check_compatibility(f, deps, keg, ENV.compiler)
# This second check is recorded for checking dependencies,
# so executable are irrelevant at this point. If a piece
# of software installs an executable that links against libstdc++
# and dylibs against libc++, libc++-only dependencies can safely
# link against it.
# The stdlib recorded in the install receipt is used during dependency
# compatibility checks, so we only care about the stdlib that libraries
# link against.
keg.detect_cxx_stdlibs(:skip_executables => true)
end

View File

@ -11,6 +11,18 @@ class CxxStdlib
klass.new(type, compiler)
end
def self.check_compatibility(formula, deps, keg, compiler)
return if formula.skip_cxxstdlib_check?
stdlib = create(keg.detect_cxx_stdlibs.first, compiler)
begin
stdlib.check_dependencies(formula, deps)
rescue IncompatibleCxxStdlibs => e
opoo e.message
end
end
attr_reader :type, :compiler
def initialize(type, compiler)
@ -32,17 +44,14 @@ class CxxStdlib
end
def check_dependencies(formula, deps)
unless formula.skip_cxxstdlib_check?
deps.each do |dep|
# Software is unlikely to link against anything from its
# buildtime deps, so it doesn't matter at all if they link
# against different C++ stdlibs
next if dep.build?
deps.each do |dep|
# Software is unlikely to link against libraries from build-time deps, so
# it doesn't matter if they link against different C++ stdlibs.
next if dep.build?
dep_stdlib = Tab.for_formula(dep.to_formula).cxxstdlib
if !compatible_with? dep_stdlib
raise IncompatibleCxxStdlibs.new(formula, dep, dep_stdlib, self)
end
dep_stdlib = Tab.for_formula(dep.to_formula).cxxstdlib
if !compatible_with? dep_stdlib
raise IncompatibleCxxStdlibs.new(formula, dep, dep_stdlib, self)
end
end
end

View File

@ -158,13 +158,10 @@ class FormulaInstaller
pour
@poured_bottle = true
stdlibs = Keg.new(f.prefix).detect_cxx_stdlibs
stdlib_in_use = CxxStdlib.create(stdlibs.first, MacOS.default_compiler)
begin
stdlib_in_use.check_dependencies(f, f.recursive_dependencies)
rescue IncompatibleCxxStdlibs => e
opoo e.message
end
CxxStdlib.check_compatibility(
f, f.recursive_dependencies,
Keg.new(f.prefix), MacOS.default_compiler
)
tab = Tab.for_keg f.prefix
tab.poured_from_bottle = true