Merge pull request #17292 from Homebrew/homebrew_version_cache
brew.sh: cache HOMEBREW_VERSION on disk.
This commit is contained in:
commit
801c737e1b
@ -3,16 +3,33 @@
|
|||||||
##### to be able to `source` in shell configurations run quickly.
|
##### to be able to `source` in shell configurations run quickly.
|
||||||
#####
|
#####
|
||||||
|
|
||||||
# Doesn't need a default case because we don't support other OSs
|
case "${MACHTYPE}" in
|
||||||
# shellcheck disable=SC2249
|
arm64-*)
|
||||||
|
HOMEBREW_PROCESSOR="arm64"
|
||||||
|
;;
|
||||||
|
x86_64-*)
|
||||||
|
HOMEBREW_PROCESSOR="x86_64"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
HOMEBREW_PROCESSOR="$(uname -m)"
|
HOMEBREW_PROCESSOR="$(uname -m)"
|
||||||
HOMEBREW_PHYSICAL_PROCESSOR="${HOMEBREW_PROCESSOR}"
|
;;
|
||||||
HOMEBREW_SYSTEM="$(uname -s)"
|
|
||||||
case "${HOMEBREW_SYSTEM}" in
|
|
||||||
Darwin) HOMEBREW_MACOS="1" ;;
|
|
||||||
Linux) HOMEBREW_LINUX="1" ;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
case "${OSTYPE}" in
|
||||||
|
darwin*)
|
||||||
|
HOMEBREW_SYSTEM="Darwin"
|
||||||
|
HOMEBREW_MACOS="1"
|
||||||
|
;;
|
||||||
|
linux*)
|
||||||
|
HOMEBREW_SYSTEM="Linux"
|
||||||
|
HOMEBREW_LINUX="1"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
HOMEBREW_SYSTEM="$(uname -s)"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
HOMEBREW_PHYSICAL_PROCESSOR="${HOMEBREW_PROCESSOR}"
|
||||||
|
|
||||||
HOMEBREW_MACOS_ARM_DEFAULT_PREFIX="/opt/homebrew"
|
HOMEBREW_MACOS_ARM_DEFAULT_PREFIX="/opt/homebrew"
|
||||||
HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY="${HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}"
|
HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY="${HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}"
|
||||||
HOMEBREW_LINUX_DEFAULT_PREFIX="/home/linuxbrew/.linuxbrew"
|
HOMEBREW_LINUX_DEFAULT_PREFIX="/home/linuxbrew/.linuxbrew"
|
||||||
@ -79,11 +96,11 @@ HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOMEBREW_DEFAULT_CACHE}}"
|
|||||||
HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOMEBREW_DEFAULT_LOGS}}"
|
HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOMEBREW_DEFAULT_LOGS}}"
|
||||||
HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_DEFAULT_TEMP}}"
|
HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_DEFAULT_TEMP}}"
|
||||||
|
|
||||||
# Don't need to handle a default case.
|
|
||||||
# HOMEBREW_LIBRARY set by bin/brew
|
|
||||||
# shellcheck disable=SC2249,SC2154
|
|
||||||
#
|
|
||||||
# commands that take a single or no arguments.
|
# commands that take a single or no arguments.
|
||||||
|
# HOMEBREW_LIBRARY set by bin/brew
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
# doesn't need a default case as other arguments handled elsewhere.
|
||||||
|
# shellcheck disable=SC2249
|
||||||
case "$1" in
|
case "$1" in
|
||||||
formulae)
|
formulae)
|
||||||
source "${HOMEBREW_LIBRARY}/Homebrew/cmd/formulae.sh"
|
source "${HOMEBREW_LIBRARY}/Homebrew/cmd/formulae.sh"
|
||||||
@ -109,6 +126,8 @@ case "$1" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# functions that take multiple arguments or handle multiple commands.
|
# functions that take multiple arguments or handle multiple commands.
|
||||||
|
# doesn't need a default case as other arguments handled elsewhere.
|
||||||
|
# shellcheck disable=SC2249
|
||||||
case "$@" in
|
case "$@" in
|
||||||
--cellar)
|
--cellar)
|
||||||
echo "${HOMEBREW_CELLAR}"
|
echo "${HOMEBREW_CELLAR}"
|
||||||
@ -232,7 +251,7 @@ numeric() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check-run-command-as-root() {
|
check-run-command-as-root() {
|
||||||
[[ "$(id -u)" == 0 || "$(id -ur)" == 0 ]] || return
|
[[ "${EUID}" == 0 || "${UID}" == 0 ]] || return
|
||||||
|
|
||||||
# Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there)
|
# Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there)
|
||||||
[[ -f /.dockerenv ]] && return
|
[[ -f /.dockerenv ]] && return
|
||||||
@ -429,11 +448,11 @@ fi
|
|||||||
|
|
||||||
# Many Pathname operations use getwd when they shouldn't, and then throw
|
# Many Pathname operations use getwd when they shouldn't, and then throw
|
||||||
# odd exceptions. Reduce our support burden by showing a user-friendly error.
|
# odd exceptions. Reduce our support burden by showing a user-friendly error.
|
||||||
if ! [[ -d "$(pwd)" ]]
|
if ! [[ -d "${PWD}" ]]
|
||||||
then
|
then
|
||||||
odie "The current working directory must exist to run brew."
|
odie "The current working directory must exist to run brew."
|
||||||
fi
|
fi
|
||||||
if ! [[ -r "$(pwd)" ]]
|
if ! [[ -r "${PWD}" ]]
|
||||||
then
|
then
|
||||||
odie "The current working directory must be readable to ${USER} to run brew."
|
odie "The current working directory must be readable to ${USER} to run brew."
|
||||||
fi
|
fi
|
||||||
@ -495,7 +514,27 @@ setup_git() {
|
|||||||
setup_curl
|
setup_curl
|
||||||
setup_git
|
setup_git
|
||||||
|
|
||||||
|
GIT_DESCRIBE_CACHE="${HOMEBREW_REPOSITORY}/.git/describe-cache"
|
||||||
|
GIT_REVISION=$("${HOMEBREW_GIT}" -C "${HOMEBREW_REPOSITORY}" rev-parse HEAD 2>/dev/null)
|
||||||
|
if [[ -n "${GIT_REVISION}" ]]
|
||||||
|
then
|
||||||
|
GIT_DESCRIBE_CACHE_FILE="${GIT_DESCRIBE_CACHE}/${GIT_REVISION}"
|
||||||
|
if [[ -f "${GIT_DESCRIBE_CACHE_FILE}" ]]
|
||||||
|
then
|
||||||
|
HOMEBREW_VERSION="$(cat "${GIT_DESCRIBE_CACHE_FILE}")"
|
||||||
|
else
|
||||||
|
rm -rf "${GIT_DESCRIBE_CACHE}"
|
||||||
HOMEBREW_VERSION="$("${HOMEBREW_GIT}" -C "${HOMEBREW_REPOSITORY}" describe --tags --dirty --abbrev=7 2>/dev/null)"
|
HOMEBREW_VERSION="$("${HOMEBREW_GIT}" -C "${HOMEBREW_REPOSITORY}" describe --tags --dirty --abbrev=7 2>/dev/null)"
|
||||||
|
mkdir -p "${GIT_DESCRIBE_CACHE}"
|
||||||
|
echo "${HOMEBREW_VERSION}" >"${GIT_DESCRIBE_CACHE_FILE}"
|
||||||
|
fi
|
||||||
|
unset GIT_DESCRIBE_CACHE_FILE
|
||||||
|
else
|
||||||
|
rm -rf "${GIT_DESCRIBE_CACHE}"
|
||||||
|
fi
|
||||||
|
unset GIT_REVISION
|
||||||
|
unset GIT_DESCRIBE_CACHE
|
||||||
|
|
||||||
HOMEBREW_USER_AGENT_VERSION="${HOMEBREW_VERSION}"
|
HOMEBREW_USER_AGENT_VERSION="${HOMEBREW_VERSION}"
|
||||||
if [[ -z "${HOMEBREW_VERSION}" ]]
|
if [[ -z "${HOMEBREW_VERSION}" ]]
|
||||||
then
|
then
|
||||||
@ -516,6 +555,8 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# commands that take a single or no arguments.
|
# commands that take a single or no arguments.
|
||||||
|
# doesn't need a default case as other arguments handled elsewhere.
|
||||||
|
# shellcheck disable=SC2249
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--version | -v)
|
--version | -v)
|
||||||
source "${HOMEBREW_LIBRARY}/Homebrew/cmd/--version.sh"
|
source "${HOMEBREW_LIBRARY}/Homebrew/cmd/--version.sh"
|
||||||
@ -787,6 +828,7 @@ EOS
|
|||||||
# a popup window asking the user to install the CLT
|
# a popup window asking the user to install the CLT
|
||||||
if [[ -n "${XCODE_SELECT_PATH}" ]]
|
if [[ -n "${XCODE_SELECT_PATH}" ]]
|
||||||
then
|
then
|
||||||
|
# TODO: this is fairly slow, figure out if there's a faster way.
|
||||||
XCRUN_OUTPUT="$(/usr/bin/xcrun clang 2>&1)"
|
XCRUN_OUTPUT="$(/usr/bin/xcrun clang 2>&1)"
|
||||||
XCRUN_STATUS="$?"
|
XCRUN_STATUS="$?"
|
||||||
|
|
||||||
@ -816,6 +858,8 @@ HOMEBREW_COMMAND="$1"
|
|||||||
shift
|
shift
|
||||||
# If you are going to change anything in below case statement,
|
# If you are going to change anything in below case statement,
|
||||||
# be sure to also update HOMEBREW_INTERNAL_COMMAND_ALIASES hash in commands.rb
|
# be sure to also update HOMEBREW_INTERNAL_COMMAND_ALIASES hash in commands.rb
|
||||||
|
# doesn't need a default case as other arguments handled elsewhere.
|
||||||
|
# shellcheck disable=SC2249
|
||||||
case "${HOMEBREW_COMMAND}" in
|
case "${HOMEBREW_COMMAND}" in
|
||||||
ls) HOMEBREW_COMMAND="list" ;;
|
ls) HOMEBREW_COMMAND="list" ;;
|
||||||
homepage) HOMEBREW_COMMAND="home" ;;
|
homepage) HOMEBREW_COMMAND="home" ;;
|
||||||
|
|||||||
2
bin/brew
2
bin/brew
@ -76,7 +76,7 @@ then
|
|||||||
HOMEBREW_REPOSITORY="${BREW_FILE_DIRECTORY%/*}"
|
HOMEBREW_REPOSITORY="${BREW_FILE_DIRECTORY%/*}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Try to find a /usr/local HOMEBREW_PREFIX where possible (for bottles)
|
# Try to find a /usr/local HOMEBREW_PREFIX where possible (for macOS x86_64 bottles)
|
||||||
if [[ -L "/usr/local/bin/brew" && ! -L "${HOMEBREW_PREFIX}/Cellar" ]]
|
if [[ -L "/usr/local/bin/brew" && ! -L "${HOMEBREW_PREFIX}/Cellar" ]]
|
||||||
then
|
then
|
||||||
USR_LOCAL_BREW_FILE_DIRECTORY="$(symlink_target_directory "/usr/local/bin/brew" "/usr/local/bin")"
|
USR_LOCAL_BREW_FILE_DIRECTORY="$(symlink_target_directory "/usr/local/bin/brew" "/usr/local/bin")"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user