Skip to content
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

formula_creator: commented examples for ruby dependencies #18190

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Library/Homebrew/formula_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ def install
virtualenv_install_with_resources
<% elsif @mode == :ruby %>
ENV["GEM_HOME"] = libexec

# Install dependencies declared in a Gemfile.lock
# system "bundle", "config", "set", "without", "development", "test"
# system "bundle", "install"

# Install dependencies declared as resources
Copy link
Member

Choose a reason for hiding this comment

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

How often is this the case for new Ruby formulae? Seems like a Gemfile.lock is pretty standard now?

Copy link
Member Author

Choose a reason for hiding this comment

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

None in last 5 new Ruby formulae, but yes in last 10:

  1. pedump 0.6.10 (new formula) homebrew-core#173274 - Gemfile.lock
  2. ronn-ng 0.10.1 (new formula) homebrew-core#172077 - via gem install
  3. deadfinder 1.3.4 (new formula) homebrew-core#161231 - Gemfile.lock
  4. sugarjar 1.0.1 (new formula) homebrew-core#157910 - Gemfile.lock
  5. haiti 1.5.0 (new formula) homebrew-core#152307 - haiti: use bundler instead of resources homebrew-core#161343
  6. wpscan 3.8.24 (new formula) homebrew-core#136553 - resources, but dropped due to license
  7. dexter 0.4.3 (new formula) homebrew-core#126915 - resources
  8. opal 1.7.3 (new formula) homebrew-core#126482 - via gem install

May also need to decide if gem install should be valid way of installing dependencies, or we should require --ignore-dependencies.

Copy link
Member

Choose a reason for hiding this comment

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

This had a Gemfile.lock, I wonder why we didn't use it. Feels like it should be an audit failure if it has one and we don't use it.

gem install seems like it could be valid, then, if we need version pinning although personally I'd tend towards just saying we always use bundle install (given all of these have Gemfiles)

# resources.each do |r|
# r.fetch
# system "gem", "install", r.cached_download, "--ignore-dependencies",
# "--no-document", "--install-dir", libexec
# end

system "gem", "build", "\#{name}.gemspec"
system "gem", "install", "\#{name}-\#{@version}.gem"
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
system "gem", "install", "\#{name}-\#{@version}.gem"
system "gem", "install", "--ignore-dependencies", "\#{name}-\#{@version}.gem"

Copy link
Member

Choose a reason for hiding this comment

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

This feels weird. Why is it needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

In order to make sure one of the previous commands (bundle install or resources) handles the dependencies.

Otherwise, for formulae with dependencies but without Gemfile.lock, this will install the latest gems and makes it less reproducible/checksummed.

It is in our documentation:

system "gem", "install", "--ignore-dependencies", "<project>-#{version}.gem"

Copy link
Member

Choose a reason for hiding this comment

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

Otherwise, for formulae with dependencies but without Gemfile.lock, this will install the latest gems and makes it less reproducible/checksummed.

This is true but I wonder how much of a problem this is for us in reality, particularly if we just move to using bundle install entirely instead (which I trust to handle the edge-cases here more than gem install).

I think the ideal outcome here (but not blocking this PR on that) would be to run bundle install and actually include the Gemfile.lock in e.g. the bottle/manifest/tab/prefix/etc.

We could take a similar approach for other packaging systems, too, and it avoids all the shit manual work required with resources.

bin.install libexec/"bin/\#{name}"
Expand Down
3 changes: 2 additions & 1 deletion docs/Formula-Cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ The preferred mechanism for installing gem dependencies is to use `bundler` with

```ruby
ENV["GEM_HOME"] = libexec
system "bundle", "install", "--without", "development"
system "bundle", "config", "set", "without", "development", "test"
system "bundle", "install"
```

From there, you can build and install the project itself:
Expand Down