Skip to content

formula_creator: add deny network for ruby - #23763

Merged
MikeMcQuaid merged 1 commit into
mainfrom
formula_creator-ruby
Sep 4, 2026
Merged

formula_creator: add deny network for ruby#23763
MikeMcQuaid merged 1 commit into
mainfrom
formula_creator-ruby

Conversation

@cho-m

@cho-m cho-m commented Sep 3, 2026

Copy link
Copy Markdown
Member

Examples for handling network access of Ruby formulae at:

Based on https://guides.rubygems.org/caching-and-vendoring/

Some extra notes:

  • Using bundle config to preserve config across both fetch & build phase. Could consider making this part of superenv / build environment, but would need to check on usage (and will need a way to avoid for stuff like sorbet-static which currently uses prebuilt binaries)
  • BUNDLE_PATH=.bundle is Bundler 5 default so can be removed in the future. Currently needed as RubyGems still creates some bin files for main package even when --no-install is used.

  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Copilot AI balanced review requested due to automatic review settings September 3, 2026 18:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

馃煝 Approval recommended

The implementation matches the staged fetch/build lifecycle and includes focused template coverage.

Pull request overview

Updates Ruby formula templates to support network-isolated builds.

Changes:

  • Cache Bundler dependencies during fetch.
  • Install cached gems locally with network access denied.
  • Add template-generation coverage for Ruby mode.
File summaries
File Description
Library/Homebrew/formula_creator.rb Adds offline Ruby dependency handling.
Library/Homebrew/test/formula_creator_spec.rb Verifies generated Ruby templates.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

馃挕 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@MikeMcQuaid MikeMcQuaid left a comment

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.

Lovely!

Comment on lines +245 to +247
system "bundle", "config", "set", "force_ruby_platform", "true"
system "bundle", "config", "set", "version", "system" # Avoid installing Bundler into the keg
system "bundle", "config", "set", "without", "development test"

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.

Follow-up: wonder if we can/should use default env instead for any of these.

@cho-m cho-m Sep 4, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

version and without are probably safe.

force_ruby_platform does break some packages that only provide native gems. Main one is sorbet-static which currently impacts ruby-lsp.

Though it may be better to require formula to configure the inverse so that it is more obvious when a prebuilt is used:

system "bundle", "config", "set", "force_ruby_platform", "false"

EDIT: for ruby-lsp, I think it doesn't actually need sorbet-static but Bundler/RubyGem limitation requires resolving development dependencies even when we set without. We also hit this in brew.

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.

Though it may be better to require formula to configure the inverse so that it is more obvious when a prebuilt is used:

Good idea 馃憤馃徎

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Sep 4, 2026
Merged via the queue into main with commit 60fa495 Sep 4, 2026
59 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the formula_creator-ruby branch September 4, 2026 08:02
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.

4 participants