Mechanism to dynamically add HOMEBREW.* vars to 'env -i' command string in 'bin/brew'

This commit is contained in:
Doug Hazell 2017-02-19 02:12:46 +00:00
parent adc43466a6
commit 5d1576784a
2 changed files with 26 additions and 8 deletions

View File

@ -0,0 +1,11 @@
#!/usr/bin/env ruby
ENV.keys.each do |key|
if key =~ /^HOMEBREW.*/
# Remove any HOMEBREW.* vars containing white-space which causes a problem for "env -i" command via string.
#
# (Any user supplied HOMEBREW.* vars with valid white-space need to be hard-coded in 'bin/brew')
#
puts "#{key}=#{ENV[key]}" unless ENV[key].split(' ').length > 1
end
end

View File

@ -46,15 +46,22 @@ HOMEBREW_LIBRARY="$HOMEBREW_REPOSITORY/Library"
if [[ -n "$HOMEBREW_ENV_FILTERING" ]] if [[ -n "$HOMEBREW_ENV_FILTERING" ]]
then then
env -i \
HOME="$HOME" \ homebrew_vars=$("$HOMEBREW_LIBRARY/Homebrew/utils/homebrew_vars.rb")
cmd_str="/usr/bin/env -i \
HOME=$HOME \
PATH=/usr/bin:/bin:/usr/sbin:/sbin \ PATH=/usr/bin:/bin:/usr/sbin:/sbin \
TERM="$TERM" \ TERM=$TERM \
HOMEBREW_BREW_FILE="$HOMEBREW_BREW_FILE" \ HOMEBREW_BREW_FILE=$HOMEBREW_BREW_FILE \
HOMEBREW_PREFIX="$HOMEBREW_PREFIX" \ HOMEBREW_PREFIX=$HOMEBREW_PREFIX \
HOMEBREW_REPOSITORY="$HOMEBREW_REPOSITORY" \ HOMEBREW_REPOSITORY=$HOMEBREW_REPOSITORY \
HOMEBREW_LIBRARY="$HOMEBREW_LIBRARY" \ HOMEBREW_LIBRARY=$HOMEBREW_LIBRARY \
/bin/bash "$HOMEBREW_LIBRARY/Homebrew/brew.sh" "$@" $homebrew_vars \
/bin/bash $HOMEBREW_LIBRARY/Homebrew/brew.sh $@"
command $cmd_str
else else
source "$HOMEBREW_LIBRARY/Homebrew/brew.sh" source "$HOMEBREW_LIBRARY/Homebrew/brew.sh"
fi fi