Skip to content

Commit

Permalink
Merge pull request #821 from Homebrew/move-to-v2-json
Browse files Browse the repository at this point in the history
Swap to `--json=v2`
  • Loading branch information
jacobbednarz committed Nov 26, 2020
2 parents c91584c + b3da7ad commit b0aed0a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/bundle/cask_dumper.rb
Expand Up @@ -26,10 +26,10 @@ def dump(casks_required_by_formulae)
def formula_dependencies(cask_list)
return [] unless cask_list.present?

cask_info_response = `brew info --cask #{cask_list.join(" ")} --json=v1`
cask_info_response = `brew info --cask #{cask_list.join(" ")} --json=v2`
cask_info = JSON.parse(cask_info_response)

cask_info.flat_map do |cask|
cask_info["casks"].flat_map do |cask|
cask.dig("depends_on", "formula")
end.compact.uniq
rescue JSON::ParserError => e
Expand Down
2 changes: 1 addition & 1 deletion lib/bundle/locker.rb
Expand Up @@ -87,7 +87,7 @@ def lock(entries, global: false, file: nil, no_lock: false)

def brew_list_info
@brew_list_info ||= begin
name_bottles = JSON.parse(`brew info --json=v1 --installed --quiet`)
name_bottles = JSON.parse(`brew info --json=v2 --installed --quiet`)
.each_with_object({}) do |f, hash|
bottle = f["bottle"]["stable"]
bottle&.delete("rebuild")
Expand Down
19 changes: 13 additions & 6 deletions spec/bundle/cask_dumper_spec.rb
Expand Up @@ -57,8 +57,8 @@
before do
allow(described_class)
.to receive(:`)
.with("brew info --cask foo --json=v1")
.and_return("[{\"depends_on\":{}}]")
.with("brew info --cask foo --json=v2")
.and_return("{\"formulae\":[],\"casks\":[]")
end

it "returns an empty array" do
Expand All @@ -70,8 +70,8 @@
before do
allow(described_class)
.to receive(:`)
.with("brew info --cask foo --json=v1")
.and_return("Error: somethng from cask!")
.with("brew info --cask foo --json=v2")
.and_return("Error: something from cask!")
end

it "returns an empty array" do
Expand All @@ -80,11 +80,18 @@
end

context "when multiple casks have the same dependency" do
let(:json_output) do
"{" \
"\"formulae\":[]," \
"\"casks\":[{\"depends_on\":{\"formula\":[\"baz\",\"qux\"]}},{\"depends_on\":{\"formula\":[\"baz\"]}}]" \
"}"
end

before do
allow(described_class)
.to receive(:`)
.with("brew info --cask foo bar --json=v1")
.and_return("[{\"depends_on\":{\"formula\":[\"baz\",\"qux\"]}},{\"depends_on\":{\"formula\":[\"baz\"]}}]")
.with("brew info --cask foo bar --json=v2")
.and_return(json_output)
end

it "returns an array of unique formula dependencies" do
Expand Down
2 changes: 1 addition & 1 deletion spec/bundle/locker_spec.rb
Expand Up @@ -70,7 +70,7 @@
allow(locker).to receive(:lockfile).and_return(lockfile)
allow(brew_options).to receive(:deep_stringify_keys)
.and_return("restart_service" => true)
allow(locker).to receive(:`).with("brew info --json=v1 --installed --quiet").and_return <<~EOS
allow(locker).to receive(:`).with("brew info --json=v2 --installed --quiet").and_return <<~EOS
[
{
"name":"mysql",
Expand Down

0 comments on commit b0aed0a

Please sign in to comment.