brew update: get the latest version of Ruby code before calling Ruby #47380
Conversation
@@ -13,6 +13,8 @@ fi | |||
BREW_FILE_DIRECTORY="$(chdir "${0%/*}" && pwd -P)" | |||
HOMEBREW_BREW_FILE="$BREW_FILE_DIRECTORY/${0##*/}" | |||
|
|||
export HOMEBREW_PREFIX=$(cd $(dirname $(dirname $HOMEBREW_BREW_FILE)) && pwd -P) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be chdir
instead of cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What’s the difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chdir
ensures that the output is sent to /dev/null
(in case of weird shell aliases/settings)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Also note that you can avoid (weird) aliases by prepending a command with \
; e.g.:
$ alias cd=echo
$ cd foo
foo
$ \cd foo
bash: cd: foo: No such file or directory
Some comments:
Some edge cases need to be addressed:
Good work though, I gotta admit I was wrong last time. 🎄 |
for i in $@ | ||
do | ||
case "$i" in | ||
--verbose) HOMEBREW_VERBOSE=1 ;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also accept -v
. This can be a little complicated, because we should support flag like -dv
, which means verbose and debug.
In addition, we need to set HOMEBREW_DEBUG
, HOMEBREW_DEVELOPER
and HOMEBREW_NO_COMPAT
based on flags. They will be used in report
script. Or we could pass all of flags to report
script.
Yeh, makes sense. I was wondering about allowing it to take e.g. SHA1/tap parameters so you can view the output for that case (which would be useful for testing).
You mean
Because we've split out
👍
Yeh, I have been wondering about that case: don't we want to just encourage the users to install the CLT's
Unfortunately I don't think it's possible to ignore interrupts but we can use a
👍
Thanks for the kind words 😊 |
Yeah, I mean shellcheck (the original one is hit by Apple's spell correction)
I'd prefer to installing our own one. The thing is that installing CLT and accepting license requires |
fi | ||
|
||
git_init_if_necessary() { | ||
if [ -z "$(ls .git 2>/dev/null)" ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use [ -d .git ]
to check if .git
exists and is a directory.
I believe I've now addressed everything except these points. @xu-cheng let me know what you think. |
|
||
if [ -z "$(which_git)" ] | ||
then | ||
brew install git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be $HOMEBREW_BREW_FILE install git
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we maybe even want to declare a function or something that means that brew install git
will use the $HOMEBREW_BREW_FILE
as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this stayed the same it's now calling a function.
I still think these should be addressed. Especially, for sudo checker and Xcode/CLT license check. |
Yeh, sorry, I meant that I will be addressing them but was just running out of time so figured I'd get more review of what I'd changed. |
do | ||
case "$i" in | ||
update) shift ;; | ||
--verbose|-v) HOMEBREW_VERBOSE=1 ;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle -v
may not enough. Because we treat -abcd
as -a -b -c -d
. You probably want:
--*) ;;
-*)
for x in $(echo "$i" | grep -o .)
do
case "$x" in
v) HOMEBREW_VERBOSE=1 ;;
*);;
esac
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--verbose|-*v*)
does what we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and handles spaces)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about --v
which is an incorrect flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also --another-flag-contains-v
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get this right, it probably needs to be something like:
case "${i}" in
update) shift ;;
--verbose) HOMEBREW_VERBOSE=1 ;;
--*) : "<reject or ignore>" ;;
-*v*) HOMEBREW_VERBOSE=1 ;;
*) : "<fail?>" ;;
esac
One just has to be careful to put the cases in the right order and a bit more work has to be done if we want to check for other short flags other than -v
.
Per chat, |
then | ||
which_git="$active_developer_dir/usr/bin/git" | ||
fi | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of these fi
is indented too deeply. And it looks as though the indenting of then
is inconsistent in this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @chdiza.
I've updated this with all the comments made. I'd like to know what tests should be made here before we push this (but I'd like to try and avoid "perfect being the enemy of good" given that this will address a lot of update issues for us and the earlier we ship this the easier it'll be to ship e.g. Ruby 2 support eventually). |
I agree that we don't have to be perfect here. But we should still be confident that this hasn't any major issues (like breaking updates completely) as those are difficult to fix once this reaches a significant number of users. I'll try to test drive this and provide a timely review, but given the extent of this change and somewhat limited time next week, don't expect that to happen before the weekend … |
Yep, that's fine. Definitely agree with not rushing through and breaking things. That's one of the reasons why this is (more-or-less) a line-by-line port of the Ruby code into Bash. Obviously the behaviour won't be identical but the flow at least should be. |
your own risk. | ||
EOS | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could add this check to bin/brew
and discard the test in brew.rb
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeh, I guess I didn't want to handle the "check if a file is present in this array" but I guess that's not too much pain to do.
I've addressed all comments and suggestions and added tests to verify we don't accidentally have invalid Bash syntax anywhere. This is ready for some testing and then 🚢ping. Another option for such a drastic change is we could bring back the old Thoughts, @Homebrew/maintainers? |
require "descriptions" | ||
|
||
module Homebrew | ||
def update_bash_report |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the time being, let's prevent users calling this command directly. i.e. adding homebrew developer check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we may want to name the command update-report
or other name without the temporary bash
part. Notice, we cannot change this command's name in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, we should call it update-report
or something similar, but not use a temporary name as changing it afterwards won't be easy, if at all possible.
(Most) comments addressed, tested and pushed. Thanks for all the review, folks. |
This splits
brew update
into two commands:brew update
andbrew report
.brew update
handles:git fetch
the latest version of the code (in parallel) and thengit merge
(orgit rebase
) the latest version and callbrew report
brew report
handles:To accomplish this we've added a basic framework to create Homebrew commands in Bash and pushed a bit of shared logic (e.g. setting
HOMEBREW_PREFIX
) into Bash to be consistent.I appreciate the tests aren't all there yet and the coverage isn't great; I did this to do a line-by-line port for now so people could validate the approach and then will work on getting decent test coverage.
This provides some speedup by running
git fetch
in parallel but will also pave the way for further speedup by using ETags to only do thegit fetch
when it's actually necessary to do so.