OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Script to sync your checkout, build a Chromium OS image, and test it all | 7 # Script to sync your checkout, build a Chromium OS image, and test it all |
8 # with one command. Can also check out a new Chromium OS checkout and | 8 # with one command. Can also check out a new Chromium OS checkout and |
9 # perform a subset of the above operations. | 9 # perform a subset of the above operations. |
10 # | 10 # |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 DEFINE_string remote "" \ | 76 DEFINE_string remote "" \ |
77 "Use this hostname/IP for live updating and running tests" | 77 "Use this hostname/IP for live updating and running tests" |
78 DEFINE_string repo "${CHROMIUMOS_REPO}" "gclient repo for chromiumos" | 78 DEFINE_string repo "${CHROMIUMOS_REPO}" "gclient repo for chromiumos" |
79 DEFINE_boolean sync ${FLAGS_TRUE} "Sync the checkout" | 79 DEFINE_boolean sync ${FLAGS_TRUE} "Sync the checkout" |
80 DEFINE_string test "" \ | 80 DEFINE_string test "" \ |
81 "Test the built image with the given params to run_remote_tests" | 81 "Test the built image with the given params to run_remote_tests" |
82 DEFINE_string top "" \ | 82 DEFINE_string top "" \ |
83 "Root directory of your checkout (defaults to determining from your cwd)" | 83 "Root directory of your checkout (defaults to determining from your cwd)" |
84 DEFINE_boolean withdev ${FLAGS_TRUE} "Build development packages" | 84 DEFINE_boolean withdev ${FLAGS_TRUE} "Build development packages" |
85 DEFINE_boolean usepkg ${FLAGS_TRUE} "Use binary packages" | 85 DEFINE_boolean usepkg ${FLAGS_TRUE} "Use binary packages" |
| 86 DEFINE_boolean useworkon ${FLAGS_FALSE} "Use cros_workon/repo workflow" |
86 DEFINE_boolean unittest ${FLAGS_TRUE} "Run unit tests" | 87 DEFINE_boolean unittest ${FLAGS_TRUE} "Run unit tests" |
87 | 88 |
88 # Returns a heuristic indicating if we believe this to be a google internal | 89 # Returns a heuristic indicating if we believe this to be a google internal |
89 # development environment. | 90 # development environment. |
90 # Returns: | 91 # Returns: |
91 # 0 if so, 1 otherwise | 92 # 0 if so, 1 otherwise |
92 function is_google_environment() { | 93 function is_google_environment() { |
93 hostname | egrep -q .google.com\$ | 94 hostname | egrep -q .google.com\$ |
94 return $? | 95 return $? |
95 } | 96 } |
96 | 97 |
97 | 98 |
98 # Validates parameters and sets "intelligent" defaults based on other | 99 # Validates parameters and sets "intelligent" defaults based on other |
99 # parameters. | 100 # parameters. |
100 function validate_and_set_param_defaults() { | 101 function validate_and_set_param_defaults() { |
101 if [[ -z "${FLAGS_top}" ]]; then | 102 if [[ -z "${FLAGS_top}" ]]; then |
102 local test_dir=$(pwd) | 103 local test_dir=$(pwd) |
103 while [[ "${test_dir}" != "/" ]]; do | 104 while [[ "${test_dir}" != "/" ]]; do |
104 if [[ -d "${test_dir}/src/platform/pam_google" ]]; then | 105 if [[ -d "${test_dir}/src/platform/dev" ]]; then |
105 FLAGS_top="${test_dir}" | 106 FLAGS_top="${test_dir}" |
106 break | 107 break |
107 fi | 108 fi |
108 test_dir=$(dirname "${test_dir}") | 109 test_dir=$(dirname "${test_dir}") |
109 done | 110 done |
110 fi | 111 fi |
111 | 112 |
112 if [[ -z "${FLAGS_top}" ]]; then | 113 if [[ -z "${FLAGS_top}" ]]; then |
113 # Use the top directory based on where this script runs from | 114 # Use the top directory based on where this script runs from |
114 FLAGS_top=$(dirname $(dirname $(dirname $0))) | 115 FLAGS_top=$(dirname $(dirname $(dirname $0))) |
115 fi | 116 fi |
116 | 117 |
117 # Canonicalize any symlinks | 118 # Canonicalize any symlinks |
118 if [[ -d "${FLAGS_top}" ]]; then | 119 if [[ -d "${FLAGS_top}" ]]; then |
119 FLAGS_top=$(readlink -f "${FLAGS_top}") | 120 FLAGS_top=$(readlink -f "${FLAGS_top}") |
120 fi | 121 fi |
121 | 122 |
| 123 if [[ -d "${FLAGS_top}" ]]; then |
| 124 # Auto detect the right workflow. |
| 125 if [[ -d "${FLAGS_top}/.git" ]]; then |
| 126 FLAGS_useworkon=${FLAGS_FALSE} |
| 127 else |
| 128 FLAGS_useworkon=${FLAGS_TRUE} |
| 129 fi |
| 130 fi |
| 131 |
122 if [[ -z "${FLAGS_chroot}" ]]; then | 132 if [[ -z "${FLAGS_chroot}" ]]; then |
123 FLAGS_chroot="${FLAGS_top}/chroot" | 133 FLAGS_chroot="${FLAGS_top}/chroot" |
124 fi | 134 fi |
125 | 135 |
126 # If chroot does not exist, force making it | 136 # If chroot does not exist, force making it |
127 if [[ ! -d "${FLAGS_chroot}" ]]; then | 137 if [[ ! -d "${FLAGS_chroot}" ]]; then |
128 FLAGS_force_make_chroot=${FLAGS_TRUE} | 138 FLAGS_force_make_chroot=${FLAGS_TRUE} |
129 fi | 139 fi |
130 | |
131 # If chrome_root option passed, set as option for ./enter_chroot | 140 # If chrome_root option passed, set as option for ./enter_chroot |
132 if [[ -n "${FLAGS_chrome_root}" ]]; then | 141 if [[ -n "${FLAGS_chrome_root}" ]]; then |
133 chroot_options="--chrome_root=${FLAGS_chrome_root}" | 142 chroot_options="--chrome_root=${FLAGS_chrome_root}" |
134 fi | 143 fi |
135 | 144 |
136 if [[ -z "${FLAGS_repo}" ]]; then | 145 if [[ -z "${FLAGS_repo}" ]]; then |
137 if is_google_environment; then | 146 if is_google_environment; then |
138 FLAGS_repo="ssh://git@chromiumos-git//chromeos" | 147 FLAGS_repo="ssh://git@chromiumos-git//chromeos" |
139 else | 148 else |
140 FLAGS_repo="http://src.chromium.org/git/chromiumos.git" | 149 FLAGS_repo="http://src.chromium.org/git/chromiumos.git" |
141 fi | 150 fi |
142 fi | 151 fi |
143 | 152 |
144 if [[ -n "${FLAGS_test}" ]]; then | 153 if [[ -n "${FLAGS_test}" ]]; then |
145 # If you specify that tests should be run, we assume the image | 154 # If you specify that tests should be run, we assume the image |
146 # is modified to run tests. | 155 # is modified to run tests. |
147 FLAGS_mod_image_for_test=${FLAGS_TRUE} | 156 FLAGS_mod_image_for_test=${FLAGS_TRUE} |
148 # If you specify that tests should be run, we assume you want | 157 # If you specify that tests should be run, we assume you want |
149 # to live update the image. | 158 # to live update the image. |
150 FLAGS_image_to_live=${FLAGS_TRUE} | 159 FLAGS_image_to_live=${FLAGS_TRUE} |
| 160 if [[ ${FLAGS_useworkon} -eq ${FLAGS_TRUE} ]]; then |
| 161 # Currently the workon flow does not enable tests to be dynamically |
| 162 # built during run_remote_tests, so we need to build them all |
| 163 # beforehand. |
| 164 FLAGS_build_autotest=${FLAGS_TRUE} |
| 165 fi |
151 fi | 166 fi |
152 | 167 |
153 # If they gave us a remote host, then we assume they want us to do a live | 168 # If they gave us a remote host, then we assume they want us to do a live |
154 # update. | 169 # update. |
155 if [[ -n "${FLAGS_remote}" ]]; then | 170 if [[ -n "${FLAGS_remote}" ]]; then |
156 FLAGS_image_to_live=${FLAGS_TRUE} | 171 FLAGS_image_to_live=${FLAGS_TRUE} |
157 fi | 172 fi |
158 | 173 |
159 # Grabbing a buildbot build is exclusive with syncing and building | 174 # Grabbing a buildbot build is exclusive with syncing and building |
160 if [[ -n "${FLAGS_grab_buildbot}" ]]; then | 175 if [[ -n "${FLAGS_grab_buildbot}" ]]; then |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 echo "Could not verify that ${device} for image_to_usb is removable" | 219 echo "Could not verify that ${device} for image_to_usb is removable" |
205 exit 1 | 220 exit 1 |
206 fi | 221 fi |
207 fi | 222 fi |
208 } | 223 } |
209 | 224 |
210 | 225 |
211 # Prints a description of what we are doing or did | 226 # Prints a description of what we are doing or did |
212 function describe_steps() { | 227 function describe_steps() { |
213 if [[ ${FLAGS_sync} -eq ${FLAGS_TRUE} ]]; then | 228 if [[ ${FLAGS_sync} -eq ${FLAGS_TRUE} ]]; then |
214 echo " * Sync client (gclient sync)" | 229 if [[ ${FLAGS_useworkon} -eq ${FLAGS_TRUE} ]]; then |
| 230 echo " * Sync client (repo sync)" |
| 231 else |
| 232 echo " * Sync client (gclient sync)" |
| 233 fi |
215 if is_google_environment; then | 234 if is_google_environment; then |
216 echo " * Create proper src/scripts/.chromeos_dev" | 235 echo " * Create proper src/scripts/.chromeos_dev" |
217 fi | 236 fi |
218 fi | 237 fi |
219 if [[ ${FLAGS_force_make_chroot} -eq ${FLAGS_TRUE} ]]; then | 238 if [[ ${FLAGS_force_make_chroot} -eq ${FLAGS_TRUE} ]]; then |
220 echo " * Rebuild chroot (make_chroot) in ${FLAGS_chroot}" | 239 echo " * Rebuild chroot (make_chroot) in ${FLAGS_chroot}" |
221 fi | 240 fi |
222 local set_passwd=${FLAGS_FALSE} | 241 local set_passwd=${FLAGS_FALSE} |
223 if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then | 242 if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then |
224 local withdev="" | 243 local withdev="" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 echo "Planning these steps on ${FLAGS_top}:" | 297 echo "Planning these steps on ${FLAGS_top}:" |
279 describe_steps | 298 describe_steps |
280 read -p "Are you sure (y/N)? " SURE | 299 read -p "Are you sure (y/N)? " SURE |
281 # Get just the first character | 300 # Get just the first character |
282 if [[ "${SURE:0:1}" != "y" ]]; then | 301 if [[ "${SURE:0:1}" != "y" ]]; then |
283 echo "Ok, better safe than sorry." | 302 echo "Ok, better safe than sorry." |
284 exit 1 | 303 exit 1 |
285 fi | 304 fi |
286 } | 305 } |
287 | 306 |
288 | |
289 # Runs gclient config on a new checkout directory. | |
290 function config_new_checkout() { | |
291 # We only know how to check out to a pattern like ~/foo/chromeos so | |
292 # make sure that's the pattern the user has given. | |
293 echo "Checking out ${FLAGS_top}" | |
294 if [[ $(basename "${FLAGS_top}") != "chromeos" ]]; then | |
295 echo "The --top directory does not exist and to check it out requires" | |
296 echo "the name to end in chromeos (try --top=${FLAGS_top}/chromeos)" | |
297 exit 1 | |
298 fi | |
299 local top_parent=$(dirname "${FLAGS_top}") | |
300 mkdir -p "${top_parent}" | |
301 cd "${top_parent}" | |
302 gclient config "${FLAGS_repo}" | |
303 } | |
304 | |
305 | |
306 # Changes to a directory relative to the top/root directory of | 307 # Changes to a directory relative to the top/root directory of |
307 # the checkout. | 308 # the checkout. |
308 # Arguments: | 309 # Arguments: |
309 # $1 - relative path | 310 # $1 - relative path |
310 function chdir_relative() { | 311 function chdir_relative() { |
311 local dir=$1 | 312 local dir=$1 |
312 echo "+ cd ${dir}" | 313 echo "+ cd ${dir}" |
313 # Allow use of .. before the innermost directory of FLAGS_top exists | 314 # Allow use of .. before the innermost directory of FLAGS_top exists |
314 if [[ "${dir}" == ".." ]]; then | 315 if [[ "${dir}" == ".." ]]; then |
315 dir=$(dirname "${FLAGS_top}") | 316 dir=$(dirname "${FLAGS_top}") |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 379 |
379 # Display duration | 380 # Display duration |
380 function show_duration() { | 381 function show_duration() { |
381 local current_time=$(date '+%s') | 382 local current_time=$(date '+%s') |
382 local duration=$((${current_time} - ${START_TIME})) | 383 local duration=$((${current_time} - ${START_TIME})) |
383 local minutes_duration=$((${duration} / 60)) | 384 local minutes_duration=$((${duration} / 60)) |
384 local seconds_duration=$((${duration} % 60)) | 385 local seconds_duration=$((${duration} % 60)) |
385 printf "Total time: %d:%02ds\n" "${minutes_duration}" "${seconds_duration}" | 386 printf "Total time: %d:%02ds\n" "${minutes_duration}" "${seconds_duration}" |
386 } | 387 } |
387 | 388 |
| 389 # Runs gclient config on a new checkout directory. |
| 390 function config_new_gclient_checkout() { |
| 391 # We only know how to check out to a pattern like ~/foo/chromeos so |
| 392 # make sure that's the pattern the user has given. |
| 393 if [[ $(basename "${FLAGS_top}") != "chromeos" ]]; then |
| 394 echo "The --top directory does not exist and to check it out requires" |
| 395 echo "the name to end in chromeos (try --top=${FLAGS_top}/chromeos)" |
| 396 exit 1 |
| 397 fi |
| 398 local top_parent=$(dirname "${FLAGS_top}") |
| 399 mkdir -p "${top_parent}" |
| 400 cd "${top_parent}" |
| 401 gclient config "${FLAGS_repo}" |
| 402 } |
| 403 |
| 404 # Runs repo init on a new checkout directory. |
| 405 function config_new_repo_checkout() { |
| 406 mkdir -p "${FLAGS_top}" |
| 407 cd "${FLAGS_top}" |
| 408 repo init -u http://src.chromium.org/git/manifest -m minilayout.xml |
| 409 } |
| 410 |
| 411 # Configures/initializes a new checkout |
| 412 function config_new_checkout() { |
| 413 echo "Checking out ${FLAGS_top}" |
| 414 if [[ ${FLAGS_useworkon} ]]; then |
| 415 config_new_repo_checkout |
| 416 else |
| 417 config_new_gclient_checkout |
| 418 fi |
| 419 } |
388 | 420 |
389 # Runs gclient sync, setting up .chromeos_dev and preparing for | 421 # Runs gclient sync, setting up .chromeos_dev and preparing for |
390 # local repo setup | 422 # local repo setup |
391 function sync() { | 423 function sync() { |
392 # cd to the directory below | 424 # cd to the directory below |
393 chdir_relative .. | 425 if [[ ${FLAGS_useworkon} -eq ${FLAGS_TRUE} ]]; then |
394 run_phase "Synchronizing client" gclient sync | 426 chdir_relative . |
| 427 run_phase "Synchronizing client" repo sync |
| 428 # Change to a directory that is definitely a git repo |
| 429 chdir_relative src/third_party/chromiumos-overlay |
| 430 git cl config "file://$(pwd)/../../../codereview.settings" |
| 431 else |
| 432 chdir_relative .. |
| 433 run_phase "Synchronizing client" gclient sync |
| 434 chdir_relative . |
| 435 git cl config "file://$(pwd)/codereview.settings" |
| 436 fi |
395 chdir_relative . | 437 chdir_relative . |
396 git cl config "file://$(pwd)/codereview.settings" | |
397 if is_google_environment; then | 438 if is_google_environment; then |
398 local base_dir=$(dirname $(dirname "${FLAGS_top}")) | 439 local base_dir=$(dirname $(dirname "${FLAGS_top}")) |
399 echo <<EOF > src/scripts/.chromeos_dev | 440 echo <<EOF > src/scripts/.chromeos_dev |
400 # Use internal chromeos-deb repository | |
401 CHROMEOS_EXT_MIRROR="http://chromeos-deb/ubuntu" | |
402 CHROMEOS_EXT_SUITE="karmic" | |
403 | |
404 # Assume Chrome is checked out nearby | 441 # Assume Chrome is checked out nearby |
405 CHROMEOS_CHROME_DIR="${base_dir}/chrome" | 442 CHROMEOS_CHROME_DIR="${base_dir}/chrome" |
406 EOF | 443 EOF |
407 fi | 444 fi |
408 } | 445 } |
409 | 446 |
410 | 447 |
411 # Downloads a buildbot image | 448 # Downloads a buildbot image |
412 function grab_buildbot() { | 449 function grab_buildbot() { |
413 if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then | 450 if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 if [[ ${FLAGS_sync} -eq ${FLAGS_TRUE} ]]; then | 538 if [[ ${FLAGS_sync} -eq ${FLAGS_TRUE} ]]; then |
502 sync | 539 sync |
503 fi | 540 fi |
504 | 541 |
505 if [[ -n "${FLAGS_grab_buildbot}" ]]; then | 542 if [[ -n "${FLAGS_grab_buildbot}" ]]; then |
506 grab_buildbot | 543 grab_buildbot |
507 fi | 544 fi |
508 | 545 |
509 if [[ ${FLAGS_force_make_chroot} -eq ${FLAGS_TRUE} ]]; then | 546 if [[ ${FLAGS_force_make_chroot} -eq ${FLAGS_TRUE} ]]; then |
510 chdir_relative src/scripts | 547 chdir_relative src/scripts |
511 run_phase "Replacing chroot" ./make_chroot --replace \ | 548 local extra_flags="--nouseworkon" |
| 549 [[ ${FLAGS_useworkon} -eq ${FLAGS_TRUE} ]] && extra_flags="--useworkon" |
| 550 run_phase "Replacing chroot" ./make_chroot ${extra_flags} --replace \ |
512 "--chroot=${FLAGS_chroot}" ${jobs_param} | 551 "--chroot=${FLAGS_chroot}" ${jobs_param} |
513 fi | 552 fi |
514 | 553 |
515 if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then | 554 if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then |
516 local pkg_param="" | 555 local pkg_param="" |
517 if [[ ${FLAGS_usepkg} -eq ${FLAGS_FALSE} ]]; then | 556 if [[ ${FLAGS_usepkg} -eq ${FLAGS_FALSE} ]]; then |
518 pkg_param="--nousepkg" | 557 pkg_param="--nousepkg" |
519 fi | 558 fi |
520 | 559 |
521 chdir_relative src/scripts | 560 chdir_relative src/scripts |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 fi | 626 fi |
588 | 627 |
589 trap - EXIT | 628 trap - EXIT |
590 echo "Successfully used ${FLAGS_top} to:" | 629 echo "Successfully used ${FLAGS_top} to:" |
591 describe_steps | 630 describe_steps |
592 show_duration | 631 show_duration |
593 } | 632 } |
594 | 633 |
595 | 634 |
596 main $@ | 635 main $@ |
OLD | NEW |