Skip to content

Fix incorrect depends_on: macos serialization in JSON API for Linux variations#22137

Merged
MikeMcQuaid merged 8 commits intoHomebrew:mainfrom
hangone:fix/remove-implicit-macos-dependency
May 7, 2026
Merged

Fix incorrect depends_on: macos serialization in JSON API for Linux variations#22137
MikeMcQuaid merged 8 commits intoHomebrew:mainfrom
hangone:fix/remove-implicit-macos-dependency

Conversation

@hangone
Copy link
Copy Markdown
Contributor

@hangone hangone commented May 4, 2026

  • Fix the JSON API incorrectly returning depends_on: macos for Linux variations.
$ curl -s https://formulae.brew.sh/api/cask/gcloud-cli.json | jq .variations.x86_64_linux.depends_on
{
  "macos": {
    ">=": [
      "10.15"
    ]
  }
}
  • Fix MacOSRequirement#to_h to return {} for bare depends :macos (no version specified) instead of {">=" => [""]} for Fix cask page rendering macOS requirements formulae.brew.sh#2187
  • Fix CaskStructGenerator.process_depends_on to handle empty hash from bare depends :macos, correctly serializing it as :any
  • Update test fixtures to remove the now-unnecessary implicit macOS dependency
  • Add tests for bare depends :macos and Linux variation behavior

