-
-
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
SimulateSystem
improvements
#13599
Merged
Merged
SimulateSystem
improvements
#13599
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fa384b0
Simplify `SimulateSystem` usage
Rylan12 34a1bc6
Use `SimulateSystem` for `ignore_missing_libraries`
Rylan12 91cf9f2
Use `SimulateSystem` for `uses_from_macos` deps
Rylan12 4cc0e85
Rename `treat_as_*?` to `simulating_or_running_on_*?`
Rylan12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
# This logic will need to be more nuanced if this file includes more than `uses_from_macos`. | ||
if OS.mac? || Homebrew::EnvConfig.simulate_macos_on_linux? | ||
require "extend/os/mac/software_spec" | ||
elsif OS.linux? | ||
require "extend/os/linux/software_spec" | ||
end | ||
require "extend/os/linux/software_spec" if OS.linux? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,12 +162,25 @@ def depends_on(spec) | |
add_dep_option(dep) if dep | ||
end | ||
|
||
def uses_from_macos(spec, _bounds = {}) | ||
spec = [spec.dup.shift].to_h if spec.is_a?(Hash) | ||
def uses_from_macos(deps, bounds = {}) | ||
if deps.is_a?(Hash) | ||
bounds = deps.dup | ||
deps = [bounds.shift].to_h | ||
end | ||
|
||
@uses_from_macos_elements << deps | ||
|
||
@uses_from_macos_elements << spec | ||
# Linux simulating macOS. Assume oldest macOS version. | ||
return if Homebrew::EnvConfig.simulate_macos_on_linux? && !bounds.key?(:since) | ||
Comment on lines
+173
to
+174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes me wonder about whether this logic should be in |
||
|
||
# macOS new enough for dependency to not be required. | ||
if Homebrew::SimulateSystem.treat_as_macos? | ||
current_os = MacOS::Version.from_symbol(Homebrew::SimulateSystem.current_os) | ||
since_os = MacOS::Version.from_symbol(bounds[:since]) if bounds.key?(:since) | ||
return if current_os >= since_os | ||
end | ||
|
||
depends_on(spec) | ||
depends_on deps | ||
end | ||
|
||
def uses_from_macos_names | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is another option
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 I prefer the original because if we aren't simulating Linux but are actually on it, we still need to return true. I can see the word "simulate" being misleading
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.
Hmm, I really don't understand this then I think 😅. Why not do a
OS.linux?
check?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 we do this:
Then the condition will be true when we're simulating macOS on Linux (because
Homebrew::SimulateSystem.os
will be:macos
(or a specific version) andOS.linux?
will still be true). We only want this condition to be true when we're simulating Linux or we are on Linux and not simulating anything. So, the full check needs to be:The
Homebrew::SimulateSystem.treat_as_linux?
method is just a shortcut for this longer conditional.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 feel like we want some sort of
OS.linux_no_really_not_simulated?
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.
TBH, I don't see why we don't want
OS.mac?
andOS.linux?
to lie when we ask it to (withHOMEBREW_SIMULATE_MACOS_ON_LINUX
, or evenHOMEBREW_SIMULATE_LINUX_ON_MACOS
). But I'll admit to not having thought about this very hard or looked for corner cases.I also don't really have a problem with
#simulating_linux?
being true even if the system really is running Linux, and it's not a simulation.Are there cases where we want to distinguish between a machine that is running Linux with another machine running macOS, but the developer wants to trick
brew
into thinking its running 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.
One instance might be that trying to
brew install
anything on macOS while simulating Linux might lead to a bad time. But do we really need guardrails here for users in this position? What if they actually really wanted tobrew install
some Linux software on macOS (perhaps for testing purposes)?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.
Probably not...? The only way for a user to activate any simulation stuff is through
HOMEBREW_SIMULATE_MACOS_ON_LINUX
, and I think it seems pretty clear that using that variable may cause problems if you don't know what you're doing. If we get weird bug reports where people are trying to set that unnecessarily, we can add a warning or undocumented it or something.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 which case it seems to me that we should be fine with
#simulating_linux?
, no? Because we don't really need to distinguish between a real Linux machine and one only pretending to be 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.
I don't think they necessarily should but the argument for them doing so is that it's useful to be able to e.g. generate information for macOS on Linux machines and, less so but still useful, to do Linux on macOS.
I think the differentiation from me is "behaviour like we need to on Linux based on the underlying system" vs. "behaviour that differs on macOS on Linux and we want to generate data (e.g. dependency trees) on one OS from the other".
Yeh, specifically this: we shouldn't allow installing in this case. We can either e.g. prevent installation or opt-in to the commands/actions that we want to allow (e.g.
brew deps
,brew info
, etc.)I'm fine with behaviour, it's just the naming that's weird to me.
simulating_or_running_on_linux?
is a bit of a mouthful but more accurately describes what's going on. Alternatively,SimulateSystem.linux?
is generic enough that it doesn't imply that you're not on Linux right now.