Brew: The `system` method in formulae incompatible with Ruby `system`

Created on 8 Sep 2020  路  3Comments  路  Source: Homebrew/brew

Bug report

  • [x] ran brew update and can still reproduce the problem? n/a
  • [x] ran brew doctor, fixed all issues and can still reproduce the problem? n/a
  • [x] ran brew config and brew doctor and included their output with your issue? n/a

What you were trying to do (and why)

In the install block of my formula, I was trying to pass environment variables like so:

def install
  system({ "FOO" => "bar" }, "env")
end
## What happened (include command output) A Ruby exception
Command output
Error: An exception occurred within a child process:
  TypeError: no implicit conversion of Hash into String
  
## What you expected to happen I've expected `system` to work the same way it does in Ruby: to accept a Hash as the 1st argument and apply the values as environment variables to the process https://ruby-doc.org/core-2.7.1/Kernel.html#method-i-system ## Step-by-step reproduction instructions (by running `brew` commands) 1. Add `system` call to `myformula.rb` 2. `brew install myformula` ## Output of `brew config` and `brew doctor` commands
HOMEBREW_VERSION: 2.4.16-144-g2314ddf
ORIGIN: https://github.com/Homebrew/brew
HEAD: 2314ddf9f5475b63d5e37d398d0a5990e0311afd
Last commit: 4 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 40d76cc32fa516569e82cb8907c9ec382fb38cf1
Core tap last commit: 16 minutes ago
Core tap branch: update-gh.rb-1599554327
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_EDITOR: vim
HOMEBREW_MAKE_JOBS: 16
HOMEBREW_NO_AUTO_UPDATE: set
HOMEBREW_NO_INSTALL_CLEANUP: set
CPU: 16-core 64-bit kabylake
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
Clang: 11.0 build 1103
Git: 2.28.0 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl
Java: 1.8.0_232-zulu-8.42.0.23
macOS: 10.15.6-x86_64
CLT: 1103.0.32.62
Xcode: 11.7

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Homebrew/homebrew-core is not on the master branch.

Check out the master branch by running:
  git -C "$(brew --repo homebrew/core)" checkout master

Warning: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
  [email protected]
  [email protected]

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  docker

Warning: You have uncommitted modifications to Homebrew/brew.
If this is a surprise to you, then you should stash these modifications.
Stashing returns Homebrew to a pristine state but can be undone
should you later need to do so for some reason.
  cd /usr/local/Homebrew && git stash && git clean -d -f

Uncommitted files:
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/patchelf-1.1.1/lib/patchelf.rb
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/patchelf-1.1.1/lib/patchelf/cli.rb
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/patchelf-1.1.1/lib/patchelf/exceptions.rb
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/patchelf-1.1.1/lib/patchelf/helper.rb
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/patchelf-1.1.1/lib/patchelf/logger.rb
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/patchelf-1.1.1/lib/patchelf/mm.rb
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/patchelf-1.1.1/lib/patchelf/patcher.rb
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/patchelf-1.1.1/lib/patchelf/saver.rb
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/patchelf-1.1.1/lib/patchelf/version.rb

You have uncommitted modifications to Homebrew/homebrew-core.
If this is a surprise to you, then you should stash these modifications.
Stashing returns Homebrew to a pristine state but can be undone
should you later need to do so for some reason.
  cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core && git stash && git clean -d -f

Uncommitted files:
   M Formula/gh.rb
  ?? steps_output.txt

Warning: Homebrew's sbin was not found in your PATH but you have installed
formulae that put executables in /usr/local/sbin.
Consider setting the PATH for example like so:
  echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc

help wanted

All 3 comments

While we have a think about this in the mean time our DSL for this is:

with_env(FOO: "bar") do
  system "env"
end

or simply:

ENV["FOO"] = "bar"
system "env"

@MikeMcQuaid Thanks the the fast response and the workarounds! I did not know about with_env. I would prefer that since ENV["FOO"] = "..." can inadvertently affect subsequent processes.

Might all this warrant a mention in https://docs.brew.sh/Formula-Cookbook? I did not find instructions to set environment variables anywhere.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thiagodebastos picture thiagodebastos  路  4Comments

kirk86 picture kirk86  路  3Comments

VagelisD picture VagelisD  路  3Comments

fooness picture fooness  路  4Comments

DomT4 picture DomT4  路  3Comments