According to #22080, formulas and casks that do not specify depends_on are treated as being supported on both macOS and Linux. But for depends_on :macos(#22006), should we default to displaying macOS >= HOMEBREW_MACOS_OLDEST_ALLOWED, or simply retain macOS?


  • 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? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you written new tests (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes. Non-maintainers may only have one AI-assisted/generated PR open at a time.

Claude Code for code, I review and create the PR.


Copilot AI review requested due to automatic review settings May 4, 2026 19:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the previously-added implicit depends_on macos: ">= …" from casks that don’t explicitly declare a macOS dependency, and fixes the API serialization/parsing path so that a bare depends_on :macos round-trips cleanly (including variations).

Changes:

  • Remove the implicit macOS dependency injection for casks without an explicit depends_on :macos.
  • Change MacOSRequirement#to_h so a bare macOS requirement serializes as {} (not {">=" => [""]}) and teach CaskStructGenerator.process_depends_on to interpret that as :any.
  • Update cask JSON fixtures and add/extend specs for bare depends_on :macos and Linux-variation behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Library/Homebrew/cask/dsl.rb Removes the private helper that injected an implicit macOS dependency into casks.
Library/Homebrew/cask/cask.rb Stops calling the removed implicit-dependency helper during cask refresh.
Library/Homebrew/requirements/macos_requirement.rb Adjusts macOS requirement hash serialization for the bare/no-version case.
Library/Homebrew/api/cask/cask_struct_generator.rb Handles empty/bare macOS requirement hashes when reconstructing depends_on args.
Library/Homebrew/test/cask/dsl_spec.rb Adds an assertion for the new bare-macos to_h serialization behavior.
Library/Homebrew/test/api/cask/cask_struct_generator_spec.rb Adds coverage for process_depends_on converting bare macOS requirements to :any.
Library/Homebrew/test/cask/cask_spec.rb Adds a spec asserting Linux variations don’t include a depends_on entry.
Library/Homebrew/test/support/fixtures/cask/everything.json Updates expected API fixture output to remove the implicit macOS dependency.
Library/Homebrew/test/support/fixtures/cask/everything-with-variations.json Same as above, for the variations fixture.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Library/Homebrew/test/cask/cask_spec.rb Outdated
Comment thread Library/Homebrew/test/api/cask/cask_struct_generator_spec.rb
@hangone hangone marked this pull request as draft May 4, 2026 19:37
@rexmhall09
Copy link
Copy Markdown
Contributor

Nice work, I was thinking about doing this myself. I think the test failures are coming from filter_runners falling back to RUNNERS.dup after removing the implicit macOS dependency. That lets Linux runners leak into cases that should still default to macOS-only CI. A decent fix might making the fallback MACOS_RUNNERS.dup instead, then keep adding Linux runners later only when cask.supports_linux? is true.

Copy link
Copy Markdown
Member

@Rylan12 Rylan12 left a comment

Choose a reason for hiding this comment

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

I haven't looked into this yet, but I will when I have a sec.

which inadvertently forced macos >= HOMEBREW_MACOS_OLDEST_ALLOWED on all casks lacking an explicit macOS dependency

This was not inadvertently added, it's what was supposed to happen. I'm not up to date on the newest cask/Linux support, so not sure how to handle this. @SMillerDev or @MikeMcQuaid, can you clarify where we stand currently Linux/cask support wise

@MikeMcQuaid
Copy link
Copy Markdown
Member

@Rylan12 We're in a non-ideal state:

  • some casks work on macOS and some work on Linux
  • it's not 100% obvious which are which
  • we have some loose heuristics for this as well as depends_on :macos (without a version specifier), cask.supports_macos? and cask.supports_linux?
  • if we remove the implicit versioned dependency we should ensure we add one or more of these instead

@SMillerDev
Copy link
Copy Markdown
Member

This was our initial stopgap to prevent adding a depends_on to every cask when we first opened it up to Linux.
With the work that Sam has done to add those dependencies now, I don't think we need that solution to imply a macOS dependency anymore.

I do think it would be beneficial to make a public note of this change in the default somewhere. Blog, social media, pinned discussion or otherwise because it will cause some confusion for tap owners.

Copy link
Copy Markdown
Member

@Rylan12 Rylan12 left a comment

Choose a reason for hiding this comment

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

API-related code looks good to me.

I'll let someone else make the final call on whether to remove the injected dependency or not, but it seems like removing it is appropriate given that we've mass-added depends_on :macos

A few comments/questions, but pretty much good to go

Comment thread Library/Homebrew/dev-cmd/generate-cask-ci-matrix.rb
Comment thread Library/Homebrew/test/cask/cask_spec.rb Outdated
Comment thread Library/Homebrew/test/cask/cask_spec.rb Outdated
@hangone hangone marked this pull request as ready for review May 6, 2026 03:36
@samford
Copy link
Copy Markdown
Member

samford commented May 6, 2026

This was our initial stopgap to prevent adding a depends_on to every cask when we first opened it up to Linux.
With the work that Sam has done to add those dependencies now, I don't think we need that solution to imply a macOS dependency anymore.

...we've mass-added depends_on :macos

To be clear, I've only added depends_on :macos to casks [in homebrew-cask] that don't use depends_on macos: (i.e., specifying a macOS version requirement), so not every macOS-only cask has depends_on :macos. It's not currently possible to add depends_on :macos to casks using depends_on macos: because Cask::DSL::DependsOn.macos= will raise an "Only a single 'depends_on macos' is allowed" error. We need to modify that method to only raise an error when it's called twice with a version requirement, not when a cask uses :macos and a version requirement.

I'm addressing that in #22146. If/when that's merged, I'll go through casks using depends_on macos: that don't support Linux and add depends_on :macos. That will bring us closer to a point where we can assume that casks not using depends_on :macos are OS-independent. However, the real condition should be "cask does not use depends_on :macos or depends_on :linux" but, unlike the formula DSL, depends_on in casks doesn't support a :linux value, so we can't reliably account for OS-independent casks (i.e., forgetting to add depends_on :macos or not adding depends_on :linux because it's unsupported will suggest that a cask is OS-independent even if it isn't). I would be happy to add depends_on :linux support (it should be pretty simple, as we don't specify Linux versions) but some would rather wait until we encounter a Linux-only cask (though apparently that may have already occurred).

It may also be a good idea to finish #22080 before dropping the implicit macOS dependency, though someone correct me if I'm wrong. That is to say, we're updating casks in homebrew/cask but we need audits to help ensure that new casks in homebrew-cask add depends_on :macos when needed (we ran into this issue less than a day after I added depends_on :macos to casks) and to also help third-party taps update their casks.

@MikeMcQuaid
Copy link
Copy Markdown
Member

I would be happy to add depends_on :linux support (it should be pretty simple, as we don't specify Linux versions) but some would rather wait until we encounter a Linux-only cask (though apparently that may have already occurred).

@samford Thanks, that would be great! We've encountered them already but just not in homebrew/cask CC @SMillerDev who can probably point some out.

It may also be a good idea to finish #22080 before dropping the implicit macOS dependency, though someone correct me if I'm wrong.

I'd rather we didn't block PRs on others that are in draft. We have sufficient logic we can use here today. It's not perfect but better than nothing.

Comment thread Library/Homebrew/cask/dsl.rb
@hangone hangone changed the title Remove implicit macos >= dependency from casks without explicit depends_on :macos Fix incorrect depends_on: macos serialization in JSON API for Linux variations May 6, 2026
hangone added 5 commits May 7, 2026 01:03
…serialization

- Remove `add_implicit_macos_dependency` which forced `macos >= 10.15` on
  all casks without an explicit macOS dependency
- Fix `MacOSRequirement#to_h` to return `{}` for bare `depends :macos`
  (no version specified) instead of `{">=" => [""]}`
- Fix `CaskStructGenerator.process_depends_on` to handle empty hash from
  bare `depends :macos`, correctly serializing it as `:any`
- Update test fixtures to remove the now-unnecessary implicit macOS dependency
- Add tests for bare `depends :macos` and Linux variation behavior
- info_spec: local-transmission no longer has macOS requirement in output
- installer_spec: use cask with explicit depends_on macos for requirement stub test
- generate-cask-ci-matrix: fallback to MACOS_RUNNERS.dup instead of
  RUNNERS.dup when no macOS version filter matches, preventing Linux
  runners from leaking into macOS-only cask CI
- info_spec: remove expectations of implicit macOS >= 10.15 requirement
  from casks without explicit depends_on :macos
- installer_spec: use cask with explicit depends_on macos for
  requirement stub test
… variations

Use API.merge_variations to simulate different platforms when checking
that Linux variations don't include macOS dependencies. This ensures the
test works correctly regardless of which platform it runs on.

Also rename test to accurately reflect it only checks for macOS
dependency exclusion, not all depends_on.
@hangone hangone force-pushed the fix/remove-implicit-macos-dependency branch from c4234ea to 60b4f23 Compare May 6, 2026 17:03
@hangone
Copy link
Copy Markdown
Contributor Author

hangone commented May 6, 2026

It appears a circular reference has occurred.

@hangone hangone force-pushed the fix/remove-implicit-macos-dependency branch from ce4dc54 to a09643a Compare May 6, 2026 18:31
@MikeMcQuaid
Copy link
Copy Markdown
Member

Thanks @hangone!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue May 7, 2026
Merged via the queue into Homebrew:main with commit 8bb06ce May 7, 2026
38 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants