OLD | NEW |
| (Empty) |
1 #!/bin/bash | |
2 | |
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 | |
5 # found in the LICENSE file. | |
6 | |
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 | |
9 # perform a subset of the above operations. | |
10 # | |
11 # Here are some example runs: | |
12 # | |
13 # sync_build_test.sh | |
14 # syncs, recreates local repo and chroot, builds, and masters an | |
15 # image in the checkout based on your current directory, or if you | |
16 # are not in a checkout, based on the top level directory the script | |
17 # is run from. | |
18 # | |
19 # sync_build_test.sh --image_to_usb=/dev/sdb -i | |
20 # same as above but then images USB device /dev/sdb with the image. | |
21 # Also prompt the user in advance of the steps we'll take to make | |
22 # sure they agrees. | |
23 # | |
24 # sync_build_test.sh --top=~/foo --nosync --remote 192.168.1.2 | |
25 # builds and masters an image in ~/foo, and live updates the machine | |
26 # at 192.168.1.2 with that image. | |
27 # | |
28 # sync_build_test.sh --top=~/newdir --test "Pam BootPerfServer" \ | |
29 # --remote=192.168.1.2 | |
30 # creates a new checkout in ~/newdir, builds and masters an image | |
31 # which is live updated to 192.168.1.2 and then runs | |
32 # two tests (Pam and BootPerfServer) against that machine. | |
33 # | |
34 # sync_build_test.sh --grab_buildbot=LATEST --test Pam --remote=192.168.1.2 | |
35 # grabs the latest build from the buildbot, properly modifies it, | |
36 # reimages 192.168.1.2, and runs the given test on it. | |
37 # | |
38 # Environment variables that may be useful: | |
39 # BUILDBOT_URI - default value for --buildbot_uri | |
40 # CHROMIUM_REPO - default value for --repo | |
41 # CHRONOS_PASSWD - default value for --chronos_passwd | |
42 # | |
43 | |
44 # --- BEGIN COMMON.SH BOILERPLATE --- | |
45 # Load common CrOS utilities. Inside the chroot this file is installed in | |
46 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's | |
47 # location. | |
48 find_common_sh() { | |
49 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")")) | |
50 local path | |
51 | |
52 SCRIPT_ROOT= | |
53 for path in "${common_paths[@]}"; do | |
54 if [ -r "${path}/common.sh" ]; then | |
55 SCRIPT_ROOT=${path} | |
56 break | |
57 fi | |
58 done | |
59 } | |
60 | |
61 find_common_sh | |
62 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) | |
63 # --- END COMMON.SH BOILERPLATE --- | |
64 | |
65 . "${SCRIPT_ROOT}/remote_access.sh" | |
66 | |
67 DEFINE_string board "" "Board setting" | |
68 DEFINE_boolean build ${FLAGS_TRUE} \ | |
69 "Build all code (but not necessarily master image)" | |
70 DEFINE_boolean build_autotest ${FLAGS_FALSE} "Build autotest" | |
71 DEFINE_string buildbot_uri "${BUILDBOT_URI}" \ | |
72 "Base URI to buildbot build location which contains LATEST file" | |
73 DEFINE_string chrome_gold ${FLAGS_TRUE} \ | |
74 "Build Chrome using gold if it is installed and supported." | |
75 DEFINE_string chrome_root "" \ | |
76 "The root of your chrome browser source. Should contain a 'src' subdir. \ | |
77 If this is set, chrome browser will be built from source." | |
78 DEFINE_string chronos_passwd "${CHRONOS_PASSWD}" \ | |
79 "Use this as the chronos user passwd (defaults to \$CHRONOS_PASSWD)" | |
80 DEFINE_string chroot "" "Chroot to build/use" | |
81 DEFINE_boolean enable_rootfs_verification ${FLAGS_FALSE} \ | |
82 "Enable rootfs verification when building image" | |
83 DEFINE_boolean force_make_chroot ${FLAGS_FALSE} "Run make_chroot indep of sync" | |
84 DEFINE_string grab_buildbot "" \ | |
85 "Instead of building, grab this full image.zip URI generated by the \ | |
86 buildbot" | |
87 DEFINE_boolean ignore_remote_test_failures ${FLAGS_FALSE} \ | |
88 "Ignore any remote tests that failed and don't return failure" | |
89 DEFINE_boolean image_to_live ${FLAGS_FALSE} \ | |
90 "Put the resulting image on live instance (requires --remote)" | |
91 DEFINE_boolean image_to_vm ${FLAGS_FALSE} "Create a VM image" | |
92 DEFINE_string image_to_usb "" \ | |
93 "Treat this device as USB and put the image on it after build" | |
94 # You can set jobs > 1 but then your build may break and you may need | |
95 # to retry. Setting it to 1 is best for non-interactive sessions. | |
96 DEFINE_integer jobs -1 "Concurrent build jobs" | |
97 DEFINE_boolean master ${FLAGS_TRUE} "Master an image from built code" | |
98 DEFINE_boolean minilayout ${FLAGS_FALSE} "Use minimal code checkout" | |
99 DEFINE_boolean mod_image_for_test ${FLAGS_FALSE} "Modify the image for testing" | |
100 DEFINE_boolean official ${FLAGS_FALSE} "Sync/Build/Test official Chrome OS" | |
101 DEFINE_boolean oldchromebinary ${FLAGS_TRUE} "Always use chrome binary package" | |
102 DEFINE_string repo "${CHROMIUMOS_REPO}" "gclient repo for chromiumos" | |
103 DEFINE_boolean sync ${FLAGS_TRUE} "Sync the checkout" | |
104 DEFINE_string test "" \ | |
105 "Test the built image with the given params to run_remote_tests" | |
106 DEFINE_string top "" \ | |
107 "Root directory of your checkout (defaults to determining from your cwd)" | |
108 DEFINE_string vm_options "--no_graphics" "VM options" | |
109 DEFINE_boolean withdev ${FLAGS_TRUE} "Build development packages" | |
110 DEFINE_boolean usepkg ${FLAGS_TRUE} "Use binary packages" | |
111 DEFINE_boolean unittest ${FLAGS_TRUE} "Run unit tests" | |
112 DEFINE_boolean yes ${FLAGS_FALSE} "Reply yes to all prompts" y | |
113 | |
114 # Returns a heuristic indicating if we believe this to be a google internal | |
115 # development environment. | |
116 # Returns: | |
117 # 0 if so, 1 otherwise | |
118 function is_google_environment() { | |
119 hostname | egrep -q .google.com\$ | |
120 return $? | |
121 } | |
122 | |
123 | |
124 # Validates parameters and sets "intelligent" defaults based on other | |
125 # parameters. | |
126 function validate_and_set_param_defaults() { | |
127 TMP=$(mktemp -d "/tmp/sync_build_test.XXXX") | |
128 | |
129 if [[ -z "${FLAGS_top}" ]]; then | |
130 local test_dir=$(pwd) | |
131 while [[ "${test_dir}" != "/" ]]; do | |
132 if [[ -d "${test_dir}/src/platform/dev" ]]; then | |
133 FLAGS_top="${test_dir}" | |
134 break | |
135 fi | |
136 test_dir=$(dirname "${test_dir}") | |
137 done | |
138 fi | |
139 | |
140 if [[ -z "${FLAGS_top}" ]]; then | |
141 # Use the top directory based on where this script runs from | |
142 FLAGS_top=${GCLIENT_ROOT} | |
143 fi | |
144 | |
145 # Canonicalize any symlinks | |
146 if [[ -d "${FLAGS_top}" ]]; then | |
147 FLAGS_top=$(readlink -f "${FLAGS_top}") | |
148 fi | |
149 | |
150 if [[ -z "${FLAGS_chroot}" ]]; then | |
151 FLAGS_chroot="${FLAGS_top}/chroot" | |
152 fi | |
153 | |
154 # If chroot does not exist, force making it | |
155 if [[ ! -d "${FLAGS_chroot}" ]]; then | |
156 FLAGS_force_make_chroot=${FLAGS_TRUE} | |
157 fi | |
158 # If chrome_root option passed, set as option for ./enter_chroot | |
159 if [[ -n "${FLAGS_chrome_root}" ]]; then | |
160 chroot_options="--chrome_root=${FLAGS_chrome_root}" | |
161 fi | |
162 | |
163 if [[ -n "${FLAGS_test}" ]]; then | |
164 # If you specify that tests should be run, we assume the image | |
165 # is modified to run tests. | |
166 FLAGS_mod_image_for_test=${FLAGS_TRUE} | |
167 if [[ -n "${FLAGS_remote}" ]]; then | |
168 # If you specify that tests should be run, we assume you want | |
169 # to live update the image. | |
170 FLAGS_image_to_live=${FLAGS_TRUE} | |
171 else | |
172 # Otherwise we assume you want to run the VM tests. | |
173 FLAGS_image_to_vm=${FLAGS_TRUE} | |
174 fi | |
175 fi | |
176 | |
177 # If they gave us a remote host, then we assume they want us to do a live | |
178 # update. | |
179 if [[ -n "${FLAGS_remote}" ]]; then | |
180 FLAGS_image_to_live=${FLAGS_TRUE} | |
181 remote_access_init | |
182 fi | |
183 | |
184 # Figure out board. | |
185 if [[ -z "${FLAGS_board}" ]]; then | |
186 if [[ -n "${FLAGS_remote}" ]]; then | |
187 learn_board | |
188 else | |
189 get_default_board | |
190 [[ -z "${DEFAULT_BOARD}" ]] && DEFAULT_BOARD="x86-generic" | |
191 FLAGS_board="${DEFAULT_BOARD}" | |
192 fi | |
193 fi | |
194 | |
195 if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then | |
196 if [[ -n "${FLAGS_chrome_root}" ]]; then | |
197 if [ ! -d "${FLAGS_chrome_root}" ]; then | |
198 die "Cannot find ${FLAGS_chrome_root} (tildes not expanded)" | |
199 fi | |
200 if [ ! -d "${FLAGS_chrome_root}/src/third_party/cros" ]; then | |
201 die "You need to add .gclient lines for Chrome on Chrome OS" | |
202 fi | |
203 fi | |
204 fi | |
205 | |
206 # Grabbing a buildbot build is exclusive with syncing and building | |
207 if [[ -n "${FLAGS_grab_buildbot}" ]]; then | |
208 if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then | |
209 if [[ -z "${FLAGS_buildbot_uri}" ]]; then | |
210 die "--grab_buildbot=LATEST requires --buildbot_uri or setting \ | |
211 BUILDBOT_URI" | |
212 exit 1 | |
213 fi | |
214 fi | |
215 FLAGS_sync=${FLAGS_FALSE} | |
216 FLAGS_build=${FLAGS_FALSE} | |
217 FLAGS_unittest=${FLAGS_FALSE} | |
218 FLAGS_master=${FLAGS_FALSE} | |
219 fi | |
220 | |
221 if [[ ${FLAGS_image_to_live} -eq ${FLAGS_TRUE} ]]; then | |
222 if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_FALSE} ]]; then | |
223 warn "You have specified to live reimage a machine with" | |
224 warn "an image that is not modified for test (so it cannot be" | |
225 warn "later live reimaged)" | |
226 fi | |
227 if [[ -n "${FLAGS_image_to_usb}" ]]; then | |
228 warn "You have specified to both live reimage a machine and" | |
229 warn "write a USB image. Is this what you wanted?" | |
230 fi | |
231 if [[ -z "${FLAGS_remote}" ]]; then | |
232 die "Please specify --remote with --image_to_live" | |
233 fi | |
234 fi | |
235 | |
236 if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_TRUE} ]]; then | |
237 # Override any specified chronos password with the test one | |
238 FLAGS_chronos_passwd="test0000" | |
239 # If you're modding for test, you also want developer packages. | |
240 FLAGS_withdev=${FLAGS_TRUE} | |
241 fi | |
242 | |
243 if [[ -n "${FLAGS_image_to_usb}" ]]; then | |
244 local device=${FLAGS_image_to_usb#/dev/} | |
245 if [[ -z "${device}" ]]; then | |
246 die "Expected --image_to_usb option of /dev/* format" | |
247 fi | |
248 local is_removable=$(cat /sys/block/${device}/removable) | |
249 if [[ "${is_removable}" != "1" ]]; then | |
250 die "Could not verify that ${device} for image_to_usb is removable" | |
251 fi | |
252 fi | |
253 } | |
254 | |
255 function has_board_directory() { | |
256 [[ -d "${FLAGS_top}/chroot/build/${FLAGS_board}" ]] | |
257 } | |
258 | |
259 # Prints a description of what we are doing or did | |
260 function describe_steps() { | |
261 if [[ ${FLAGS_sync} -eq ${FLAGS_TRUE} ]]; then | |
262 local is_official="" | |
263 [ ${FLAGS_official} -eq ${FLAGS_TRUE} ] && is_official=" (official)" | |
264 info " * Sync client (repo sync)${is_official} (disable using --nosync)" | |
265 fi | |
266 if [[ ${FLAGS_force_make_chroot} -eq ${FLAGS_TRUE} ]]; then | |
267 info " * Rebuild chroot (make_chroot) in ${FLAGS_chroot}" | |
268 fi | |
269 local set_passwd=${FLAGS_FALSE} | |
270 if ! has_board_directory; then | |
271 info " * Setup new board ${FLAGS_board} (setup_board)" | |
272 fi | |
273 if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then | |
274 local extra_build="" | |
275 if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]]; then | |
276 extra_build=" with dev packages" | |
277 fi | |
278 if [[ ${FLAGS_oldchromebinary} -eq ${FLAGS_TRUE} ]]; then | |
279 extra_build=" (but pull Chrome binary)" | |
280 fi | |
281 info " * Build packages${extra_build} (build_packages) \ | |
282 (disable using --nobuild)" | |
283 set_passwd=${FLAGS_TRUE} | |
284 if [[ ${FLAGS_build_autotest} -eq ${FLAGS_TRUE} ]]; then | |
285 info " * Cross-build autotest client tests (build_autotest)" | |
286 fi | |
287 if [[ -n "${FLAGS_chrome_root}" ]]; then | |
288 info " * After Chrome builds in build_packages, building Chrome from \ | |
289 sources at ${FLAGS_chrome_root}" | |
290 fi | |
291 fi | |
292 if [[ ${FLAGS_master} -eq ${FLAGS_TRUE} ]]; then | |
293 info " * Master image (build_image) (disable using --nomaster)" | |
294 fi | |
295 if [[ -n "${FLAGS_grab_buildbot}" ]]; then | |
296 if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then | |
297 info " * Grab latest buildbot image under ${FLAGS_buildbot_uri}" | |
298 else | |
299 info " * Grab buildbot image zip at URI ${FLAGS_grab_buildbot}" | |
300 fi | |
301 fi | |
302 if [[ ${FLAGS_unittest} -eq ${FLAGS_TRUE} ]]; then | |
303 info " * Run cros_run_unit_tests to run all unit tests \ | |
304 (disable using --nounittest)" | |
305 fi | |
306 if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_TRUE} ]]; then | |
307 if [[ -n "${FLAGS_grab_buildbot}" ]]; then | |
308 info " * Use the prebuilt image modded for test (rootfs_test.image)" | |
309 info " * Install prebuilt cross-compiled autotests in chroot" | |
310 else | |
311 info " * Make image able to run tests (mod_image_for_test)" | |
312 fi | |
313 set_passwd=${FLAGS_TRUE} | |
314 else | |
315 info " * Not modifying image for test (enable using --mod_image_for_test)" | |
316 fi | |
317 if [[ ${set_passwd} -eq ${FLAGS_TRUE} ]]; then | |
318 if [[ -n "${FLAGS_chronos_passwd}" ]]; then | |
319 info " * Set chronos password to ${FLAGS_chronos_passwd}" | |
320 else | |
321 info " * Set chronos password randomly" | |
322 fi | |
323 fi | |
324 if [[ -n "${FLAGS_image_to_usb}" ]]; then | |
325 info " * Write the image to USB device ${FLAGS_image_to_usb}" | |
326 fi | |
327 if [[ ${FLAGS_image_to_live} -eq ${FLAGS_TRUE} ]]; then | |
328 info " * Reimage live test Chromium OS instance at ${FLAGS_remote}" | |
329 fi | |
330 if [[ ${FLAGS_image_to_vm} -eq ${FLAGS_TRUE} ]]; then | |
331 info " * Copy off a separate VM image" | |
332 fi | |
333 if [[ -n "${FLAGS_test}" ]]; then | |
334 if [[ -n "${FLAGS_remote}" ]]; then | |
335 info " * Run (and build) tests (${FLAGS_test}) on machine at \ | |
336 ${FLAGS_remote}" | |
337 else | |
338 info " * Start a VM locally and run (and build) tests (${FLAGS_test}) \ | |
339 on it" | |
340 fi | |
341 else | |
342 info " * Not running any autotests (pass --test=suite_Smoke for instance \ | |
343 to change)" | |
344 fi | |
345 } | |
346 | |
347 # Prompt user Y/N to continue | |
348 function prompt_to_continue() { | |
349 if [ ${FLAGS_yes} -eq ${FLAGS_TRUE} ]; then | |
350 info "Continuing without prompting since you passed --yes" | |
351 return | |
352 fi | |
353 echo "" | |
354 read -p "Are you sure (y/N)? " SURE | |
355 echo "(Pass -y to skip this prompt)" | |
356 echo "" | |
357 # Get just the first character | |
358 if [[ "${SURE:0:1}" != "y" ]]; then | |
359 die "Ok, better safe than sorry." | |
360 fi | |
361 } | |
362 | |
363 # Get user's permission on steps to take | |
364 function interactive() { | |
365 echo "" | |
366 info "Planning these steps on ${FLAGS_top} for ${FLAGS_board}:" | |
367 describe_steps | |
368 prompt_to_continue | |
369 } | |
370 | |
371 # Changes to a directory relative to the top/root directory of | |
372 # the checkout. | |
373 # Arguments: | |
374 # $1 - relative path | |
375 function chdir_relative() { | |
376 local dir=$1 | |
377 info "Running: cd ${dir}" | |
378 # Allow use of .. before the innermost directory of FLAGS_top exists | |
379 if [[ "${dir}" == ".." ]]; then | |
380 dir=$(dirname "${FLAGS_top}") | |
381 else | |
382 dir="${FLAGS_top}/${dir}" | |
383 fi | |
384 cd "${dir}" | |
385 } | |
386 | |
387 | |
388 function info_div { | |
389 info "#############################################################" | |
390 } | |
391 | |
392 # Describe to the user that a phase is running (and make it obviously when | |
393 # scrolling through lots of output). | |
394 # Arguments: | |
395 # $1 - phase description | |
396 function describe_phase() { | |
397 local desc="$1" | |
398 echo "" | |
399 info_div | |
400 info "${desc}" | |
401 } | |
402 | |
403 function cleanup() { | |
404 [ -n "${TMP}" ] && rm -rf "${TMP}" | |
405 cleanup_remote_access | |
406 } | |
407 | |
408 # Called when there is a failure and we exit early | |
409 function failure() { | |
410 trap - EXIT | |
411 # Clear these out just in case. | |
412 export GSDCURL_USERNAME="" | |
413 export GSDCURL_PASSWORD="" | |
414 describe_phase "Failure during: ${LAST_PHASE}" | |
415 show_duration | |
416 info_div | |
417 cleanup | |
418 } | |
419 | |
420 | |
421 # Runs a phase, describing it first, and also updates the sudo timeout | |
422 # afterwards. | |
423 # Arguments: | |
424 # $1 - phase description | |
425 # $2.. - command/params to run | |
426 function run_phase() { | |
427 local desc="$1" | |
428 shift | |
429 LAST_PHASE="${desc}" | |
430 describe_phase "${desc}" | |
431 local line="Running: " | |
432 line+=$@ | |
433 info "${line}" | |
434 info_div | |
435 echo "" | |
436 "$@" | |
437 sudo true | |
438 } | |
439 | |
440 | |
441 # Runs a phase, similar to run_phase, but runs within the chroot. | |
442 # Arguments: | |
443 # $1 - phase description | |
444 # $2.. - command/params to run in chroot | |
445 function run_phase_in_chroot() { | |
446 local desc="$1" | |
447 shift | |
448 run_phase "${desc}" ./enter_chroot.sh "--chroot=${FLAGS_chroot}" \ | |
449 ${chroot_options} -- "$@" | |
450 } | |
451 | |
452 | |
453 # Record start time. | |
454 function set_start_time() { | |
455 START_TIME=$(date '+%s') | |
456 } | |
457 | |
458 | |
459 # Display duration | |
460 function show_duration() { | |
461 local current_time=$(date '+%s') | |
462 local duration=$((${current_time} - ${START_TIME})) | |
463 local minutes_duration=$((${duration} / 60)) | |
464 local seconds_duration=$((${duration} % 60)) | |
465 info "$(printf "Total time: %d:%02ds\n" "${minutes_duration}" \ | |
466 "${seconds_duration}")" | |
467 } | |
468 | |
469 # Runs repo init on a new checkout directory. | |
470 function config_new_repo_checkout() { | |
471 mkdir -p "${FLAGS_top}" | |
472 cd "${FLAGS_top}" | |
473 local minilayout="" | |
474 [ ${FLAGS_minilayout} -eq ${FLAGS_TRUE} ] && minilayout="-m minilayout.xml" | |
475 local git_uri="http://git.chromium.org/git/manifest" | |
476 if [ ${FLAGS_official} -eq ${FLAGS_TRUE} ]; then | |
477 git_uri="ssh://git@gitrw.chromium.org:9222/manifest-internal" | |
478 fi | |
479 repo init -u "${git_uri}" ${minilayout} | |
480 } | |
481 | |
482 # Configures/initializes a new checkout | |
483 function config_new_checkout() { | |
484 info "Checking out ${FLAGS_top}" | |
485 config_new_repo_checkout | |
486 } | |
487 | |
488 # Runs gclient sync, setting up .chromeos_dev and preparing for | |
489 # local repo setup | |
490 function sync() { | |
491 # cd to the directory below | |
492 chdir_relative . | |
493 run_phase "Synchronizing client" repo sync | |
494 # Change to a directory that is definitely a git repo | |
495 chdir_relative src/third_party/chromiumos-overlay | |
496 git cl config "file://$(pwd)/../../../codereview.settings" | |
497 chdir_relative . | |
498 } | |
499 | |
500 | |
501 # Downloads a buildbot image | |
502 function grab_buildbot() { | |
503 read -p "Username [${LOGNAME}]: " GSDCURL_USERNAME | |
504 export GSDCURL_USERNAME | |
505 read -s -p "Password: " GSDCURL_PASSWORD | |
506 export GSDCURL_PASSWORD | |
507 CURL="${SCRIPTS_DIR}/bin/cros_gsdcurl.py" | |
508 if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then | |
509 local latest=$(${CURL} "${FLAGS_buildbot_uri}/LATEST") | |
510 if [[ -z "${latest}" ]]; then | |
511 die "Error finding latest." | |
512 fi | |
513 FLAGS_grab_buildbot="${FLAGS_buildbot_uri}/${latest}/image.zip" | |
514 fi | |
515 local dl_dir="${TMP}/image" | |
516 mkdir -p "${dl_dir}" | |
517 | |
518 info "Grabbing image from ${FLAGS_grab_buildbot} to ${dl_dir}" | |
519 run_phase "Downloading image" ${CURL} "${FLAGS_grab_buildbot}" \ | |
520 -o "${dl_dir}/image.zip" | |
521 # Clear out the credentials so they can't be used later. | |
522 export GSDCURL_USERNAME="" | |
523 export GSDCURL_PASSWORD="" | |
524 | |
525 cd "${dl_dir}" | |
526 unzip image.zip | |
527 local image_basename=$(basename "$(dirname "${FLAGS_grab_buildbot}")") | |
528 local image_base_dir="${FLAGS_top}/src/build/images/${FLAGS_board}" | |
529 local image_dir="${image_base_dir}/${image_basename}" | |
530 info "Copying in build image to ${image_dir}" | |
531 rm -rf "${image_dir}" | |
532 mkdir -p "${image_dir}" | |
533 if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_TRUE} ]]; then | |
534 run_phase "Installing buildbot test modified image" \ | |
535 mv chromiumos_test_image.bin "${image_dir}/chromiumos_image.bin" | |
536 FLAGS_mod_image_for_test=${FLAGS_FALSE} | |
537 else | |
538 run_phase "Installing buildbot base image" \ | |
539 mv chromiumos_base_image.bin "${image_dir}/chromiumos_image.bin" | |
540 fi | |
541 | |
542 if [[ -n "${FLAGS_test}" ]]; then | |
543 if [[ ! -d "${FLAGS_top}/chroot/build/${FLAGS_board}" ]]; then | |
544 die "To run tests on a buildbot image, run setup_board first." | |
545 fi | |
546 if [[ -e "autotest.tgz" || -e "autotest.tar.bz2" ]]; then | |
547 # pull in autotest | |
548 local dir="${FLAGS_chroot}/build/${FLAGS_board}/usr/local" | |
549 local tar_args="xzf" | |
550 local tar_name="${dl_dir}/autotest.tgz" | |
551 if [[ -e "autotest.tar.bz2" ]]; then | |
552 tar_args="xjf" | |
553 tar_name="${dl_dir}/autotest.tar.bz2" | |
554 fi | |
555 sudo rm -rf "${dir}/autotest" | |
556 # Expand in temp directory as current user, then move it as | |
557 # root to keep local user ownership | |
558 run_phase "Unpacking buildbot autotest cross-compiled binaries" \ | |
559 tar ${tar_args} "${tar_name}" | |
560 run_phase "Installing buildbot autotest cross-compiled binaries" \ | |
561 sudo mv autotest ${dir} | |
562 fi | |
563 fi | |
564 chdir_relative . | |
565 run_phase "Removing downloaded image" rm -rf "${dl_dir}" | |
566 } | |
567 | |
568 | |
569 function main() { | |
570 assert_outside_chroot | |
571 assert_not_root_user | |
572 | |
573 # Parse command line | |
574 FLAGS "$@" || exit 1 | |
575 eval set -- "${FLAGS_ARGV}" | |
576 | |
577 # Die on any errors. | |
578 set -e | |
579 | |
580 validate_and_set_param_defaults | |
581 | |
582 # Cache up sudo status | |
583 sudo true | |
584 | |
585 interactive | |
586 | |
587 set_start_time | |
588 trap failure EXIT | |
589 | |
590 local withdev_param="" | |
591 if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]]; then | |
592 withdev_param="--withdev" | |
593 fi | |
594 | |
595 local jobs_param="" | |
596 if [[ ${FLAGS_jobs} -gt 1 ]]; then | |
597 jobs_param="--jobs=${FLAGS_jobs}" | |
598 fi | |
599 | |
600 local board_param="--board=${FLAGS_board}" | |
601 | |
602 if [[ ! -e "${FLAGS_top}" ]]; then | |
603 config_new_checkout | |
604 fi | |
605 | |
606 if [[ ${FLAGS_sync} -eq ${FLAGS_TRUE} ]]; then | |
607 sync | |
608 fi | |
609 | |
610 if [[ -n "${FLAGS_grab_buildbot}" ]]; then | |
611 grab_buildbot | |
612 fi | |
613 | |
614 if [[ ${FLAGS_force_make_chroot} -eq ${FLAGS_TRUE} ]]; then | |
615 chdir_relative src/scripts | |
616 run_phase "Replacing chroot" ./make_chroot --replace \ | |
617 "--chroot=${FLAGS_chroot}" ${jobs_param} | |
618 fi | |
619 | |
620 if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then | |
621 # It's necessary to enable localaccount for BVT tests to pass. | |
622 chdir_relative src/scripts | |
623 run_phase "Enable local account" \ | |
624 ./enable_localaccount.sh chronos "${FLAGS_chroot}" | |
625 | |
626 local pkg_param="" | |
627 if [[ ${FLAGS_usepkg} -eq ${FLAGS_FALSE} ]]; then | |
628 pkg_param="--nousepkg" | |
629 fi | |
630 | |
631 chdir_relative src/scripts | |
632 # Only setup board target if the directory does not exist | |
633 if ! has_board_directory; then | |
634 run_phase_in_chroot "Setting up board target" \ | |
635 ./setup_board ${pkg_param} "${board_param}" | |
636 fi | |
637 local build_autotest_param="" | |
638 if [[ ${FLAGS_build_autotest} -eq ${FLAGS_TRUE} ]]; then | |
639 build_autotest_param="--withautotest" | |
640 fi | |
641 if [[ ${FLAGS_oldchromebinary} -eq ${FLAGS_TRUE} ]]; then | |
642 pkg_param="${pkg_param} --oldchromebinary" | |
643 fi | |
644 | |
645 run_phase_in_chroot "Building packages" \ | |
646 ./build_packages "${board_param}" \ | |
647 ${withdev_param} ${build_autotest_param} \ | |
648 ${pkg_param} | |
649 fi | |
650 | |
651 if [[ ${FLAGS_chrome_root} ]]; then | |
652 chdir_relative src/scripts | |
653 # You can always pass USE=gold, the ebuild will only really use | |
654 # gold if x86 and the binaries are found. | |
655 local chrome_use="" | |
656 if [ ${FLAGS_chrome_gold} -eq ${FLAGS_TRUE} ]; then | |
657 chrome_use="${chrome_use} gold" | |
658 fi | |
659 if [ ${FLAGS_official} -eq ${FLAGS_TRUE} ]; then | |
660 chrome_use="${chrome_use} internal" | |
661 fi | |
662 [ -z "${FLAGS_test}" ] && chrome_use="${chrome_use} -build_tests" | |
663 run_phase_in_chroot "Building Chromium browser" env \ | |
664 BOARD="${FLAGS_board}" USE="${chrome_use}" FEATURES="-usersandbox" \ | |
665 CHROME_ORIGIN=LOCAL_SOURCE emerge-${FLAGS_board} chromeos-chrome | |
666 fi | |
667 | |
668 if [[ ${FLAGS_unittest} -eq ${FLAGS_TRUE} ]] && \ | |
669 [[ "${FLAGS_board}" == "x86-generic" ]] ; then | |
670 chdir_relative src/scripts | |
671 run_phase_in_chroot "Running unit tests" ./cros_run_unit_tests \ | |
672 ${board_param} | |
673 fi | |
674 | |
675 if [[ ${FLAGS_master} -eq ${FLAGS_TRUE} ]]; then | |
676 chdir_relative src/scripts | |
677 if [[ -n "${FLAGS_chronos_passwd}" ]]; then | |
678 run_phase_in_chroot "Setting default chronos password" \ | |
679 sh -c "echo '${FLAGS_chronos_passwd}' | \ | |
680 ~/trunk/src/scripts/set_shared_user_password.sh" | |
681 fi | |
682 local other_params="--enable_rootfs_verification" | |
683 if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_FALSE} ]]; then | |
684 other_params="--noenable_rootfs_verification" | |
685 fi | |
686 run_phase_in_chroot "Mastering image" ./build_image \ | |
687 "${board_param}" --replace ${withdev_param} \ | |
688 ${jobs_param} ${other_params} | |
689 fi | |
690 | |
691 if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_TRUE} ]]; then | |
692 chdir_relative src/scripts | |
693 run_phase_in_chroot "Modifying image for test" \ | |
694 "./mod_image_for_test.sh" "${board_param}" --yes | |
695 fi | |
696 | |
697 if [[ -n "${FLAGS_image_to_usb}" ]]; then | |
698 chdir_relative src/scripts | |
699 run_phase "Installing image to USB" \ | |
700 ./image_to_usb.sh --yes "--to=${FLAGS_image_to_usb}" "${board_param}" | |
701 fi | |
702 | |
703 if [[ ${FLAGS_image_to_live} -eq ${FLAGS_TRUE} ]]; then | |
704 chdir_relative src/scripts | |
705 run_phase "Re-imaging live Chromium OS machine ${FLAGS_remote}" \ | |
706 ./image_to_live.sh "--remote=${FLAGS_remote}" --update_known_hosts | |
707 fi | |
708 | |
709 if [[ ${FLAGS_image_to_vm} -eq ${FLAGS_TRUE} ]]; then | |
710 chdir_relative src/scripts | |
711 run_phase_in_chroot "Creating VM image from existing image" \ | |
712 ./image_to_vm.sh "--board=${FLAGS_board}" | |
713 fi | |
714 | |
715 if [[ -n "${FLAGS_test}" ]]; then | |
716 chdir_relative src/scripts | |
717 if [[ -z "${FLAGS_remote}" ]]; then | |
718 # Launch remote machine and run tests. We need first to | |
719 # figure out what IP to use. | |
720 if ! run_phase "Running VM tests locally" \ | |
721 ./bin/cros_run_vm_test "--board=${FLAGS_board}" \ | |
722 "--test_case=${FLAGS_test}" ${FLAGS_vm_options}; then | |
723 if [[ ${FLAGS_ignore_remote_test_failures} -eq ${FLAGS_FALSE} ]]; then | |
724 die "VM tests failed and --ignore_remote_test_failures not passed" | |
725 fi | |
726 fi | |
727 else | |
728 # We purposefully do not quote FLAGS_test below as we expect it may | |
729 # have multiple parameters | |
730 if ! run_phase "Running tests on Chromium OS machine ${FLAGS_remote}" \ | |
731 ./run_remote_tests.sh "--remote=${FLAGS_remote}" ${FLAGS_test} \ | |
732 "${board_param}" --build; then | |
733 if [[ ${FLAGS_ignore_remote_test_failures} -eq ${FLAGS_FALSE} ]]; then | |
734 die "Remote tests failed and --ignore_remote_test_failures not passed" | |
735 fi | |
736 fi | |
737 fi | |
738 fi | |
739 | |
740 trap cleanup EXIT | |
741 echo "" | |
742 info_div | |
743 info "Successfully used ${FLAGS_top} to:" | |
744 describe_steps | |
745 show_duration | |
746 info_div | |
747 } | |
748 | |
749 main "$@" | |
750 | |
OLD | NEW |