Skip to content

Commit 1578b1e

Browse files
committed
Update submodules in parallel
1 parent c2f4744 commit 1578b1e

File tree

1 file changed

+29
-43
lines changed

1 file changed

+29
-43
lines changed

src/ci/init_repo.sh

+29-43
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ci_dir=$(cd $(dirname $0) && pwd)
1717
. "$ci_dir/shared.sh"
1818

1919
travis_fold start init_repo
20+
travis_time_start
2021

2122
REPO_DIR="$1"
2223
CACHE_DIR="$2"
@@ -42,54 +43,39 @@ if grep -q RUST_RELEASE_CHANNEL=beta src/ci/run.sh; then
4243
git fetch origin --unshallow beta master
4344
fi
4445

45-
travis_fold start update_cache
46-
travis_time_start
47-
48-
# Update the cache (a pristine copy of the rust source master)
49-
retry sh -c "rm -rf $cache_src_dir && mkdir -p $cache_src_dir && \
50-
git clone --depth 1 https://github.com/rust-lang/rust.git $cache_src_dir"
51-
if [ -d $cache_src_dir/src/llvm ]; then
52-
(cd $cache_src_dir && git rm src/llvm)
53-
fi
54-
if [ -d $cache_src_dir/src/llvm-emscripten ]; then
55-
(cd $cache_src_dir && git rm src/llvm-emscripten)
56-
fi
57-
retry sh -c "cd $cache_src_dir && \
58-
git submodule deinit -f . && git submodule sync && git submodule update --init"
59-
60-
travis_fold end update_cache
61-
travis_time_finish
46+
function fetch_submodule {
47+
local module=$1
48+
local cached="download-${module//\//-}.tar.gz"
49+
retry sh -c "rm -f $cached && \
50+
curl -sSL -o $cached $2"
51+
mkdir $module
52+
touch "$module/.git"
53+
tar -C $module --strip-components=1 -xf $cached
54+
rm $cached
55+
}
6256

63-
travis_fold start update_submodules
64-
travis_time_start
65-
66-
# Update the submodules of the repo we're in, using the pristine repo as
67-
# a cache for any object files
68-
# No, `git submodule foreach` won't work:
69-
# http://stackoverflow.com/questions/12641469/list-submodules-in-a-git-repository
57+
included="src/llvm src/llvm-emscripten src/doc/book src/doc/rust-by-example"
7058
modules="$(git config --file .gitmodules --get-regexp '\.path$' | cut -d' ' -f2)"
71-
for module in $modules; do
72-
if [ "$module" = src/llvm ] || [ "$module" = src/llvm-emscripten ]; then
59+
modules=($modules)
60+
use_git=""
61+
urls="$(git config --file .gitmodules --get-regexp '\.url$' | cut -d' ' -f2)"
62+
urls=($urls)
63+
for i in ${!modules[@]}; do
64+
module=${modules[$i]}
65+
if [[ " $included " = *" $module "* ]]; then
7366
commit="$(git ls-tree HEAD $module | awk '{print $3}')"
7467
git rm $module
75-
retry sh -c "rm -f $commit.tar.gz && \
76-
curl -sSL -O https://github.com/rust-lang/llvm/archive/$commit.tar.gz"
77-
tar -C src/ -xf "$commit.tar.gz"
78-
rm "$commit.tar.gz"
79-
mv "src/llvm-$commit" $module
80-
continue
81-
fi
82-
if [ ! -e "$cache_src_dir/$module/.git" ]; then
83-
echo "WARNING: $module not found in pristine repo"
84-
retry sh -c "git submodule deinit -f $module && \
85-
git submodule update --init --recursive $module"
68+
url=${urls[$i]}
69+
url=${url/\.git/}
70+
fetch_submodule $module "$url/archive/$commit.tar.gz" &
8671
continue
72+
else
73+
use_git="$use_git $module"
8774
fi
88-
retry sh -c "git submodule deinit -f $module && \
89-
git submodule update --init --recursive --reference $cache_src_dir/$module $module"
9075
done
91-
92-
travis_fold end update_submodules
93-
travis_time_finish
94-
76+
retry sh -c "git submodule deinit -f $use_git && \
77+
git submodule sync && \
78+
git submodule update -j 16 --init --recursive $use_git"
79+
wait
9580
travis_fold end init_repo
81+
travis_time_finish

0 commit comments

Comments
 (0)