From 444b292df9d60b355895c9b024522d01b9e30771 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 16 Feb 2018 10:41:14 -0600 Subject: [PATCH 01/14] zip and bzip2 dependencies when needed On some systems identified as Linux, zip and bzip2 might not be available. Therefore, on such platforms we add them unconditionally as dependencies when required. On Mac, these dependencies are always satisfied. --- Library/Homebrew/dependency_collector.rb | 10 +++++++ .../extend/os/dependency_collector.rb | 1 + .../extend/os/linux/dependency_collector.rb | 27 +++++++++++++++++++ .../extend/os/mac/dependency_collector.rb | 5 ++++ 4 files changed, 43 insertions(+) create mode 100644 Library/Homebrew/extend/os/linux/dependency_collector.rb diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index 03a86d661e385..9e6d6ab0b9bd5 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -72,6 +72,14 @@ def xz_dep_if_needed(tags) def ld64_dep_if_needed(*); end + def zip_dep_if_needed(tags) + return + end + + def bzip2_dep_if_needed(tags) + return + end + def self.tar_needs_xz_dependency? !new.xz_dep_if_needed([]).nil? end @@ -162,6 +170,8 @@ def parse_url_spec(url, tags) when ".lz" then Dependency.new("lzip", tags) when ".rar" then Dependency.new("unrar", tags) when ".7z" then Dependency.new("p7zip", tags) + when ".zip" then zip_dep_if_needed(tags) + when ".bz2" then bzip2_dep_if_needed(tags) end end end diff --git a/Library/Homebrew/extend/os/dependency_collector.rb b/Library/Homebrew/extend/os/dependency_collector.rb index 56fcad31d00e8..fffec1c999409 100644 --- a/Library/Homebrew/extend/os/dependency_collector.rb +++ b/Library/Homebrew/extend/os/dependency_collector.rb @@ -1,2 +1,3 @@ require "dependency_collector" require "extend/os/mac/dependency_collector" if OS.mac? +require "extend/os/linux/dependency_collector" if OS.linux? diff --git a/Library/Homebrew/extend/os/linux/dependency_collector.rb b/Library/Homebrew/extend/os/linux/dependency_collector.rb new file mode 100644 index 0000000000000..13ea1ab334bcd --- /dev/null +++ b/Library/Homebrew/extend/os/linux/dependency_collector.rb @@ -0,0 +1,27 @@ +class DependencyCollector + + def git_dep_if_needed(tags) + Dependency.new("git", tags) + end + + def cvs_dep_if_needed(tags) + Dependency.new("cvs", tags) + end + + def xz_dep_if_needed(tags) + Dependency.new("xz", tags) + end + + def ld64_dep_if_needed(*) + return + end + + def zip_dep_if_needed(tags) + Dependency.new("zip", tags) + end + + def bzip2_dep_if_needed(tags) + Dependency.new("bzip2", tags) + end + +end diff --git a/Library/Homebrew/extend/os/mac/dependency_collector.rb b/Library/Homebrew/extend/os/mac/dependency_collector.rb index 108b6ccb2b9b0..1162868794ea1 100644 --- a/Library/Homebrew/extend/os/mac/dependency_collector.rb +++ b/Library/Homebrew/extend/os/mac/dependency_collector.rb @@ -23,4 +23,9 @@ def ld64_dep_if_needed(*) return if MacOS.version > :tiger LD64Dependency.new end + + def zip_dep_if_needed(tags); end + + def bzip2_dep_if_needed(tags); end + end From 5a9297612060d25d5c959530330e4a907e0931a8 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 16 Feb 2018 10:49:43 -0600 Subject: [PATCH 02/14] Fixing brew-style offenses --- Library/Homebrew/dependency_collector.rb | 8 ++------ Library/Homebrew/extend/os/linux/dependency_collector.rb | 6 +----- Library/Homebrew/extend/os/mac/dependency_collector.rb | 1 - 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index 9e6d6ab0b9bd5..689e4e2f13387 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -72,13 +72,9 @@ def xz_dep_if_needed(tags) def ld64_dep_if_needed(*); end - def zip_dep_if_needed(tags) - return - end + def zip_dep_if_needed(*); end - def bzip2_dep_if_needed(tags) - return - end + def bzip2_dep_if_needed(*); end def self.tar_needs_xz_dependency? !new.xz_dep_if_needed([]).nil? diff --git a/Library/Homebrew/extend/os/linux/dependency_collector.rb b/Library/Homebrew/extend/os/linux/dependency_collector.rb index 13ea1ab334bcd..61df498ffa646 100644 --- a/Library/Homebrew/extend/os/linux/dependency_collector.rb +++ b/Library/Homebrew/extend/os/linux/dependency_collector.rb @@ -1,5 +1,4 @@ class DependencyCollector - def git_dep_if_needed(tags) Dependency.new("git", tags) end @@ -12,9 +11,7 @@ def xz_dep_if_needed(tags) Dependency.new("xz", tags) end - def ld64_dep_if_needed(*) - return - end + def ld64_dep_if_needed(*); end def zip_dep_if_needed(tags) Dependency.new("zip", tags) @@ -23,5 +20,4 @@ def zip_dep_if_needed(tags) def bzip2_dep_if_needed(tags) Dependency.new("bzip2", tags) end - end diff --git a/Library/Homebrew/extend/os/mac/dependency_collector.rb b/Library/Homebrew/extend/os/mac/dependency_collector.rb index 1162868794ea1..5fd83f6185fad 100644 --- a/Library/Homebrew/extend/os/mac/dependency_collector.rb +++ b/Library/Homebrew/extend/os/mac/dependency_collector.rb @@ -27,5 +27,4 @@ def ld64_dep_if_needed(*) def zip_dep_if_needed(tags); end def bzip2_dep_if_needed(tags); end - end From a53171d9fe99eee935720bccab84cdfd5092ee5b Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 16 Feb 2018 14:58:07 -0600 Subject: [PATCH 03/14] Adding tests for dependency_collector on Linux --- .../test/dependency_collector_spec.rb | 1 + .../test/os/dependency_collector_spec.rb | 1 + .../os/linux/dependency_collector_spec.rb | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 Library/Homebrew/test/os/dependency_collector_spec.rb create mode 100644 Library/Homebrew/test/os/linux/dependency_collector_spec.rb diff --git a/Library/Homebrew/test/dependency_collector_spec.rb b/Library/Homebrew/test/dependency_collector_spec.rb index 46e859b2d8ae2..f8fb16c0296c3 100644 --- a/Library/Homebrew/test/dependency_collector_spec.rb +++ b/Library/Homebrew/test/dependency_collector_spec.rb @@ -140,3 +140,4 @@ def find_requirement(klass) end end end +require "test/os/dependency_collector_spec" diff --git a/Library/Homebrew/test/os/dependency_collector_spec.rb b/Library/Homebrew/test/os/dependency_collector_spec.rb new file mode 100644 index 0000000000000..3d7029e40528a --- /dev/null +++ b/Library/Homebrew/test/os/dependency_collector_spec.rb @@ -0,0 +1 @@ +require "test/os/linux/dependency_collector_spec" if OS.linux? diff --git a/Library/Homebrew/test/os/linux/dependency_collector_spec.rb b/Library/Homebrew/test/os/linux/dependency_collector_spec.rb new file mode 100644 index 0000000000000..37d61c89be2aa --- /dev/null +++ b/Library/Homebrew/test/os/linux/dependency_collector_spec.rb @@ -0,0 +1,23 @@ +require "dependency_collector" + +describe DependencyCollector do + alias_matcher :be_a_build_requirement, :be_build + + after(:each) do + described_class.clear_cache + end + + describe "#add" do + it "creates a resource dependency from a '.zip' URL" do + resource = Resource.new + resource.url("http://example.com/foo.zip") + expect(subject.add(resource)).to eq(Dependency.new("zip", [:build])) + end + + it "creates a resource dependency from a '.bzip2' URL" do + resource = Resource.new + resource.url("http://example.com/foo.tar.bzip2") + expect(subject.add(resource)).to eq(Dependency.new("bzip2", [:build])) + end + end +end From 5cfcd2ae9f2a4ef731f666e3e78cfb74ae28ae38 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 16 Feb 2018 15:04:43 -0600 Subject: [PATCH 04/14] Fixing test --- Library/Homebrew/test/os/linux/dependency_collector_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/os/linux/dependency_collector_spec.rb b/Library/Homebrew/test/os/linux/dependency_collector_spec.rb index 37d61c89be2aa..eaae99fe92c1d 100644 --- a/Library/Homebrew/test/os/linux/dependency_collector_spec.rb +++ b/Library/Homebrew/test/os/linux/dependency_collector_spec.rb @@ -14,9 +14,9 @@ expect(subject.add(resource)).to eq(Dependency.new("zip", [:build])) end - it "creates a resource dependency from a '.bzip2' URL" do + it "creates a resource dependency from a '.bz2' URL" do resource = Resource.new - resource.url("http://example.com/foo.tar.bzip2") + resource.url("http://example.com/foo.tar.bz2") expect(subject.add(resource)).to eq(Dependency.new("bzip2", [:build])) end end From 1b74f21492ca92bb8899304176cfdf4c42def297 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 16 Feb 2018 15:08:55 -0600 Subject: [PATCH 05/14] Removing unnecessary arguments --- Library/Homebrew/extend/os/mac/dependency_collector.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/dependency_collector.rb b/Library/Homebrew/extend/os/mac/dependency_collector.rb index 5fd83f6185fad..671a63f5584d0 100644 --- a/Library/Homebrew/extend/os/mac/dependency_collector.rb +++ b/Library/Homebrew/extend/os/mac/dependency_collector.rb @@ -24,7 +24,7 @@ def ld64_dep_if_needed(*) LD64Dependency.new end - def zip_dep_if_needed(tags); end + def zip_dep_if_needed(*); end - def bzip2_dep_if_needed(tags); end + def bzip2_dep_if_needed(*); end end From 3dabebbd1643971d1904749530fe6ba73ec38817 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Mon, 19 Feb 2018 06:49:42 +0000 Subject: [PATCH 06/14] Refactoring based on suggestions Defaulting zip_dep_if_needed(tags) and bzip2_dep_if_needed(tags) methods to those on Linux and overriding them on macOS. --- Library/Homebrew/dependency_collector.rb | 8 +++++-- .../extend/os/dependency_collector.rb | 1 - .../extend/os/linux/dependency_collector.rb | 23 ------------------- 3 files changed, 6 insertions(+), 26 deletions(-) delete mode 100644 Library/Homebrew/extend/os/linux/dependency_collector.rb diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index 689e4e2f13387..4b8f9e8723c70 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -72,9 +72,13 @@ def xz_dep_if_needed(tags) def ld64_dep_if_needed(*); end - def zip_dep_if_needed(*); end + def zip_dep_if_needed(tags) + Dependency.new("zip", tags) + end - def bzip2_dep_if_needed(*); end + def bzip2_dep_if_needed(tags) + Dependency.new("bzip2", tags) + end def self.tar_needs_xz_dependency? !new.xz_dep_if_needed([]).nil? diff --git a/Library/Homebrew/extend/os/dependency_collector.rb b/Library/Homebrew/extend/os/dependency_collector.rb index fffec1c999409..56fcad31d00e8 100644 --- a/Library/Homebrew/extend/os/dependency_collector.rb +++ b/Library/Homebrew/extend/os/dependency_collector.rb @@ -1,3 +1,2 @@ require "dependency_collector" require "extend/os/mac/dependency_collector" if OS.mac? -require "extend/os/linux/dependency_collector" if OS.linux? diff --git a/Library/Homebrew/extend/os/linux/dependency_collector.rb b/Library/Homebrew/extend/os/linux/dependency_collector.rb deleted file mode 100644 index 61df498ffa646..0000000000000 --- a/Library/Homebrew/extend/os/linux/dependency_collector.rb +++ /dev/null @@ -1,23 +0,0 @@ -class DependencyCollector - def git_dep_if_needed(tags) - Dependency.new("git", tags) - end - - def cvs_dep_if_needed(tags) - Dependency.new("cvs", tags) - end - - def xz_dep_if_needed(tags) - Dependency.new("xz", tags) - end - - def ld64_dep_if_needed(*); end - - def zip_dep_if_needed(tags) - Dependency.new("zip", tags) - end - - def bzip2_dep_if_needed(tags) - Dependency.new("bzip2", tags) - end -end From b084a2581f32fcbc6fbdf081ffce9a6c53f66ff6 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Mon, 19 Feb 2018 07:21:34 +0000 Subject: [PATCH 07/14] Making zip and bzip2 dependecies conditional Here, we are adding `unless which("zip")` and `unless which("bzip2")` and, thus, make `zip` and `bzip2` dependencies conditional. --- Library/Homebrew/dependency_collector.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index 4b8f9e8723c70..bd71d61b090d1 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -73,11 +73,11 @@ def xz_dep_if_needed(tags) def ld64_dep_if_needed(*); end def zip_dep_if_needed(tags) - Dependency.new("zip", tags) + Dependency.new("zip", tags) unless which("zip") end def bzip2_dep_if_needed(tags) - Dependency.new("bzip2", tags) + Dependency.new("bzip2", tags) unless which("bzip2") end def self.tar_needs_xz_dependency? From 73a3592981f7645ba81afef0332def27f553abc4 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Mon, 19 Feb 2018 08:54:30 +0000 Subject: [PATCH 08/14] Renaming linux-specifix file with tests Files are globbed based on their name. Therefore, we have to rename them so tests for Linux are not executed on a Mac. --- Library/Homebrew/test/os/dependency_collector_spec.rb | 2 +- .../{dependency_collector_spec.rb => dependency_collector.rb} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename Library/Homebrew/test/os/linux/{dependency_collector_spec.rb => dependency_collector.rb} (100%) diff --git a/Library/Homebrew/test/os/dependency_collector_spec.rb b/Library/Homebrew/test/os/dependency_collector_spec.rb index 3d7029e40528a..d190788daae33 100644 --- a/Library/Homebrew/test/os/dependency_collector_spec.rb +++ b/Library/Homebrew/test/os/dependency_collector_spec.rb @@ -1 +1 @@ -require "test/os/linux/dependency_collector_spec" if OS.linux? +require "test/os/linux/dependency_collector" if OS.linux? diff --git a/Library/Homebrew/test/os/linux/dependency_collector_spec.rb b/Library/Homebrew/test/os/linux/dependency_collector.rb similarity index 100% rename from Library/Homebrew/test/os/linux/dependency_collector_spec.rb rename to Library/Homebrew/test/os/linux/dependency_collector.rb From d25fc5ce50a46b37e84d90151d0ea3c467667231 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Mon, 19 Feb 2018 09:54:36 +0000 Subject: [PATCH 09/14] Code refactoring --- Library/Homebrew/dependency_collector.rb | 4 ++-- Library/Homebrew/extend/os/mac/dependency_collector.rb | 8 ++++---- Library/Homebrew/test/dependency_collector_spec.rb | 1 - Library/Homebrew/test/os/dependency_collector_spec.rb | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index bd71d61b090d1..41e79810ea30e 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -166,12 +166,12 @@ def resource_dep(spec, tags) def parse_url_spec(url, tags) case File.extname(url) when ".xz" then xz_dep_if_needed(tags) + when ".zip" then zip_dep_if_needed(tags) + when ".bz2" then bzip2_dep_if_needed(tags) when ".lha", ".lzh" then Dependency.new("lha", tags) when ".lz" then Dependency.new("lzip", tags) when ".rar" then Dependency.new("unrar", tags) when ".7z" then Dependency.new("p7zip", tags) - when ".zip" then zip_dep_if_needed(tags) - when ".bz2" then bzip2_dep_if_needed(tags) end end end diff --git a/Library/Homebrew/extend/os/mac/dependency_collector.rb b/Library/Homebrew/extend/os/mac/dependency_collector.rb index 671a63f5584d0..a7e5d7ffc89d0 100644 --- a/Library/Homebrew/extend/os/mac/dependency_collector.rb +++ b/Library/Homebrew/extend/os/mac/dependency_collector.rb @@ -18,13 +18,13 @@ def xz_dep_if_needed(tags) Dependency.new("xz", tags) end + def zip_dep_if_needed(tags); end + + def bzip2_dep_if_needed(tags); end + def ld64_dep_if_needed(*) # Tiger's ld is too old to properly link some software return if MacOS.version > :tiger LD64Dependency.new end - - def zip_dep_if_needed(*); end - - def bzip2_dep_if_needed(*); end end diff --git a/Library/Homebrew/test/dependency_collector_spec.rb b/Library/Homebrew/test/dependency_collector_spec.rb index f8fb16c0296c3..46e859b2d8ae2 100644 --- a/Library/Homebrew/test/dependency_collector_spec.rb +++ b/Library/Homebrew/test/dependency_collector_spec.rb @@ -140,4 +140,3 @@ def find_requirement(klass) end end end -require "test/os/dependency_collector_spec" diff --git a/Library/Homebrew/test/os/dependency_collector_spec.rb b/Library/Homebrew/test/os/dependency_collector_spec.rb index d190788daae33..4fe064732c1b9 100644 --- a/Library/Homebrew/test/os/dependency_collector_spec.rb +++ b/Library/Homebrew/test/os/dependency_collector_spec.rb @@ -1 +1 @@ -require "test/os/linux/dependency_collector" if OS.linux? +require "test/dependency_collector" From 306c19061ee1211e285cdd6006d852cc26a5ae90 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Mon, 19 Feb 2018 09:58:30 +0000 Subject: [PATCH 10/14] Code refactoring v2.0 --- Library/Homebrew/dependency_collector.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index 41e79810ea30e..0a38f0de3918e 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -70,8 +70,6 @@ def xz_dep_if_needed(tags) Dependency.new("xz", tags) end - def ld64_dep_if_needed(*); end - def zip_dep_if_needed(tags) Dependency.new("zip", tags) unless which("zip") end @@ -80,6 +78,8 @@ def bzip2_dep_if_needed(tags) Dependency.new("bzip2", tags) unless which("bzip2") end + def ld64_dep_if_needed(*); end + def self.tar_needs_xz_dependency? !new.xz_dep_if_needed([]).nil? end From c6dac68d8bdb652152d89a097a9ab9f270832d68 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Mon, 19 Feb 2018 10:21:01 +0000 Subject: [PATCH 11/14] Code refactoring v3.0 --- .../test/os/dependency_collector_spec.rb | 24 ++++++++++++++++++- .../test/os/linux/dependency_collector.rb | 23 ------------------ 2 files changed, 23 insertions(+), 24 deletions(-) delete mode 100644 Library/Homebrew/test/os/linux/dependency_collector.rb diff --git a/Library/Homebrew/test/os/dependency_collector_spec.rb b/Library/Homebrew/test/os/dependency_collector_spec.rb index 4fe064732c1b9..eaae99fe92c1d 100644 --- a/Library/Homebrew/test/os/dependency_collector_spec.rb +++ b/Library/Homebrew/test/os/dependency_collector_spec.rb @@ -1 +1,23 @@ -require "test/dependency_collector" +require "dependency_collector" + +describe DependencyCollector do + alias_matcher :be_a_build_requirement, :be_build + + after(:each) do + described_class.clear_cache + end + + describe "#add" do + it "creates a resource dependency from a '.zip' URL" do + resource = Resource.new + resource.url("http://example.com/foo.zip") + expect(subject.add(resource)).to eq(Dependency.new("zip", [:build])) + end + + it "creates a resource dependency from a '.bz2' URL" do + resource = Resource.new + resource.url("http://example.com/foo.tar.bz2") + expect(subject.add(resource)).to eq(Dependency.new("bzip2", [:build])) + end + end +end diff --git a/Library/Homebrew/test/os/linux/dependency_collector.rb b/Library/Homebrew/test/os/linux/dependency_collector.rb deleted file mode 100644 index eaae99fe92c1d..0000000000000 --- a/Library/Homebrew/test/os/linux/dependency_collector.rb +++ /dev/null @@ -1,23 +0,0 @@ -require "dependency_collector" - -describe DependencyCollector do - alias_matcher :be_a_build_requirement, :be_build - - after(:each) do - described_class.clear_cache - end - - describe "#add" do - it "creates a resource dependency from a '.zip' URL" do - resource = Resource.new - resource.url("http://example.com/foo.zip") - expect(subject.add(resource)).to eq(Dependency.new("zip", [:build])) - end - - it "creates a resource dependency from a '.bz2' URL" do - resource = Resource.new - resource.url("http://example.com/foo.tar.bz2") - expect(subject.add(resource)).to eq(Dependency.new("bzip2", [:build])) - end - end -end From 14d7a7a08c9aab7db14ea03f59ec85899e5e3ba6 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 20 Feb 2018 21:33:38 +0000 Subject: [PATCH 12/14] Code refactoring 4.0 --- .../extend/os/dependency_collector.rb | 1 + .../extend/os/linux/dependency_collector.rb | 5 ++ .../test/os/dependency_collector_spec.rb | 23 -------- .../os/linux/dependency_collector_spec.rb | 53 +++++++++++++++++++ .../test/os/mac/dependency_collector_spec.rb | 12 +++++ 5 files changed, 71 insertions(+), 23 deletions(-) create mode 100644 Library/Homebrew/extend/os/linux/dependency_collector.rb delete mode 100644 Library/Homebrew/test/os/dependency_collector_spec.rb create mode 100644 Library/Homebrew/test/os/linux/dependency_collector_spec.rb diff --git a/Library/Homebrew/extend/os/dependency_collector.rb b/Library/Homebrew/extend/os/dependency_collector.rb index 56fcad31d00e8..fffec1c999409 100644 --- a/Library/Homebrew/extend/os/dependency_collector.rb +++ b/Library/Homebrew/extend/os/dependency_collector.rb @@ -1,2 +1,3 @@ require "dependency_collector" require "extend/os/mac/dependency_collector" if OS.mac? +require "extend/os/linux/dependency_collector" if OS.linux? diff --git a/Library/Homebrew/extend/os/linux/dependency_collector.rb b/Library/Homebrew/extend/os/linux/dependency_collector.rb new file mode 100644 index 0000000000000..dc5b994b8ad9b --- /dev/null +++ b/Library/Homebrew/extend/os/linux/dependency_collector.rb @@ -0,0 +1,5 @@ +class DependencyCollector + def xz_dep_if_needed(tags) + Dependency.new("xz", tags) unless which("xz") + end +end diff --git a/Library/Homebrew/test/os/dependency_collector_spec.rb b/Library/Homebrew/test/os/dependency_collector_spec.rb deleted file mode 100644 index eaae99fe92c1d..0000000000000 --- a/Library/Homebrew/test/os/dependency_collector_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require "dependency_collector" - -describe DependencyCollector do - alias_matcher :be_a_build_requirement, :be_build - - after(:each) do - described_class.clear_cache - end - - describe "#add" do - it "creates a resource dependency from a '.zip' URL" do - resource = Resource.new - resource.url("http://example.com/foo.zip") - expect(subject.add(resource)).to eq(Dependency.new("zip", [:build])) - end - - it "creates a resource dependency from a '.bz2' URL" do - resource = Resource.new - resource.url("http://example.com/foo.tar.bz2") - expect(subject.add(resource)).to eq(Dependency.new("bzip2", [:build])) - end - end -end diff --git a/Library/Homebrew/test/os/linux/dependency_collector_spec.rb b/Library/Homebrew/test/os/linux/dependency_collector_spec.rb new file mode 100644 index 0000000000000..5771fd59a2cb0 --- /dev/null +++ b/Library/Homebrew/test/os/linux/dependency_collector_spec.rb @@ -0,0 +1,53 @@ +require "dependency_collector" + +describe DependencyCollector do + alias_matcher :be_a_build_requirement, :be_build + + after(:each) do + described_class.clear_cache + end + + describe "#add" do + resource = Resource.new + + context "when xz, zip, and bzip2 are not available" do + it "creates a resource dependency from a '.xz' URL" do + resource.url("http://example.com/foo.xz") + allow_any_instance_of(Object).to receive(:which).with("xz") + expect(subject.add(resource)).to eq(Dependency.new("xz", [:build])) + end + + it "creates a resource dependency from a '.zip' URL" do + resource.url("http://example.com/foo.zip") + allow_any_instance_of(Object).to receive(:which).with("zip") + expect(subject.add(resource)).to eq(Dependency.new("zip", [:build])) + end + + it "creates a resource dependency from a '.bz2' URL" do + resource.url("http://example.com/foo.tar.bz2") + allow_any_instance_of(Object).to receive(:which).with("bzip2") + expect(subject.add(resource)).to eq(Dependency.new("bzip2", [:build])) + end + end + + context "when xz, zip, and bzip2 are available" do + it "does not create a resource dependency from a '.xz' URL" do + resource.url("http://example.com/foo.xz") + allow_any_instance_of(Object).to receive(:which).with("xz").and_return(Pathname.new("foo")) + expect(subject.add(resource)).to be nil + end + + it "does not create a resource dependency from a '.zip' URL" do + resource.url("http://example.com/foo.zip") + allow_any_instance_of(Object).to receive(:which).with("zip").and_return(Pathname.new("foo")) + expect(subject.add(resource)).to be nil + end + + it "does not create a resource dependency from a '.bz2' URL" do + resource.url("http://example.com/foo.tar.bz2") + allow_any_instance_of(Object).to receive(:which).with("bzip2").and_return(Pathname.new("foo")) + expect(subject.add(resource)).to be nil + end + end + end +end diff --git a/Library/Homebrew/test/os/mac/dependency_collector_spec.rb b/Library/Homebrew/test/os/mac/dependency_collector_spec.rb index 5d260ebf711c2..a8fe8ba54cd4b 100644 --- a/Library/Homebrew/test/os/mac/dependency_collector_spec.rb +++ b/Library/Homebrew/test/os/mac/dependency_collector_spec.rb @@ -36,6 +36,18 @@ expect(subject.add(resource)).to be nil end + specify "Resource dependency from a '.zip' URL" do + resource = Resource.new + resource.url("http://example.com/foo.zip") + expect(subject.add(resource)).to be nil + end + + specify "Resource dependency from a '.bz2' URL" do + resource = Resource.new + resource.url("http://example.com/foo.tar.bz2") + expect(subject.add(resource)).to be nil + end + specify "Resource dependency from a '.git' URL" do resource = Resource.new resource.url("git://example.com/foo/bar.git") From c83dd0d04b857161b47a43b54ba56c7296ac50c0 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Wed, 21 Feb 2018 13:44:51 +0000 Subject: [PATCH 13/14] brew style: replace tabs with spaces --- .../os/linux/dependency_collector_spec.rb | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Library/Homebrew/test/os/linux/dependency_collector_spec.rb b/Library/Homebrew/test/os/linux/dependency_collector_spec.rb index 5771fd59a2cb0..543ed39b0b2f4 100644 --- a/Library/Homebrew/test/os/linux/dependency_collector_spec.rb +++ b/Library/Homebrew/test/os/linux/dependency_collector_spec.rb @@ -12,41 +12,41 @@ context "when xz, zip, and bzip2 are not available" do it "creates a resource dependency from a '.xz' URL" do - resource.url("http://example.com/foo.xz") - allow_any_instance_of(Object).to receive(:which).with("xz") - expect(subject.add(resource)).to eq(Dependency.new("xz", [:build])) + resource.url("http://example.com/foo.xz") + allow_any_instance_of(Object).to receive(:which).with("xz") + expect(subject.add(resource)).to eq(Dependency.new("xz", [:build])) end it "creates a resource dependency from a '.zip' URL" do - resource.url("http://example.com/foo.zip") - allow_any_instance_of(Object).to receive(:which).with("zip") - expect(subject.add(resource)).to eq(Dependency.new("zip", [:build])) + resource.url("http://example.com/foo.zip") + allow_any_instance_of(Object).to receive(:which).with("zip") + expect(subject.add(resource)).to eq(Dependency.new("zip", [:build])) end it "creates a resource dependency from a '.bz2' URL" do - resource.url("http://example.com/foo.tar.bz2") - allow_any_instance_of(Object).to receive(:which).with("bzip2") - expect(subject.add(resource)).to eq(Dependency.new("bzip2", [:build])) + resource.url("http://example.com/foo.tar.bz2") + allow_any_instance_of(Object).to receive(:which).with("bzip2") + expect(subject.add(resource)).to eq(Dependency.new("bzip2", [:build])) end end context "when xz, zip, and bzip2 are available" do it "does not create a resource dependency from a '.xz' URL" do - resource.url("http://example.com/foo.xz") - allow_any_instance_of(Object).to receive(:which).with("xz").and_return(Pathname.new("foo")) - expect(subject.add(resource)).to be nil + resource.url("http://example.com/foo.xz") + allow_any_instance_of(Object).to receive(:which).with("xz").and_return(Pathname.new("foo")) + expect(subject.add(resource)).to be nil end it "does not create a resource dependency from a '.zip' URL" do - resource.url("http://example.com/foo.zip") - allow_any_instance_of(Object).to receive(:which).with("zip").and_return(Pathname.new("foo")) - expect(subject.add(resource)).to be nil + resource.url("http://example.com/foo.zip") + allow_any_instance_of(Object).to receive(:which).with("zip").and_return(Pathname.new("foo")) + expect(subject.add(resource)).to be nil end it "does not create a resource dependency from a '.bz2' URL" do - resource.url("http://example.com/foo.tar.bz2") - allow_any_instance_of(Object).to receive(:which).with("bzip2").and_return(Pathname.new("foo")) - expect(subject.add(resource)).to be nil + resource.url("http://example.com/foo.tar.bz2") + allow_any_instance_of(Object).to receive(:which).with("bzip2").and_return(Pathname.new("foo")) + expect(subject.add(resource)).to be nil end end end From f8874004c2c0ee06b3f0420ac549f762beeb3433 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Wed, 21 Feb 2018 14:11:35 +0000 Subject: [PATCH 14/14] Make 'xz' and 'cvs' dependencies conditional --- Library/Homebrew/dependency_collector.rb | 4 ++-- Library/Homebrew/extend/os/dependency_collector.rb | 1 - Library/Homebrew/extend/os/linux/dependency_collector.rb | 5 ----- 3 files changed, 2 insertions(+), 8 deletions(-) delete mode 100644 Library/Homebrew/extend/os/linux/dependency_collector.rb diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index 0a38f0de3918e..7d3b90f9c6697 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -63,11 +63,11 @@ def subversion_dep_if_needed(tags) end def cvs_dep_if_needed(tags) - Dependency.new("cvs", tags) + Dependency.new("cvs", tags) unless which("cvs") end def xz_dep_if_needed(tags) - Dependency.new("xz", tags) + Dependency.new("xz", tags) unless which("xz") end def zip_dep_if_needed(tags) diff --git a/Library/Homebrew/extend/os/dependency_collector.rb b/Library/Homebrew/extend/os/dependency_collector.rb index fffec1c999409..56fcad31d00e8 100644 --- a/Library/Homebrew/extend/os/dependency_collector.rb +++ b/Library/Homebrew/extend/os/dependency_collector.rb @@ -1,3 +1,2 @@ require "dependency_collector" require "extend/os/mac/dependency_collector" if OS.mac? -require "extend/os/linux/dependency_collector" if OS.linux? diff --git a/Library/Homebrew/extend/os/linux/dependency_collector.rb b/Library/Homebrew/extend/os/linux/dependency_collector.rb deleted file mode 100644 index dc5b994b8ad9b..0000000000000 --- a/Library/Homebrew/extend/os/linux/dependency_collector.rb +++ /dev/null @@ -1,5 +0,0 @@ -class DependencyCollector - def xz_dep_if_needed(tags) - Dependency.new("xz", tags) unless which("xz") - end -end