Skip to content

Commit

Permalink
Cleanup dependency code on macOS and add retry to git fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Mar 18, 2024
1 parent 48e0de2 commit 21eeae3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
22 changes: 2 additions & 20 deletions src/scripts/darwin.sh
Expand Up @@ -113,17 +113,6 @@ add_pecl() {
add_log "${tick:?}" "PECL" "Found PECL $pear_version"
}

# Function to link all libraries of a formula.
link_libraries() {
formula=$1
formula_prefix="$(brew --prefix "$formula")"
sudo mkdir -p "$formula_prefix"/lib
for lib in "$formula_prefix"/lib/*.dylib; do
lib_name=$(basename "$lib")
sudo cp -a "$lib" "$brew_prefix/lib/$lib_name" 2>/dev/null || true
done
}

# Link opcache extension to extensions directory.
link_opcache() {
opcache_ini="$brew_prefix"/etc/php/"$version"/conf.d/ext-opcache.ini
Expand All @@ -142,19 +131,11 @@ patch_brew() {
trap "sudo sed -Ei '' 's/$code.*/$code, overwrite: overwrite?\)/' $formula_installer" exit
}

# Helper function to update the dependencies.
update_dependencies_helper() {
dependency=$1
[[ "${dependency:0:3}" = "lib" ]] && prefix=lib || prefix="${dependency:0:1}"
get -q -n "$core_repo/Formula/$prefix/$dependency.rb" "https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/$prefix/$dependency.rb"
link_libraries "$dependency"
}

# Function to update dependencies.
update_dependencies() {
patch_brew
if ! [ -e /tmp/update_dependencies ]; then
git -C "$core_repo" fetch origin master && git -C "$core_repo" reset --hard origin/master
git_retry -C "$core_repo" fetch origin master && git -C "$core_repo" reset --hard origin/master
echo '' | sudo tee /tmp/update_dependencies >/dev/null 2>&1
fi
}
Expand Down Expand Up @@ -294,6 +275,7 @@ export HOMEBREW_NO_INSTALL_FROM_API=1
# shellcheck source=.
. "${scripts:?}"/unix.sh
. "${scripts:?}"/tools/brew.sh
. "${scripts:?}"/tools/retry.sh
. "${scripts:?}"/tools/add_tools.sh
. "${scripts:?}"/extensions/source.sh
. "${scripts:?}"/extensions/add_extensions.sh
Expand Down
20 changes: 20 additions & 0 deletions src/scripts/tools/retry.sh
@@ -0,0 +1,20 @@
function retry {
local try=0

until "$@"; do
exit_code="$?"
try=$((try + 1))

if [ $try -lt 10 ]; then
sleep "$((2 ** try))"
else
return $exit_code
fi
done

return 0
}

function git_retry {
retry git "$@"
}

0 comments on commit 21eeae3

Please sign in to comment.