OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # A convenience script to largely replicate the behavior of `gclient sync` in a | 6 TOPLEVEL=$(git rev-parse --show-toplevel) |
7 # submodule-based checkout. Fetches latest commits for top-level solutions; | 7 TOPPERLEVEL=$(dirname $TOPLEVEL) |
8 # updates submodules; and runs post-sync hooks. | |
9 | 8 |
10 orig_args="$@" | 9 cat <<EOF |
11 ECHO= | 10 Sorry `whoami`, but the git-submodule flow has been deprecated in order to |
12 pull=pull | 11 simplify the plethora of SCM choices, and to pave the way towards a git-only |
13 pull_args= | 12 chromium development flow. |
14 hooks=yes | |
15 j=10 | |
16 crup_runner="crup-runner.sh" | |
17 | 13 |
18 usage() { | 14 Please consult https://code.google.com/p/chromium/wiki/UsingGitSubmodules#Conver
t_from_submodules_to_gclient |
19 cat <<EOF | 15 for instructions on how to convert your submodule checkout to gclient. |
20 Usage: git-crup [-n|--dry-run] [--fetch|--sync] [-j|--jobs [jobs]] | |
21 [--no-hooks] [<args to git-pull or git-fetch>] | |
22 | 16 |
23 -n, --dry-run Don't do anything; just show what would have been done. | 17 The simplest chromium and/or blink instructions follow for convenience. |
24 --fetch Run 'git fetch' on top-level sources, but don't merge. | 18 |
25 --sync Don't do anything at all to the top-level sources. | 19 1. Make sure the parent directory of this checkout is empty, besides this repo: |
26 -j, --jobs Run this many jobs in parallel. | 20 $ ls $TOPPERLEVEL |
27 --no-hooks Don't run hooks (e.g., to generate build files) after | |
28 updating. | |
29 EOF | 21 EOF |
30 } | 22 ls "$TOPPERLEVEL" |
| 23 if [[ "$(ls "$TOPPERLEVEL")" != 'src' ]] |
| 24 then |
| 25 echo Please move this repo to its own directory before continuing!!! |
| 26 fi |
| 27 echo |
31 | 28 |
32 serial_update() { | 29 cat <<EOF |
33 ( cd "$1" | 30 2. Please add a .gclient file to $TOPPERLEVEL/.gclient of the form: |
34 if test -n "$toplevel_cmd"; then | 31 # ======== .gclient begins ========= |
35 $ECHO $toplevel_cmd | sed "s/^/[$1] /g" | 32 solutions = [{ |
36 if [ $? -ne 0 ]; then | 33 'name': '$(basename "$TOPLEVEL")', |
37 return $? | 34 'url': 'https://chromium.googlesource.com/chromium/src.git', |
38 fi | 35 'managed': False, |
39 fi | 36 'deps_file': '.DEPS.git', |
40 $ECHO git submodule --quiet sync | 37 # Uncomment the following if you're doing blink development |
41 $ECHO git ls-files -s | grep ^160000 | awk '{print $4}' | | 38 # 'custom_vars': {'webkit_rev': ''}, |
42 while read submod; do | 39 }] |
43 $ECHO "$crup_runner" "$1/$submod" | 40 # ======== .gclient ends ========= |
44 done | |
45 ) | |
46 } | |
47 | 41 |
48 while test $# -ne 0; do | 42 3. Run \`gclient sync\` to synchronize dependencies in your checkout instead of
$(basename "$0")! |
49 case "$1" in | 43 EOF |
50 -j[0-9]*) | |
51 j=$(echo "$1" | cut -c3-) | |
52 ;; | |
53 --jobs=[0-9]*) | |
54 j=$(echo "$1" | cut -c8-) | |
55 ;; | |
56 -j|--jobs) | |
57 case "$2" in | |
58 ''|-*) | |
59 j=0 | |
60 ;; | |
61 *) | |
62 j="$2" | |
63 shift | |
64 ;; | |
65 esac | |
66 ;; | |
67 -n|--dry-run) | |
68 ECHO=echo | |
69 ;; | |
70 -h|--help) | |
71 usage | |
72 exit 0 | |
73 ;; | |
74 --fetch) | |
75 pull=fetch | |
76 ;; | |
77 --sync) | |
78 pull= | |
79 ;; | |
80 --no-hooks|--nohooks) | |
81 hooks=no | |
82 ;; | |
83 *) | |
84 pull_args="$pull_args $1" | |
85 break | |
86 ;; | |
87 esac | |
88 shift | |
89 done | |
90 | 44 |
91 # Auto-update depot_tools. | 45 exit 1 |
92 if [ -z "$GIT_CRUP_REINVOKE" ]; then | |
93 kernel_name="\$(uname -s)" | |
94 if [ "\${kernel_name:0:5}" = "MINGW" ]; then | |
95 cmd '/C update_depot_tools.bat' | |
96 else | |
97 update_depot_tools | |
98 fi | |
99 GIT_CRUP_REINVOKE=1 exec bash "$0" $orig_args | |
100 fi | |
101 | |
102 while test "$PWD" != "/"; do | |
103 if test -f "$PWD/src/.gitmodules"; then | |
104 break | |
105 fi | |
106 cd .. | |
107 done | |
108 if test "$PWD" = "/"; then | |
109 echo "Could not find the root of your checkout; aborting." 1>&2 | |
110 exit 1 | |
111 fi | |
112 | |
113 export GIT_MERGE_AUTOEDIT=no | |
114 | |
115 if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then | |
116 max_lines="--max-lines=1" | |
117 else | |
118 max_lines="-L 1" | |
119 fi | |
120 | |
121 if ( echo test | xargs -I bar true 2>/dev/null ); then | |
122 replace_arg="-I replace_arg" | |
123 else | |
124 replace_arg="-ireplace_arg" | |
125 fi | |
126 | |
127 if ( echo test test | xargs -P 2 true 2>/dev/null ); then | |
128 xargs_parallel=yes | |
129 else | |
130 if test "$j" != "1"; then | |
131 echo "Warning: parallel execution is not supported on this platform." 1>&2 | |
132 fi | |
133 xargs_parallel=no | |
134 fi | |
135 | |
136 if test -n "$pull"; then | |
137 toplevel_cmd="git $pull $pull_args -q origin" | |
138 else | |
139 toplevel_cmd= | |
140 fi | |
141 | |
142 set -o pipefail | |
143 if test "$xargs_parallel" = "yes"; then | |
144 ( ls -d */.git | sed 's/\/\.git$//' | | |
145 xargs $max_lines $replace_arg -P "$j" \ | |
146 "$crup_runner" replace_arg $ECHO $toplevel_cmd | | |
147 xargs $max_lines -P "$j" $ECHO "$crup_runner" ) | |
148 else | |
149 ls -d */.git | | |
150 while read gitdir; do | |
151 serial_update "${gitdir%%/.git}" | |
152 done | |
153 fi | |
154 | |
155 status=$? | |
156 | |
157 if [ "$status" -ne 0 ]; then | |
158 cat 1>&2 <<EOF | |
159 Please check the preceding terminal output for error messages. | |
160 Run 'git submodule status' to see the current state of submodule checkouts. | |
161 EOF | |
162 exit $status | |
163 fi | |
164 | |
165 if [ "$hooks" = "yes" ]; then | |
166 $ECHO git runhooks | |
167 status=$? | |
168 fi | |
169 | |
170 echo | |
171 exit $status | |
OLD | NEW |