aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike McQuaid2016-10-15 13:10:35 +0100
committerMike McQuaid2016-10-15 13:10:37 +0100
commitb1a16deb190ae5ccb05b60a3dd10b53eaf1bae15 (patch)
tree5c74a2f3425ccac27cf40cb01d171e2d34e2b821
parent13276409a9b08fcbadfed18c25b6fd11af343729 (diff)
downloadbrew-b1a16deb190ae5ccb05b60a3dd10b53eaf1bae15.tar.bz2
Use BSD tar's libarchive LZMA support if available
Avoid using an unnecessary `xz` dependency when it's not needed.
-rw-r--r--Library/Homebrew/dependency_collector.rb16
-rw-r--r--Library/Homebrew/development_tools.rb4
-rw-r--r--Library/Homebrew/download_strategy.rb22
-rw-r--r--Library/Homebrew/extend/os/mac/dependency_collector.rb9
-rw-r--r--Library/Homebrew/extend/os/mac/development_tools.rb4
-rw-r--r--Library/Homebrew/test/test_dependency_collector.rb6
-rw-r--r--Library/Homebrew/test/test_os_mac_dependency_collector.rb19
7 files changed, 59 insertions, 21 deletions
diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb
index 02c781998..814084255 100644
--- a/Library/Homebrew/dependency_collector.rb
+++ b/Library/Homebrew/dependency_collector.rb
@@ -61,6 +61,10 @@ class DependencyCollector
parse_spec(spec, Array(tags))
end
+ def self.tar_needs_xz_dependency?
+ !new.xz_dep([]).nil?
+ end
+
private
def parse_spec(spec, tags)
@@ -113,7 +117,7 @@ class DependencyCollector
when :osxfuse then OsxfuseRequirement.new(tags)
when :perl then PerlRequirement.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)
# Tiger's ld is too old to properly link some software
when :ld64 then LD64Dependency.new if MacOS.version < :leopard
@@ -134,8 +138,12 @@ class DependencyCollector
spec.new(tags)
end
- def ant_dep(spec, tags)
- Dependency.new(spec.to_s, tags)
+ def ant_dep(tags)
+ Dependency.new("ant", tags)
+ end
+
+ def xz_dep(tags)
+ Dependency.new("xz", tags)
end
def resource_dep(spec, tags)
@@ -164,7 +172,7 @@ class DependencyCollector
def parse_url_spec(url, tags)
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 ".lz" then Dependency.new("lzip", tags)
when ".rar" then Dependency.new("unrar", tags)
diff --git a/Library/Homebrew/development_tools.rb b/Library/Homebrew/development_tools.rb
index 7221e5b52..3e1f16d2a 100644
--- a/Library/Homebrew/development_tools.rb
+++ b/Library/Homebrew/development_tools.rb
@@ -88,6 +88,10 @@ class DevelopmentTools
@clang_version = @clang_build_version = nil
@non_apple_gcc_version = {}
end
+
+ def tar_supports_xz?
+ false
+ end
end
end
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index 4f2f1b6b0..057768246 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -222,7 +222,7 @@ end
class AbstractFileDownloadStrategy < AbstractDownloadStrategy
def stage
- case cached_location.compression_type
+ case type = cached_location.compression_type
when :zip
with_system_path { quiet_safe_system "unzip", "-qq", cached_location }
chdir
@@ -230,19 +230,23 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
with_system_path { buffered_write("gunzip") }
when :bzip2_only
with_system_path { buffered_write("bunzip2") }
- when :gzip, :bzip2, :compress, :tar
+ when :gzip, :bzip2, :xz, :compress, :tar
tar_flags = "x"
- # Older versions of tar require an explicit format flag
- if cached_location.compression_type == :gzip
+ if type == :gzip
tar_flags << "z"
- elsif cached_location.compression_type == :bzip2
+ elsif type == :bzip2
tar_flags << "j"
+ elsif type == :xz
+ tar_flags << "J"
end
tar_flags << "f"
- with_system_path { safe_system "tar", tar_flags, cached_location }
- chdir
- when :xz
- with_system_path { pipe_to_tar(xzpath) }
+ with_system_path do
+ if type == :xz && DependencyCollector.tar_needs_xz_dependency?
+ pipe_to_tar(xzpath)
+ else
+ safe_system "tar", tar_flags, cached_location
+ end
+ end
chdir
when :lzip
with_system_path { pipe_to_tar(lzippath) }
diff --git a/Library/Homebrew/extend/os/mac/dependency_collector.rb b/Library/Homebrew/extend/os/mac/dependency_collector.rb
index ee98045b6..72c619105 100644
--- a/Library/Homebrew/extend/os/mac/dependency_collector.rb
+++ b/Library/Homebrew/extend/os/mac/dependency_collector.rb
@@ -1,6 +1,11 @@
class DependencyCollector
- def ant_dep(spec, tags)
+ def ant_dep(tags)
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
diff --git a/Library/Homebrew/extend/os/mac/development_tools.rb b/Library/Homebrew/extend/os/mac/development_tools.rb
index 381b26e66..7c97b9d69 100644
--- a/Library/Homebrew/extend/os/mac/development_tools.rb
+++ b/Library/Homebrew/extend/os/mac/development_tools.rb
@@ -76,5 +76,9 @@ class DevelopmentTools
end
end
end
+
+ def tar_supports_xz?
+ false
+ end
end
end
diff --git a/Library/Homebrew/test/test_dependency_collector.rb b/Library/Homebrew/test/test_dependency_collector.rb
index 4e87c8515..1c7f70118 100644
--- a/Library/Homebrew/test/test_dependency_collector.rb
+++ b/Library/Homebrew/test/test_dependency_collector.rb
@@ -114,12 +114,6 @@ class DependencyCollectorTests < Homebrew::TestCase
assert_nil @d.add(resource)
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
resource = Resource.new
resource.url("http://example.com/foo.lz")
diff --git a/Library/Homebrew/test/test_os_mac_dependency_collector.rb b/Library/Homebrew/test/test_os_mac_dependency_collector.rb
index 05b466c94..d3a45b1fb 100644
--- a/Library/Homebrew/test/test_os_mac_dependency_collector.rb
+++ b/Library/Homebrew/test/test_os_mac_dependency_collector.rb
@@ -14,6 +14,11 @@ class OSMacDependencyCollectorTests < Homebrew::TestCase
DependencyCollector.clear_cache
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
MacOS.stubs(:version).returns(MacOS::Version.new("10.4"))
assert_equal LD64Dependency.new, @d.build(:ld64)
@@ -35,4 +40,18 @@ class OSMacDependencyCollectorTests < Homebrew::TestCase
@d.add ant: :build
assert_nil find_dependency("ant")
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