From 34bbdc1996467b07704bc6025992487b08a98a2b Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Fri, 5 Jul 2013 21:45:05 -0400 Subject: [PATCH] fix(build_packages): Move gsutil code from build_packages to a library. To avoid making the same gsutil changes in more scripts move the code to a library file where some of the basic parts can be shared. --- build_library/release_util.sh | 37 +++++++++++++++++++++++++++++++++++ build_packages | 30 ++++++---------------------- 2 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 build_library/release_util.sh diff --git a/build_library/release_util.sh b/build_library/release_util.sh new file mode 100644 index 0000000000..ba669107df --- /dev/null +++ b/build_library/release_util.sh @@ -0,0 +1,37 @@ +# Copyright (c) 2013 The CoreOS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +GSUTIL_OPTS= +UPLOAD_ROOT="gs://storage.core-os.net/coreos" +UPLOAD_DEFAULT=${FLAGS_FALSE} +if [[ ${COREOS_OFFICIAL:-0} -eq 1 ]]; then + UPLOAD_DEFAULT=${FLAGS_TRUE} +fi + +DEFINE_boolean parallel ${FLAGS_TRUE} \ + "Enable parallelism in gsutil." +DEFINE_boolean upload ${UPLOAD_DEFAULT} \ + "Upload all packages/images via gsutil." + +check_gsutil_opts() { + [[ ${FLAGS_upload} -eq ${FLAGS_TRUE} ]] || return 0 + + if [[ ${FLAGS_parallel} -eq ${FLAGS_TRUE} ]]; then + GSUTIL_OPTS="-m" + fi + + if [[ ! -f "$HOME/.boto" ]]; then + die_notrace "Please run gsutil config to create ~/.boto" + fi +} + +upload_packages() { + [[ ${FLAGS_upload} -eq ${FLAGS_TRUE} ]] || return 0 + [[ -n "${BOARD}" ]] || die "board_options.sh must be sourced first" + + local BOARD_PACKAGES="${1:-"${BOARD_ROOT}/packages"}" + local UPLOAD_PATH="${UPLOAD_ROOT}/${BOARD}/${COREOS_VERSION_STRING}/pkgs/" + info "Uploading packages" + gsutil ${GSUTIL_OPTS} cp -R "${BOARD_PACKAGES}"/* "${UPLOAD_PATH}" +} diff --git a/build_packages b/build_packages index 73228d16cd..53334fd7c9 100755 --- a/build_packages +++ b/build_packages @@ -11,12 +11,6 @@ restart_in_chroot_if_needed "$@" assert_not_root_user -UPLOAD_ROOT="gs://storage.core-os.net/coreos" -UPLOAD_DEFAULT=${FLAGS_FALSE} -if [[ ${COREOS_OFFICIAL:-0} -eq 1 ]]; then - UPLOAD_DEFAULT=${FLAGS_TRUE} -fi - # Developer-visible flags. DEFINE_string board "${DEFAULT_BOARD}" \ "The board to build packages for." @@ -32,10 +26,9 @@ DEFINE_boolean withautotest "${FLAGS_TRUE}" \ "Build autotest client code." DEFINE_boolean fetchonly "${FLAGS_FALSE}" \ "Don't build anything, instead only fetch what is needed." -DEFINE_boolean parallel ${FLAGS_TRUE} \ - "Enable parallelism in gsutil." -DEFINE_boolean upload ${UPLOAD_DEFAULT} \ - "Upload all packages via gsutil." + +# include upload options +. "${BUILD_LIBRARY_DIR}/release_util.sh" || exit 1 FLAGS_HELP="usage: $(basename $0) [flags] [packages] @@ -95,9 +88,7 @@ if [[ -z "${FLAGS_board}" ]]; then exit 1 fi -if [[ ${FLAGS_upload} -eq ${FLAGS_TRUE} && ! -f "$HOME/.boto" ]]; then - die_notrace "Please run gsutil config to create ~/.boto" -fi +check_gsutil_opts CHROMITE_BIN="${GCLIENT_ROOT}/chromite/bin" @@ -246,17 +237,8 @@ info "Merging board packages now" tee "${tmpfile}" ) -if [[ ${FLAGS_upload} -eq ${FLAGS_TRUE} ]]; then - GSUTIL_OPTS= - if [[ ${FLAGS_parallel} -eq ${FLAGS_TRUE} ]]; then - GSUTIL_OPTS="-m" - fi - - BOARD_PACKAGES="${BOARD_ROOT}/packages" - UPLOAD_PATH="${UPLOAD_ROOT}/${BOARD}/${COREOS_VERSION_STRING}/pkgs/" - info "Uploading packages" - gsutil ${GSUTIL_OPTS} cp -R "${BOARD_PACKAGES}"/* "${UPLOAD_PATH}" -fi +# upload packages if enabled +upload_packages # Extract total package count from emerge output. package_count=$(awk '$0 ~ /^Total: [0-9]+ packages/ { print $2 }' "${tmpfile}")