Merge pull request #1279 from MikeMcQuaid/use-tar-xz

Use BSD tar's libarchive LZMA support if available
This commit is contained in:
Mike McQuaid 2016-10-15 13:37:35 +01:00 committed by GitHub
commit 527a62b64b
7 changed files with 59 additions and 21 deletions

View File

@ -61,6 +61,10 @@ class DependencyCollector
parse_spec(spec, Array(tags)) parse_spec(spec, Array(tags))
end end
def self.tar_needs_xz_dependency?
!new.xz_dep([]).nil?
end
private private
def parse_spec(spec, tags) def parse_spec(spec, tags)
@ -113,7 +117,7 @@ class DependencyCollector
when :osxfuse then OsxfuseRequirement.new(tags) when :osxfuse then OsxfuseRequirement.new(tags)
when :perl then PerlRequirement.new(tags) when :perl then PerlRequirement.new(tags)
when :tuntap then TuntapRequirement.new(tags) when :tuntap then TuntapRequirement.new(tags)
when :ant then ant_dep(spec, tags) when :ant then ant_dep(tags)
when :emacs then EmacsRequirement.new(tags) when :emacs then EmacsRequirement.new(tags)
# Tiger's ld is too old to properly link some software # Tiger's ld is too old to properly link some software
when :ld64 then LD64Dependency.new if MacOS.version < :leopard when :ld64 then LD64Dependency.new if MacOS.version < :leopard
@ -134,8 +138,12 @@ class DependencyCollector
spec.new(tags) spec.new(tags)
end end
def ant_dep(spec, tags) def ant_dep(tags)
Dependency.new(spec.to_s, tags) Dependency.new("ant", tags)
end
def xz_dep(tags)
Dependency.new("xz", tags)
end end
def resource_dep(spec, tags) def resource_dep(spec, tags)
@ -164,7 +172,7 @@ class DependencyCollector
def parse_url_spec(url, tags) def parse_url_spec(url, tags)
case File.extname(url) case File.extname(url)
when ".xz" then Dependency.new("xz", tags) when ".xz" then xz_dep(tags)
when ".lha", ".lzh" then Dependency.new("lha", tags) when ".lha", ".lzh" then Dependency.new("lha", tags)
when ".lz" then Dependency.new("lzip", tags) when ".lz" then Dependency.new("lzip", tags)
when ".rar" then Dependency.new("unrar", tags) when ".rar" then Dependency.new("unrar", tags)

View File

@ -88,6 +88,10 @@ class DevelopmentTools
@clang_version = @clang_build_version = nil @clang_version = @clang_build_version = nil
@non_apple_gcc_version = {} @non_apple_gcc_version = {}
end end
def tar_supports_xz?
false
end
end end
end end

View File

@ -222,7 +222,7 @@ end
class AbstractFileDownloadStrategy < AbstractDownloadStrategy class AbstractFileDownloadStrategy < AbstractDownloadStrategy
def stage def stage
case cached_location.compression_type case type = cached_location.compression_type
when :zip when :zip
with_system_path { quiet_safe_system "unzip", "-qq", cached_location } with_system_path { quiet_safe_system "unzip", "-qq", cached_location }
chdir chdir
@ -230,19 +230,23 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
with_system_path { buffered_write("gunzip") } with_system_path { buffered_write("gunzip") }
when :bzip2_only when :bzip2_only
with_system_path { buffered_write("bunzip2") } with_system_path { buffered_write("bunzip2") }
when :gzip, :bzip2, :compress, :tar when :gzip, :bzip2, :xz, :compress, :tar
tar_flags = "x" tar_flags = "x"
# Older versions of tar require an explicit format flag if type == :gzip
if cached_location.compression_type == :gzip
tar_flags << "z" tar_flags << "z"
elsif cached_location.compression_type == :bzip2 elsif type == :bzip2
tar_flags << "j" tar_flags << "j"
elsif type == :xz
tar_flags << "J"
end end
tar_flags << "f" tar_flags << "f"
with_system_path { safe_system "tar", tar_flags, cached_location } with_system_path do
chdir if type == :xz && DependencyCollector.tar_needs_xz_dependency?
when :xz pipe_to_tar(xzpath)
with_system_path { pipe_to_tar(xzpath) } else
safe_system "tar", tar_flags, cached_location
end
end
chdir chdir
when :lzip when :lzip
with_system_path { pipe_to_tar(lzippath) } with_system_path { pipe_to_tar(lzippath) }

View File

@ -1,6 +1,11 @@
class DependencyCollector class DependencyCollector
def ant_dep(spec, tags) def ant_dep(tags)
return if MacOS.version < :mavericks return if MacOS.version < :mavericks
Dependency.new(spec.to_s, tags) Dependency.new("ant", tags)
end
def xz_dep(tags)
return if MacOS.version >= :lion
Dependency.new("xz", tags)
end end
end end

View File

@ -76,5 +76,9 @@ class DevelopmentTools
end end
end end
end end
def tar_supports_xz?
false
end
end end
end end

View File

@ -114,12 +114,6 @@ class DependencyCollectorTests < Homebrew::TestCase
assert_nil @d.add(resource) assert_nil @d.add(resource)
end end
def test_resource_dep_xz_url
resource = Resource.new
resource.url("http://example.com/foo.tar.xz")
assert_equal Dependency.new("xz", [:build]), @d.add(resource)
end
def test_resource_dep_lz_url def test_resource_dep_lz_url
resource = Resource.new resource = Resource.new
resource.url("http://example.com/foo.lz") resource.url("http://example.com/foo.lz")

View File

@ -14,6 +14,11 @@ class OSMacDependencyCollectorTests < Homebrew::TestCase
DependencyCollector.clear_cache DependencyCollector.clear_cache
end end
def test_tar_needs_xz_dependency
MacOS.stubs(:version).returns(MacOS::Version.new("10.7"))
refute DependencyCollector.tar_needs_xz_dependency?
end
def test_ld64_dep_pre_leopard def test_ld64_dep_pre_leopard
MacOS.stubs(:version).returns(MacOS::Version.new("10.4")) MacOS.stubs(:version).returns(MacOS::Version.new("10.4"))
assert_equal LD64Dependency.new, @d.build(:ld64) assert_equal LD64Dependency.new, @d.build(:ld64)
@ -35,4 +40,18 @@ class OSMacDependencyCollectorTests < Homebrew::TestCase
@d.add ant: :build @d.add ant: :build
assert_nil find_dependency("ant") assert_nil find_dependency("ant")
end end
def test_resource_dep_xz_url_pre_lion
MacOS.stubs(:version).returns(MacOS::Version.new("10.6"))
resource = Resource.new
resource.url("http://example.com/foo.tar.xz")
assert_equal Dependency.new("xz", [:build]), @d.add(resource)
end
def test_resource_dep_xz_lion_or_newer
MacOS.stubs(:version).returns(MacOS::Version.new("10.7"))
resource = Resource.new
resource.url("http://example.com/foo.tar.xz")
assert_nil @d.add(resource)
end
end end