Skip to content

Clean up submodule checkout scripts #98439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/ci/docker/host-x86_64/dist-various-2/shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,3 @@ function retry {
}
done
}

# Copied from ../../init_repo.sh
function fetch_github_commit_archive {
local module=$1
local cached="download-${module//\//-}.tar.gz"
retry sh -c "rm -f $cached && \
curl -f -sSL -o $cached $2"
mkdir $module
touch "$module/.git"
tar -C $module --strip-components=1 -xf $cached
rm $cached
}
83 changes: 0 additions & 83 deletions src/ci/init_repo.sh

This file was deleted.

72 changes: 63 additions & 9 deletions src/ci/scripts/checkout-submodules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,70 @@
# Check out all our submodules, but more quickly than using git by using one of
# our custom scripts

set -euo pipefail
IFS=$'\n\t'
set -o errexit
set -o pipefail
set -o nounset

source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
if [ ! -d ".git" ]; then
echo "Error: This must run in the root of the repository"
exit 1
fi

ci_dir=$(cd $(dirname $0) && pwd)/..
. "$ci_dir/shared.sh"

if isWindows; then
path="/c/cache/rustsrc"
else
path="${HOME}/rustsrc"
# On the beta channel we'll be automatically calculating the prerelease version
# via the git history, so unshallow our shallow clone from CI.
if [ "$(releaseChannel)" = "beta" ]; then
git fetch origin --unshallow beta master
fi

mkdir -p "${path}"
"$(cd "$(dirname "$0")" && pwd)/../init_repo.sh" . "${path}"
function fetch_github_commit_archive {
local module=$1
local cached="download-${module//\//-}.tar.gz"
retry sh -c "rm -f $cached && \
curl -f -sSL -o $cached $2"
mkdir $module
touch "$module/.git"
# On Windows, the default behavior is to emulate symlinks by copying
# files. However, that ends up being order-dependent while extracting,
# which can cause a failure if the symlink comes first. This env var
# causes tar to use real symlinks instead, which are allowed to dangle.
export MSYS=winsymlinks:nativestrict
tar -C $module --strip-components=1 -xf $cached
rm $cached
}

# Archive downloads are temporarily disabled due to sudden 504
# gateway timeout errors.
# included="src/llvm-project src/doc/book src/doc/rust-by-example"
included=""
modules="$(git config --file .gitmodules --get-regexp '\.path$' | cut -d' ' -f2)"
modules=($modules)
use_git=""
urls="$(git config --file .gitmodules --get-regexp '\.url$' | cut -d' ' -f2)"
urls=($urls)
# shellcheck disable=SC2068
for i in ${!modules[@]}; do
module=${modules[$i]}
if [[ " $included " = *" $module "* ]]; then
commit="$(git ls-tree HEAD $module | awk '{print $3}')"
git rm $module
url=${urls[$i]}
url=${url/\.git/}
fetch_github_commit_archive $module "$url/archive/$commit.tar.gz" &
bg_pids[${i}]=$!
continue
else
use_git="$use_git $module"
fi
done
retry sh -c "git submodule deinit -f $use_git && \
git submodule sync && \
git submodule update -j 16 --init --recursive --depth 1 $use_git"
# STATUS=0
# for pid in ${bg_pids[*]}
# do
# wait $pid || STATUS=1
# done
# exit ${STATUS}