Skip to content

API: supply additional data for requirements#7105

Merged
MikeMcQuaid merged 1 commit intoHomebrew:masterfrom
EricFromCanada:json-requirements
Mar 4, 2020
Merged

API: supply additional data for requirements#7105
MikeMcQuaid merged 1 commit intoHomebrew:masterfrom
EricFromCanada:json-requirements

Conversation

@EricFromCanada
Copy link
Copy Markdown
Member

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Adds additional fields to the "requirements" section of the formula JSON API; specifically:

  • for :maximum_macos, changes name to "maximum_macos"
  • adds version which can have a value for "macos", "maximum_macos", "java", and "xcode" requirements, and is null for others
  • adds contexts which is a list of one or both "build" and "test" and an empty list otherwise
  • also adds an inspect method to macos_requirement.rb so it includes the comparator and version

Merging this will allow fixing the display of e.g. macOS requirements for pages like https://formulae.brew.sh/formula/valgrind which don't include any version information.

Example output
# macos run version
$ brew info --json go | jq ".[0].requirements"
[
  {
	"name": "macos",
	"cask": null,
	"download": null,
	"version": "10.11",
	"contexts": []
  }
]

# maximum_macos run version
$ brew info --json valgrind | jq ".[0].requirements"
[
  {
	"name": "maximum_macos",
	"cask": null,
	"download": null,
	"version": "10.13",
	"contexts": []
  }
]

# maximum_macos build version
$ brew info --json gcc@5 | jq ".[0].requirements"
[
  {
	"name": "maximum_macos",
	"cask": null,
	"download": null,
	"version": "10.13",
	"contexts": [
	  "build"
	]
  }
]

# xcode build
$ brew info --json llvm | jq ".[0].requirements"
[
  {
	"name": "xcode",
	"cask": null,
	"download": null,
	"version": null,
	"contexts": [
	  "build"
	]
  }
]

# xcode version
$ brew info --json rswift | jq ".[0].requirements"
[
  {
	"name": "xcode",
	"cask": null,
	"download": null,
	"version": "10.0",
	"contexts": []
  }
]

# xcode version build
$ brew info --json plank | jq ".[0].requirements"
[
  {
	"name": "xcode",
	"cask": null,
	"download": null,
	"version": "11.3",
	"contexts": [
	  "build"
	]
  }
]

# xcode versions for run & build
$ brew info --json needle | jq ".[0].requirements"
[
  {
	"name": "xcode",
	"cask": null,
	"download": null,
	"version": "10.0",
	"contexts": [
	  "build"
	]
  },
  {
	"name": "xcode",
	"cask": null,
	"download": null,
	"version": "6.0",
	"contexts": []
  }
]

# xcode version for build & test
$ brew info --json sourcedocs | jq ".[0].requirements"
[
  {
	"name": "xcode",
	"cask": null,
	"download": null,
	"version": "10.3",
	"contexts": [
	  "build",
	  "test"
	]
  }
]

# java version
$ brew info --json blazegraph | jq ".[0].requirements"
[
  {
	"name": "java",
	"cask": "adoptopenjdk",
	"download": null,
	"version": "1.7+",
	"contexts": []
  }
]

# java version for build & test
$ brew info --json infer | jq ".[0].requirements"
[
  {
	"name": "java",
	"cask": "homebrew/cask-versions/adoptopenjdk8",
	"download": null,
	"version": "1.8",
	"contexts": [
	  "build",
	  "test"
	]
  }
]

Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! One tiny nit.

Comment thread Library/Homebrew/formula.rb Outdated
end

hsh["requirements"] = requirements.map do |req|
req.name.prepend("maximum_") if req.try(:comparator) == "<="
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better ❤️

@MikeMcQuaid MikeMcQuaid merged commit 0d7100e into Homebrew:master Mar 4, 2020
@MikeMcQuaid
Copy link
Copy Markdown
Member

Nice work as usual @EricFromCanada!

@EricFromCanada EricFromCanada deleted the json-requirements branch March 4, 2020 14:34
@lock lock bot added the outdated PR was locked due to age label Apr 4, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated PR was locked due to age

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants