-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add uses from macos #6162
Add uses from macos #6162
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done, Gabriel! And thanks for the comprehensive tests!
I'm away on a work trip right now but will review this when I get the chance. Thanks! |
FYI, you may want to implement this feature in head do
uses_from_mac "python"
end |
@xu-cheng wrote… #6150 (comment)
|
These are both good suggestions. Gabriel, would you be up for moving the definition of |
I suggest keeping the same syntax as uses_from_macos "m4" => :build
uses_from_macos "gpatch" => [:build, :test], :before => :mojave |
Agreed 👍 |
Yeah, sure. |
@sjackman Actually, i was wondering if it is really necessary, because |
Ah, |
Thank you, Gabriel! Sorry that I hadn't given you the right info in the first place. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start on this @gkpacker, thanks!
class Formula | ||
class << self | ||
def uses_from_macos(dep, **args) | ||
depends_on(dep) if add_mac_dependency?(args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with @xu-cheng this should should tags like :test
and :build
and pass them through accordingly and it should be on SoftwareSpec
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If dep
is a hash, I think that does happen with the current code (untested).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it already works with tags, i'll add some specs for it
require "formula" | ||
|
||
describe Formula do | ||
describe "#uses_from_macos" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work on the tests 👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent first contribution, Gabriel! I hope there are more to come. 🌟
|
||
class SoftwareSpec | ||
def uses_from_macos(deps, **args) | ||
depends_on(deps) if add_mac_dependency?(args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current code will fail to handle uses_from_macos "foo" => :build, :before => :el_capitan
. As in this case,
deps
is { "foo" => :build, :before => : el_capitan }
, while args
is {}
I suggest something like the following. Though you may consider to choose better variable names.
depends_on(deps) if add_mac_dependency?(args) | |
if deps.is_a?(Hash) | |
dep, dep_tags = deps.first | |
deps.delete(dep) | |
depends_on(dep => dep_tags) if add_mac_dependency?(deps) | |
else | |
depends_on(deps) if add_mac_dependency?(args) | |
end |
Further, I suggest you should test all four cases in the test cases.
uses_from_macos "foo"
uses_from_macos "foo" , :before => :el_capitan
uses_from_macos "foo" => :build
uses_from_macos "foo" => :build, :before => :el_capitan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, @xu-cheng! I suggest…
def uses_from_macos(dep, **args)
if dep.is_a?(Hash)
args = dep
dep = Hash[*args.shift]
end
depends_on(dep) if add_mac_dependency?(args)
end
Further, I suggest you should test all four cases in the test cases.
Good suggestion!
return false if args[:before] && OS::Mac.version >= args[:before] | ||
|
||
true | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my understanding, uses_from_macos "foo"
(i.e. without version args) should not add foo
as dependency on macOS. However, the current logic does the opposite.
|
||
class SoftwareSpec | ||
def uses_from_macos(deps, **args) | ||
depends_on(deps) if add_mac_dependency?(args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, @xu-cheng! I suggest…
def uses_from_macos(dep, **args)
if dep.is_a?(Hash)
args = dep
dep = Hash[*args.shift]
end
depends_on(dep) if add_mac_dependency?(args)
end
Further, I suggest you should test all four cases in the test cases.
Good suggestion!
|
||
return false if args[:before] && OS::Mac.version >= args[:before] | ||
|
||
true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my understanding, uses_from_macos "foo" (i.e. without version args) should not add foo as dependency on macOS. However, the current logic does the opposite.
true | |
!args.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, actually i think it makes sense to have this behaviour only on Linux, since it uses from macos. Without any version specification it seems that the method uses from macos unconditionally, so:
On MacOS
uses_from_macos "foo" # always add foo as dep in macos
uses_from_macos "foo", after: :sierra # add foo as dep only after macos sierra
On Linux
uses_from_macos "foo" # Does nothing, since we're adding a macos dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact it's the exact opposite of that. uses_from_macos "foo", after: :sierra
means that on macOS Sierra and later we use foo
provided by macOS operating system, and so we do not need to to use the brewed dependency. Before macOS Sierra we need to install the brewed dependency. On Linux we always install the dependency.
On macOS
uses_from_macos "foo" # Never add foo as dep in macos
uses_from_macos "foo", after: :sierra # add foo as dep only before macos sierra
On Linux
uses_from_macos "foo" # Always add foo as dep on Linux
@@ -1,6 +1,8 @@ | |||
# frozen_string_literal: true | |||
|
|||
class SoftwareSpec | |||
undef uses_from_macos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this, i was troubleshooting a misterious spec that was failling because it requires linux and it wasn't mocking with OS.linux?
. Saw this on other files and added here...
expect(spec.deps.last.tags).to include(:head) | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it shouldn't be on os/linux/
anyway, since it's the default behaviour
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these tests fail on macOS, then they do need to be in os/linux/
. If they pass on macOS, then yeah, they could be moved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the :needs_linux
tag instead for (the only) Linux specific tests. The test file folder locations should match the source file definitions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mocking OS.linux
shouldn't be enough for this case? It was running the extended uses_from_macos
version even returning true on OS.linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be sufficient but it's not how we've been doing things with other tests. Would appreciate consistency for now and could change elsewhere in a follow-up PR?
Library/Homebrew/software_spec.rb
Outdated
@@ -170,6 +170,12 @@ def depends_on(spec) | |||
add_dep_option(dep) if dep | |||
end | |||
|
|||
def uses_from_macos(deps, **_args) | |||
deps.is_a?(Hash) && deps = Hash[*deps.shift] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deps.is_a?(Hash) && deps = Hash[*deps.shift] | |
deps = Hash[*deps.shift] if deps.is_a?(Hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor style nit, otherwise this PR looks good to me!
expect(spec.deps.last.tags).to include(:head) | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these tests fail on macOS, then they do need to be in os/linux/
. If they pass on macOS, then yeah, they could be moved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Three CI failures on Linux to check out:
https://dev.azure.com/Homebrew/Homebrew/_build/results?buildId=10713&view=logs |
@sjackman How can i fix if can't run them locally? |
Oh, sorry, dind't checked the logs |
I use Docker for macOS to run |
@sjackman Another few questions:
|
The CI seems stalled. To rerun it, rebase the PR onto |
57d20a1
to
9fa8dc5
Compare
@sjackman Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this work, Gabriel!
Merged! Thank you for your first contribution to Homebrew, Gabriel! 🥇 |
Great work here @gkpacker 🎉 A suggested next PR would be to expose this information in brew/Library/Homebrew/formula.rb Lines 1590 to 1657 in 7c5f71e
|
Another suggested next PR would be to revive this PR to add |
Homebrew/brew 2.1.5 is released, which includes this PR and the DSL command |
Fixes #6150
Add
uses_from_macos
method:On Linux:
depends_on
, ignoring OS version specificationsOn MacOS:
depends_on
only if system meets dependency os requirementsUsage
Add specified dependency based on MacOS version
brew style
with your changes locally?brew tests
with your changes locally?