crosutils: enable learning board type and setting localaccount

Change-Id: Ib2509f2f8f650e037cad173496930ec71eeb64ef

BUG=n0ne
TEST=various invocations though mostly --remote=IP --test=bvt

Review URL: http://codereview.chromium.org/4104004
This commit is contained in:
Ken Mixter 2011-01-21 17:30:17 -08:00
parent 3343f56b77
commit 60dabf1a79

View File

@ -44,21 +44,24 @@
# Load common constants. This should be the first executable line. # Load common constants. This should be the first executable line.
# The path to common.sh should be relative to your script's location. # The path to common.sh should be relative to your script's location.
. "$(dirname "$0")/common.sh" . "$(dirname "$0")/common.sh"
# Allow remote access (for learning board type)
. "$(dirname "$0")/remote_access.sh"
DEFINE_string board "" "Board setting"
DEFINE_string board "x86-generic" "Board setting"
DEFINE_boolean build ${FLAGS_TRUE} \ DEFINE_boolean build ${FLAGS_TRUE} \
"Build all code (but not necessarily master image)" "Build all code (but not necessarily master image)"
DEFINE_boolean build_autotest ${FLAGS_FALSE} "Build autotest" DEFINE_boolean build_autotest ${FLAGS_FALSE} "Build autotest"
DEFINE_string buildbot_uri "${BUILDBOT_URI}" \ DEFINE_string buildbot_uri "${BUILDBOT_URI}" \
"Base URI to buildbot build location which contains LATEST file" "Base URI to buildbot build location which contains LATEST file"
DEFINE_string chrome_gold ${FLAGS_TRUE} \
"Build Chrome using gold if it is installed and supported."
DEFINE_string chrome_root "" \ DEFINE_string chrome_root "" \
"The root of your chrome browser source. Should contain a 'src' subdir. \ "The root of your chrome browser source. Should contain a 'src' subdir. \
If this is set, chrome browser will be built from source." If this is set, chrome browser will be built from source."
DEFINE_string chronos_passwd "${CHRONOS_PASSWD}" \ DEFINE_string chronos_passwd "${CHRONOS_PASSWD}" \
"Use this as the chronos user passwd (defaults to \$CHRONOS_PASSWD)" "Use this as the chronos user passwd (defaults to \$CHRONOS_PASSWD)"
DEFINE_string chroot "" "Chroot to build/use" DEFINE_string chroot "" "Chroot to build/use"
DEFINE_boolean enable_rootfs_verification ${FLAGS_TRUE} \ DEFINE_boolean enable_rootfs_verification ${FLAGS_FALSE} \
"Enable rootfs verification when building image" "Enable rootfs verification when building image"
DEFINE_boolean force_make_chroot ${FLAGS_FALSE} "Run make_chroot indep of sync" DEFINE_boolean force_make_chroot ${FLAGS_FALSE} "Run make_chroot indep of sync"
DEFINE_string grab_buildbot "" \ DEFINE_string grab_buildbot "" \
@ -68,28 +71,28 @@ DEFINE_boolean ignore_remote_test_failures ${FLAGS_FALSE} \
"Ignore any remote tests that failed and don't return failure" "Ignore any remote tests that failed and don't return failure"
DEFINE_boolean image_to_live ${FLAGS_FALSE} \ DEFINE_boolean image_to_live ${FLAGS_FALSE} \
"Put the resulting image on live instance (requires --remote)" "Put the resulting image on live instance (requires --remote)"
DEFINE_boolean image_to_vm ${FLAGS_FALSE} "Create a VM image"
DEFINE_string image_to_usb "" \ DEFINE_string image_to_usb "" \
"Treat this device as USB and put the image on it after build" "Treat this device as USB and put the image on it after build"
# You can set jobs > 1 but then your build may break and you may need # You can set jobs > 1 but then your build may break and you may need
# to retry. Setting it to 1 is best for non-interactive sessions. # to retry. Setting it to 1 is best for non-interactive sessions.
DEFINE_boolean interactive ${FLAGS_FALSE} \
"Tell user what we plan to do and wait for input to proceed" i
DEFINE_integer jobs -1 "Concurrent build jobs" DEFINE_integer jobs -1 "Concurrent build jobs"
DEFINE_boolean master ${FLAGS_TRUE} "Master an image from built code" DEFINE_boolean master ${FLAGS_TRUE} "Master an image from built code"
DEFINE_boolean minilayout ${FLAGS_FALSE} "Use minimal code checkout" DEFINE_boolean minilayout ${FLAGS_FALSE} "Use minimal code checkout"
DEFINE_boolean mod_image_for_test ${FLAGS_FALSE} "Modify the image for testing" DEFINE_boolean mod_image_for_test ${FLAGS_FALSE} "Modify the image for testing"
DEFINE_string remote "" \ DEFINE_boolean official ${FLAGS_FALSE} "Sync/Build/Test official Chrome OS"
"Use this hostname/IP for live updating and running tests" DEFINE_boolean oldchromebinary ${FLAGS_TRUE} "Always use chrome binary package"
DEFINE_string repo "${CHROMIUMOS_REPO}" "gclient repo for chromiumos" DEFINE_string repo "${CHROMIUMOS_REPO}" "gclient repo for chromiumos"
DEFINE_boolean sync ${FLAGS_TRUE} "Sync the checkout" DEFINE_boolean sync ${FLAGS_TRUE} "Sync the checkout"
DEFINE_string test "" \ DEFINE_string test "" \
"Test the built image with the given params to run_remote_tests" "Test the built image with the given params to run_remote_tests"
DEFINE_string top "" \ DEFINE_string top "" \
"Root directory of your checkout (defaults to determining from your cwd)" "Root directory of your checkout (defaults to determining from your cwd)"
DEFINE_string vm_options "--no_graphics" "VM options"
DEFINE_boolean withdev ${FLAGS_TRUE} "Build development packages" DEFINE_boolean withdev ${FLAGS_TRUE} "Build development packages"
DEFINE_boolean usepkg ${FLAGS_TRUE} "Use binary packages" DEFINE_boolean usepkg ${FLAGS_TRUE} "Use binary packages"
DEFINE_boolean useworkon ${FLAGS_TRUE} "Use cros_workon/repo workflow"
DEFINE_boolean unittest ${FLAGS_TRUE} "Run unit tests" DEFINE_boolean unittest ${FLAGS_TRUE} "Run unit tests"
DEFINE_boolean yes ${FLAGS_FALSE} "Reply yes to all prompts" y
# Returns a heuristic indicating if we believe this to be a google internal # Returns a heuristic indicating if we believe this to be a google internal
# development environment. # development environment.
@ -104,6 +107,8 @@ function is_google_environment() {
# Validates parameters and sets "intelligent" defaults based on other # Validates parameters and sets "intelligent" defaults based on other
# parameters. # parameters.
function validate_and_set_param_defaults() { function validate_and_set_param_defaults() {
TMP=$(mktemp -d "/tmp/sync_build_test.XXXX")
if [[ -z "${FLAGS_top}" ]]; then if [[ -z "${FLAGS_top}" ]]; then
local test_dir=$(pwd) local test_dir=$(pwd)
while [[ "${test_dir}" != "/" ]]; do while [[ "${test_dir}" != "/" ]]; do
@ -125,15 +130,6 @@ function validate_and_set_param_defaults() {
FLAGS_top=$(readlink -f "${FLAGS_top}") FLAGS_top=$(readlink -f "${FLAGS_top}")
fi fi
if [[ -d "${FLAGS_top}" ]]; then
# Auto detect the right workflow.
if [[ -d "${FLAGS_top}/.git" ]]; then
FLAGS_useworkon=${FLAGS_FALSE}
else
FLAGS_useworkon=${FLAGS_TRUE}
fi
fi
if [[ -z "${FLAGS_chroot}" ]]; then if [[ -z "${FLAGS_chroot}" ]]; then
FLAGS_chroot="${FLAGS_top}/chroot" FLAGS_chroot="${FLAGS_top}/chroot"
fi fi
@ -147,26 +143,17 @@ function validate_and_set_param_defaults() {
chroot_options="--chrome_root=${FLAGS_chrome_root}" chroot_options="--chrome_root=${FLAGS_chrome_root}"
fi fi
if [[ -z "${FLAGS_repo}" ]]; then
if is_google_environment; then
FLAGS_repo="ssh://git@chromiumos-git//chromeos"
else
FLAGS_repo="http://src.chromium.org/git/chromiumos.git"
fi
fi
if [[ -n "${FLAGS_test}" ]]; then if [[ -n "${FLAGS_test}" ]]; then
# If you specify that tests should be run, we assume the image # If you specify that tests should be run, we assume the image
# is modified to run tests. # is modified to run tests.
FLAGS_mod_image_for_test=${FLAGS_TRUE} FLAGS_mod_image_for_test=${FLAGS_TRUE}
# If you specify that tests should be run, we assume you want if [[ -n "${FLAGS_remote}" ]]; then
# to live update the image. # If you specify that tests should be run, we assume you want
FLAGS_image_to_live=${FLAGS_TRUE} # to live update the image.
if [[ ${FLAGS_useworkon} -eq ${FLAGS_TRUE} ]]; then FLAGS_image_to_live=${FLAGS_TRUE}
# Currently the workon flow does not enable tests to be dynamically else
# built during run_remote_tests, so we need to build them all # Otherwise we assume you want to run the VM tests.
# beforehand. FLAGS_image_to_vm=${FLAGS_TRUE}
FLAGS_build_autotest=${FLAGS_TRUE}
fi fi
fi fi
@ -174,14 +161,37 @@ function validate_and_set_param_defaults() {
# update. # update.
if [[ -n "${FLAGS_remote}" ]]; then if [[ -n "${FLAGS_remote}" ]]; then
FLAGS_image_to_live=${FLAGS_TRUE} FLAGS_image_to_live=${FLAGS_TRUE}
remote_access_init
fi
# Figure out board.
if [[ -z "${FLAGS_board}" ]]; then
if [[ -n "${FLAGS_remote}" ]]; then
learn_board
else
get_default_board
[[ -z "${DEFAULT_BOARD}" ]] && DEFAULT_BOARD="x86-generic"
FLAGS_board="${DEFAULT_BOARD}"
fi
fi
if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then
if [[ -n "${FLAGS_chrome_root}" ]]; then
if [ ! -d "${FLAGS_chrome_root}" ]; then
die "Cannot find ${FLAGS_chrome_root} (tildes not expanded)"
fi
if [ ! -d "${FLAGS_chrome_root}/src/third_party/cros" ]; then
die "You need to add .gclient lines for Chrome on Chrome OS"
fi
fi
fi fi
# Grabbing a buildbot build is exclusive with syncing and building # Grabbing a buildbot build is exclusive with syncing and building
if [[ -n "${FLAGS_grab_buildbot}" ]]; then if [[ -n "${FLAGS_grab_buildbot}" ]]; then
if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then
if [[ -z "${FLAGS_buildbot_uri}" ]]; then if [[ -z "${FLAGS_buildbot_uri}" ]]; then
echo "--grab_buildbot=LATEST requires --buildbot_uri or setting " die "--grab_buildbot=LATEST requires --buildbot_uri or setting \
echo "BUILDBOT_URI" BUILDBOT_URI"
exit 1 exit 1
fi fi
fi fi
@ -193,17 +203,16 @@ function validate_and_set_param_defaults() {
if [[ ${FLAGS_image_to_live} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_image_to_live} -eq ${FLAGS_TRUE} ]]; then
if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_FALSE} ]]; then if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_FALSE} ]]; then
echo "WARNING: You have specified to live reimage a machine with" warn "You have specified to live reimage a machine with"
echo "an image that is not modified for test (so it cannot be" warn "an image that is not modified for test (so it cannot be"
echo "later live reimaged)" warn "later live reimaged)"
fi fi
if [[ -n "${FLAGS_image_to_usb}" ]]; then if [[ -n "${FLAGS_image_to_usb}" ]]; then
echo "WARNING: You have specified to both live reimage a machine and" warn "You have specified to both live reimage a machine and"
echo "write a USB image. Is this what you wanted?" warn "write a USB image. Is this what you wanted?"
fi fi
if [[ -z "${FLAGS_remote}" ]]; then if [[ -z "${FLAGS_remote}" ]]; then
echo "Please specify --remote with --image_to_live" die "Please specify --remote with --image_to_live"
exit 1
fi fi
fi fi
@ -217,97 +226,129 @@ function validate_and_set_param_defaults() {
if [[ -n "${FLAGS_image_to_usb}" ]]; then if [[ -n "${FLAGS_image_to_usb}" ]]; then
local device=${FLAGS_image_to_usb#/dev/} local device=${FLAGS_image_to_usb#/dev/}
if [[ -z "${device}" ]]; then if [[ -z "${device}" ]]; then
echo "Expected --image_to_usb option of /dev/* format" die "Expected --image_to_usb option of /dev/* format"
exit 1
fi fi
local is_removable=$(cat /sys/block/${device}/removable) local is_removable=$(cat /sys/block/${device}/removable)
if [[ "${is_removable}" != "1" ]]; then if [[ "${is_removable}" != "1" ]]; then
echo "Could not verify that ${device} for image_to_usb is removable" die "Could not verify that ${device} for image_to_usb is removable"
exit 1
fi fi
fi fi
} }
function has_board_directory() {
[[ -d "${FLAGS_top}/chroot/build/${FLAGS_board}" ]]
}
# Prints a description of what we are doing or did # Prints a description of what we are doing or did
function describe_steps() { function describe_steps() {
if [[ ${FLAGS_sync} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_sync} -eq ${FLAGS_TRUE} ]]; then
if [[ ${FLAGS_useworkon} -eq ${FLAGS_TRUE} ]]; then local is_official=""
echo " * Sync client (repo sync)" [ ${FLAGS_official} -eq ${FLAGS_TRUE} ] && is_official=" (official)"
else info " * Sync client (repo sync)${is_official} (disable using --nosync)"
echo " * Sync client (gclient sync)"
fi
if is_google_environment; then
echo " * Create proper src/scripts/.chromeos_dev"
fi
fi fi
if [[ ${FLAGS_force_make_chroot} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_force_make_chroot} -eq ${FLAGS_TRUE} ]]; then
echo " * Rebuild chroot (make_chroot) in ${FLAGS_chroot}" info " * Rebuild chroot (make_chroot) in ${FLAGS_chroot}"
fi fi
local set_passwd=${FLAGS_FALSE} local set_passwd=${FLAGS_FALSE}
if ! has_board_directory; then
info " * Setup new board ${FLAGS_board} (setup_board)"
fi
if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then
local withdev="" local extra_build=""
local jobs=" single job (slow but safe)"
if [[ ${FLAGS_jobs} -gt 1 ]]; then
jobs=" ${FLAGS_jobs} jobs (may cause build failure)"
fi
if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]]; then
withdev=" with dev packages" extra_build=" with dev packages"
fi fi
echo " * Build image${withdev}${jobs}" if [[ ${FLAGS_oldchromebinary} -eq ${FLAGS_TRUE} ]]; then
extra_build=" (but pull Chrome binary)"
fi
info " * Build packages${extra_build} (build_packages) \
(disable using --nobuild)"
set_passwd=${FLAGS_TRUE} set_passwd=${FLAGS_TRUE}
if [[ ${FLAGS_build_autotest} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_build_autotest} -eq ${FLAGS_TRUE} ]]; then
echo " * Cross-build autotest client tests (build_autotest)" info " * Cross-build autotest client tests (build_autotest)"
fi
if [[ -n "${FLAGS_chrome_root}" ]]; then
info " * After Chrome builds in build_packages, building Chrome from \
sources at ${FLAGS_chrome_root}"
fi fi
fi fi
if [[ ${FLAGS_master} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_master} -eq ${FLAGS_TRUE} ]]; then
echo " * Master image (build_image)" info " * Master image (build_image) (disable using --nomaster)"
fi fi
if [[ -n "${FLAGS_grab_buildbot}" ]]; then if [[ -n "${FLAGS_grab_buildbot}" ]]; then
if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then
echo " * Grab latest buildbot image under ${FLAGS_buildbot_uri}" info " * Grab latest buildbot image under ${FLAGS_buildbot_uri}"
else else
echo " * Grab buildbot image zip at URI ${FLAGS_grab_buildbot}" info " * Grab buildbot image zip at URI ${FLAGS_grab_buildbot}"
fi fi
fi fi
if [[ ${FLAGS_unittest} -eq ${FLAGS_TRUE} ]]; then
info " * Run cros_run_unit_tests to run all unit tests \
(disable using --nounittest)"
fi
if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_TRUE} ]]; then
if [[ -n "${FLAGS_grab_buildbot}" ]]; then if [[ -n "${FLAGS_grab_buildbot}" ]]; then
echo " * Use the prebuilt image modded for test (rootfs_test.image)" info " * Use the prebuilt image modded for test (rootfs_test.image)"
echo " * Install prebuilt cross-compiled autotests in chroot" info " * Install prebuilt cross-compiled autotests in chroot"
else else
echo " * Make image able to run tests (mod_image_for_test)" info " * Make image able to run tests (mod_image_for_test)"
fi fi
set_passwd=${FLAGS_TRUE} set_passwd=${FLAGS_TRUE}
else
info " * Not modifying image for test (enable using --mod_image_for_test)"
fi fi
if [[ ${set_passwd} -eq ${FLAGS_TRUE} ]]; then if [[ ${set_passwd} -eq ${FLAGS_TRUE} ]]; then
if [[ -n "${FLAGS_chronos_passwd}" ]]; then if [[ -n "${FLAGS_chronos_passwd}" ]]; then
echo " * Set chronos password to ${FLAGS_chronos_passwd}" info " * Set chronos password to ${FLAGS_chronos_passwd}"
else else
echo " * Set chronos password randomly" info " * Set chronos password randomly"
fi fi
fi fi
if [[ -n "${FLAGS_image_to_usb}" ]]; then if [[ -n "${FLAGS_image_to_usb}" ]]; then
echo " * Write the image to USB device ${FLAGS_image_to_usb}" info " * Write the image to USB device ${FLAGS_image_to_usb}"
fi fi
if [[ ${FLAGS_image_to_live} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_image_to_live} -eq ${FLAGS_TRUE} ]]; then
echo " * Reimage live test Chromium OS instance at ${FLAGS_remote}" info " * Reimage live test Chromium OS instance at ${FLAGS_remote}"
fi
if [[ ${FLAGS_image_to_vm} -eq ${FLAGS_TRUE} ]]; then
info " * Copy off a separate VM image"
fi fi
if [[ -n "${FLAGS_test}" ]]; then if [[ -n "${FLAGS_test}" ]]; then
echo " * Run tests (${FLAGS_test}) on machine at ${FLAGS_remote}" if [[ -n "${FLAGS_remote}" ]]; then
info " * Run (and build) tests (${FLAGS_test}) on machine at \
${FLAGS_remote}"
else
info " * Start a VM locally and run (and build) tests (${FLAGS_test}) \
on it"
fi
else
info " * Not running any autotests (pass --test=suite_Smoke for instance \
to change)"
fi fi
} }
# Prompt user Y/N to continue
function prompt_to_continue() {
if [ ${FLAGS_yes} -eq ${FLAGS_TRUE} ]; then
info "Continuing without prompting since you passed --yes"
return
fi
echo ""
read -p "Are you sure (y/N)? " SURE
echo "(Pass -y to skip this prompt)"
echo ""
# Get just the first character
if [[ "${SURE:0:1}" != "y" ]]; then
die "Ok, better safe than sorry."
fi
}
# Get user's permission on steps to take # Get user's permission on steps to take
function interactive() { function interactive() {
echo "Planning these steps on ${FLAGS_top}:" echo ""
info "Planning these steps on ${FLAGS_top} for ${FLAGS_board}:"
describe_steps describe_steps
read -p "Are you sure (y/N)? " SURE prompt_to_continue
# Get just the first character
if [[ "${SURE:0:1}" != "y" ]]; then
echo "Ok, better safe than sorry."
exit 1
fi
} }
# Changes to a directory relative to the top/root directory of # Changes to a directory relative to the top/root directory of
@ -316,7 +357,7 @@ function interactive() {
# $1 - relative path # $1 - relative path
function chdir_relative() { function chdir_relative() {
local dir=$1 local dir=$1
echo "+ cd ${dir}" info "Running: cd ${dir}"
# Allow use of .. before the innermost directory of FLAGS_top exists # Allow use of .. before the innermost directory of FLAGS_top exists
if [[ "${dir}" == ".." ]]; then if [[ "${dir}" == ".." ]]; then
dir=$(dirname "${FLAGS_top}") dir=$(dirname "${FLAGS_top}")
@ -327,6 +368,10 @@ function chdir_relative() {
} }
function info_div {
info "#############################################################"
}
# Describe to the user that a phase is running (and make it obviously when # Describe to the user that a phase is running (and make it obviously when
# scrolling through lots of output). # scrolling through lots of output).
# Arguments: # Arguments:
@ -334,12 +379,14 @@ function chdir_relative() {
function describe_phase() { function describe_phase() {
local desc="$1" local desc="$1"
echo "" echo ""
echo "#" info_div
echo "#" info "${desc}"
echo "# ${desc}"
echo "#"
} }
function cleanup() {
[ -n "${TMP}" ] && rm -rf "${TMP}"
cleanup_remote_access
}
# Called when there is a failure and we exit early # Called when there is a failure and we exit early
function failure() { function failure() {
@ -349,6 +396,8 @@ function failure() {
export GSDCURL_PASSWORD="" export GSDCURL_PASSWORD=""
describe_phase "Failure during: ${LAST_PHASE}" describe_phase "Failure during: ${LAST_PHASE}"
show_duration show_duration
info_div
cleanup
} }
@ -362,9 +411,13 @@ function run_phase() {
shift shift
LAST_PHASE="${desc}" LAST_PHASE="${desc}"
describe_phase "${desc}" describe_phase "${desc}"
echo "+ $@" local line="Running: "
line+=$@
info "${line}"
info_div
echo ""
"$@" "$@"
sudo -v sudo true
} }
@ -392,22 +445,8 @@ function show_duration() {
local duration=$((${current_time} - ${START_TIME})) local duration=$((${current_time} - ${START_TIME}))
local minutes_duration=$((${duration} / 60)) local minutes_duration=$((${duration} / 60))
local seconds_duration=$((${duration} % 60)) local seconds_duration=$((${duration} % 60))
printf "Total time: %d:%02ds\n" "${minutes_duration}" "${seconds_duration}" info "$(printf "Total time: %d:%02ds\n" "${minutes_duration}" \
} "${seconds_duration}")"
# Runs gclient config on a new checkout directory.
function config_new_gclient_checkout() {
# We only know how to check out to a pattern like ~/foo/chromeos so
# make sure that's the pattern the user has given.
if [[ $(basename "${FLAGS_top}") != "chromeos" ]]; then
echo "The --top directory does not exist and to check it out requires"
echo "the name to end in chromeos (try --top=${FLAGS_top}/chromeos)"
exit 1
fi
local top_parent=$(dirname "${FLAGS_top}")
mkdir -p "${top_parent}"
cd "${top_parent}"
gclient config "${FLAGS_repo}"
} }
# Runs repo init on a new checkout directory. # Runs repo init on a new checkout directory.
@ -416,43 +455,29 @@ function config_new_repo_checkout() {
cd "${FLAGS_top}" cd "${FLAGS_top}"
local minilayout="" local minilayout=""
[ ${FLAGS_minilayout} -eq ${FLAGS_TRUE} ] && minilayout="-m minilayout.xml" [ ${FLAGS_minilayout} -eq ${FLAGS_TRUE} ] && minilayout="-m minilayout.xml"
repo init -u http://src.chromium.org/git/manifest ${minilayout} local git_uri="http://git.chromium.org/git/manifest"
if [ ${FLAGS_official} -eq ${FLAGS_TRUE} ]; then
git_uri="ssh://git@gitrw.chromium.org:9222/manifest-internal"
fi
repo init -u "${git_uri}" ${minilayout}
} }
# Configures/initializes a new checkout # Configures/initializes a new checkout
function config_new_checkout() { function config_new_checkout() {
echo "Checking out ${FLAGS_top}" info "Checking out ${FLAGS_top}"
if [[ ${FLAGS_useworkon} ]]; then config_new_repo_checkout
config_new_repo_checkout
else
config_new_gclient_checkout
fi
} }
# Runs gclient sync, setting up .chromeos_dev and preparing for # Runs gclient sync, setting up .chromeos_dev and preparing for
# local repo setup # local repo setup
function sync() { function sync() {
# cd to the directory below # cd to the directory below
if [[ ${FLAGS_useworkon} -eq ${FLAGS_TRUE} ]]; then
chdir_relative .
run_phase "Synchronizing client" repo sync
# Change to a directory that is definitely a git repo
chdir_relative src/third_party/chromiumos-overlay
git cl config "file://$(pwd)/../../../codereview.settings"
else
chdir_relative ..
run_phase "Synchronizing client" gclient sync
chdir_relative .
git cl config "file://$(pwd)/codereview.settings"
fi
chdir_relative . chdir_relative .
if is_google_environment; then run_phase "Synchronizing client" repo sync
local base_dir=$(dirname $(dirname "${FLAGS_top}")) # Change to a directory that is definitely a git repo
echo <<EOF > src/scripts/.chromeos_dev chdir_relative src/third_party/chromiumos-overlay
# Assume Chrome is checked out nearby git cl config "file://$(pwd)/../../../codereview.settings"
CHROMEOS_CHROME_DIR="${base_dir}/chrome" chdir_relative .
EOF
fi
} }
@ -466,14 +491,14 @@ function grab_buildbot() {
if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then
local latest=$(${CURL} "${FLAGS_buildbot_uri}/LATEST") local latest=$(${CURL} "${FLAGS_buildbot_uri}/LATEST")
if [[ -z "${latest}" ]]; then if [[ -z "${latest}" ]]; then
echo "Error finding latest." die "Error finding latest."
exit 1
fi fi
FLAGS_grab_buildbot="${FLAGS_buildbot_uri}/${latest}/image.zip" FLAGS_grab_buildbot="${FLAGS_buildbot_uri}/${latest}/image.zip"
fi fi
local dl_dir=$(mktemp -d "/tmp/image.XXXX") local dl_dir="${TMP}/image"
mkdir -p "${dl_dir}"
echo "Grabbing image from ${FLAGS_grab_buildbot} to ${dl_dir}" info "Grabbing image from ${FLAGS_grab_buildbot} to ${dl_dir}"
run_phase "Downloading image" ${CURL} "${FLAGS_grab_buildbot}" \ run_phase "Downloading image" ${CURL} "${FLAGS_grab_buildbot}" \
-o "${dl_dir}/image.zip" -o "${dl_dir}/image.zip"
# Clear out the credentials so they can't be used later. # Clear out the credentials so they can't be used later.
@ -485,7 +510,7 @@ function grab_buildbot() {
local image_basename=$(basename $(dirname "${FLAGS_grab_buildbot}")) local image_basename=$(basename $(dirname "${FLAGS_grab_buildbot}"))
local image_base_dir="${FLAGS_top}/src/build/images/${FLAGS_board}" local image_base_dir="${FLAGS_top}/src/build/images/${FLAGS_board}"
local image_dir="${image_base_dir}/${image_basename}" local image_dir="${image_base_dir}/${image_basename}"
echo "Copying in build image to ${image_dir}" info "Copying in build image to ${image_dir}"
rm -rf "${image_dir}" rm -rf "${image_dir}"
mkdir -p "${image_dir}" mkdir -p "${image_dir}"
if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_TRUE} ]]; then
@ -538,11 +563,9 @@ function main() {
validate_and_set_param_defaults validate_and_set_param_defaults
# Cache up sudo status # Cache up sudo status
sudo -v sudo true
if [[ ${FLAGS_interactive} -eq ${FLAGS_TRUE} ]]; then interactive
interactive
fi
set_start_time set_start_time
trap failure EXIT trap failure EXIT
@ -573,13 +596,16 @@ function main() {
if [[ ${FLAGS_force_make_chroot} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_force_make_chroot} -eq ${FLAGS_TRUE} ]]; then
chdir_relative src/scripts chdir_relative src/scripts
local extra_flags="--nouseworkon" run_phase "Replacing chroot" ./make_chroot --replace \
[[ ${FLAGS_useworkon} -eq ${FLAGS_TRUE} ]] && extra_flags="--useworkon"
run_phase "Replacing chroot" ./make_chroot ${extra_flags} --replace \
"--chroot=${FLAGS_chroot}" ${jobs_param} "--chroot=${FLAGS_chroot}" ${jobs_param}
fi fi
if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_build} -eq ${FLAGS_TRUE} ]]; then
# It's necessary to enable localaccount for BVT tests to pass.
chdir_relative src/scripts
run_phase "Enable local account" \
./enable_localaccount.sh chronos "${FLAGS_chroot}"
local pkg_param="" local pkg_param=""
if [[ ${FLAGS_usepkg} -eq ${FLAGS_FALSE} ]]; then if [[ ${FLAGS_usepkg} -eq ${FLAGS_FALSE} ]]; then
pkg_param="--nousepkg" pkg_param="--nousepkg"
@ -587,7 +613,7 @@ function main() {
chdir_relative src/scripts chdir_relative src/scripts
# Only setup board target if the directory does not exist # Only setup board target if the directory does not exist
if [[ ! -d "${FLAGS_top}/chroot/build/${FLAGS_board}" ]]; then if ! has_board_directory; then
run_phase_in_chroot "Setting up board target" \ run_phase_in_chroot "Setting up board target" \
./setup_board ${pkg_param} "${board_param}" ./setup_board ${pkg_param} "${board_param}"
fi fi
@ -595,21 +621,35 @@ function main() {
if [[ ${FLAGS_build_autotest} -eq ${FLAGS_TRUE} ]]; then if [[ ${FLAGS_build_autotest} -eq ${FLAGS_TRUE} ]]; then
build_autotest_param="--withautotest" build_autotest_param="--withautotest"
fi fi
if [[ ${FLAGS_oldchromebinary} -eq ${FLAGS_TRUE} ]]; then
pkg_param="${pkg_param} --oldchromebinary"
fi
run_phase_in_chroot "Building packages" \ run_phase_in_chroot "Building packages" \
./build_packages "${board_param}" \ ./build_packages "${board_param}" \
${jobs_param} ${withdev_param} ${build_autotest_param} \ ${withdev_param} ${build_autotest_param} \
${pkg_param} ${pkg_param}
fi fi
if [[ ${FLAGS_chrome_root} ]]; then if [[ ${FLAGS_chrome_root} ]]; then
run_phase_in_chroot "Building Chromium browser" \ chdir_relative src/scripts
BOARD="${FLAGS_board}" USE="build_tests" FEATURES="-usersandbox" \ # You can always pass USE=gold, the ebuild will only really use
# gold if x86 and the binaries are found.
local chrome_use=""
if [ ${FLAGS_chrome_gold} -eq ${FLAGS_TRUE} ]; then
chrome_use="${chrome_use} gold"
fi
if [ ${FLAGS_official} -eq ${FLAGS_TRUE} ]; then
chrome_use="${chrome_use} internal"
fi
[ -z "${FLAGS_test}" ] && chrome_use="${chrome_use} -build_tests"
run_phase_in_chroot "Building Chromium browser" env \
BOARD="${FLAGS_board}" USE="${chrome_use}" FEATURES="-usersandbox" \
CHROME_ORIGIN=LOCAL_SOURCE emerge-${FLAGS_board} chromeos-chrome CHROME_ORIGIN=LOCAL_SOURCE emerge-${FLAGS_board} chromeos-chrome
fi fi
if [[ ${FLAGS_unittest} -eq ${FLAGS_TRUE} ]] && [[ "${FLAGS_board}" == \ if [[ ${FLAGS_unittest} -eq ${FLAGS_TRUE} ]] && \
"x86-generic" ]] ; then [[ "${FLAGS_board}" == "x86-generic" ]] ; then
chdir_relative src/scripts chdir_relative src/scripts
run_phase_in_chroot "Running unit tests" ./cros_run_unit_tests \ run_phase_in_chroot "Running unit tests" ./cros_run_unit_tests \
${board_param} ${board_param}
@ -619,8 +659,8 @@ function main() {
chdir_relative src/scripts chdir_relative src/scripts
if [[ -n "${FLAGS_chronos_passwd}" ]]; then if [[ -n "${FLAGS_chronos_passwd}" ]]; then
run_phase_in_chroot "Setting default chronos password" \ run_phase_in_chroot "Setting default chronos password" \
./enter_chroot.sh "echo '${FLAGS_chronos_passwd}' | \ sh -c "echo '${FLAGS_chronos_passwd}' | \
~/trunk/src/scripts/set_shared_user_password.sh" ~/trunk/src/scripts/set_shared_user_password.sh"
fi fi
local other_params="--enable_rootfs_verification" local other_params="--enable_rootfs_verification"
if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_FALSE} ]]; then if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_FALSE} ]]; then
@ -649,25 +689,45 @@ function main() {
./image_to_live.sh "--remote=${FLAGS_remote}" --update_known_hosts ./image_to_live.sh "--remote=${FLAGS_remote}" --update_known_hosts
fi fi
if [[ ${FLAGS_image_to_vm} -eq ${FLAGS_TRUE} ]]; then
chdir_relative src/scripts
run_phase_in_chroot "Creating VM image from existing image" \
./image_to_vm.sh "--board=${FLAGS_board}"
fi
if [[ -n "${FLAGS_test}" ]]; then if [[ -n "${FLAGS_test}" ]]; then
chdir_relative src/scripts chdir_relative src/scripts
# We purposefully do not quote FLAGS_test below as we expect it may if [[ -z "${FLAGS_remote}" ]]; then
# have multiple parameters # Launch remote machine and run tests. We need first to
if ! run_phase "Running tests on Chromium OS machine ${FLAGS_remote}" \ # figure out what IP to use.
./run_remote_tests.sh "--remote=${FLAGS_remote}" ${FLAGS_test} \ if ! run_phase "Running VM tests locally" \
"${board_param}"; then ./bin/cros_run_vm_test "--board=${FLAGS_board}" \
if [[ ${FLAGS_ignore_remote_test_failures} -eq ${FLAGS_FALSE} ]]; then "--test_case=${FLAGS_test}" ${FLAGS_vm_options}; then
echo "Remote tests failed and --ignore_remote_test_failures not passed" if [[ ${FLAGS_ignore_remote_test_failures} -eq ${FLAGS_FALSE} ]]; then
false die "VM tests failed and --ignore_remote_test_failures not passed"
fi
fi
else
# We purposefully do not quote FLAGS_test below as we expect it may
# have multiple parameters
if ! run_phase "Running tests on Chromium OS machine ${FLAGS_remote}" \
./run_remote_tests.sh "--remote=${FLAGS_remote}" ${FLAGS_test} \
"${board_param}" --build; then
if [[ ${FLAGS_ignore_remote_test_failures} -eq ${FLAGS_FALSE} ]]; then
die "Remote tests failed and --ignore_remote_test_failures not passed"
fi
fi fi
fi fi
fi fi
trap - EXIT trap cleanup EXIT
echo "Successfully used ${FLAGS_top} to:" echo ""
info_div
info "Successfully used ${FLAGS_top} to:"
describe_steps describe_steps
show_duration show_duration
info_div
} }
main "$@"
main $@