Skip to content

How to set ENV based on cmd output in install #4887

Discussion options

You must be logged in to vote

Hi Tom, you can use backticks to capture command output (you may be familiar with this in shell, but this is also a Ruby-ism):

ENV["RUSTFLAGS"] = `pkg-config --libs vips`.chomp # sets RUSTFLAGS in the environment
system "cargo", "install", "--features", "libvips", "--locked", "--path", "." # will use RUSTFLAGS set above

One similar example of this in existing formula is https://github.com/Homebrew/homebrew-core/blob/a1640c6c17a2f4bc14336d364f1989da8631e1c8/Formula/x/xsd.rb#L52.

You can generally use some other techniques for capturing command output in Ruby, including ::capture2, ::capture2e, and/or ::capture3 in Open3.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@themissingcow
Comment options

Answer selected by themissingcow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants