Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 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 | # Simple wrapper script to build a cros_workon package incrementally. |
| 8 | # You must already be cros_workon'ing the package in question. |
| 9 | |
Mandeep Singh Baines | e7c5ea1 | 2011-03-25 22:37:43 | [diff] [blame] | 10 | . /usr/lib/crosutils/common.sh || exit 1 |
Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 11 | |
| 12 | get_default_board |
| 13 | |
| 14 | DEFINE_string board "${DEFAULT_BOARD}" \ |
| 15 | "Board for which to build the package." |
| 16 | DEFINE_boolean test "${FLAGS_FALSE}" \ |
| 17 | "Compile and run tests as well." |
| 18 | DEFINE_boolean reconf "${FLAGS_FALSE}" \ |
| 19 | "Re-run configure and prepare steps." |
| 20 | DEFINE_boolean install "${FLAGS_FALSE}" \ |
| 21 | "Incrementally build and install your package." |
| 22 | DEFINE_boolean scrub "${FLAGS_FALSE}" \ |
| 23 | "Blow away all in-tree files not managed by git." |
| 24 | |
| 25 | set -e |
| 26 | # Parse command line. |
| 27 | FLAGS "$@" || exit 1 |
| 28 | eval set -- "${FLAGS_ARGV}" |
| 29 | |
| 30 | if [ $# -lt 1 ]; then |
| 31 | echo "Usage: ${0} [OPTIONS] <package (read: ebuild) basename>" |
| 32 | exit 1 |
| 33 | fi |
| 34 | |
| 35 | if [ -n "${FLAGS_board}" ]; then |
| 36 | BOARD_DIR=/build/"${FLAGS_board}" |
| 37 | EBUILDCMD=ebuild-"${FLAGS_board}" |
| 38 | EMERGECMD=emerge-"${FLAGS_board}" |
| 39 | EQUERYCMD=equery-"${FLAGS_board}" |
| 40 | BOARD_STR="${FLAGS_board}" |
| 41 | BOARD_KEYWORD="$(portageq-${FLAGS_board} envvar ARCH)" |
| 42 | fi |
| 43 | |
Mandeep Singh Baines | 98bbb68 | 2011-06-02 17:53:25 | [diff] [blame] | 44 | pkg="${1}" |
| 45 | if [ "${pkg}" = "." ]; then |
| 46 | if ! pkg=$(git config workon.pkg); then |
| 47 | die "workon.pkg not set in git config for this project" |
| 48 | fi |
| 49 | fi |
| 50 | |
Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 51 | unstable_suffix="9999" |
Mandeep Singh Baines | 98bbb68 | 2011-06-02 17:53:25 | [diff] [blame] | 52 | workon_name="${pkg}-${unstable_suffix}" |
Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 53 | pkgfile= |
| 54 | workpath= |
| 55 | |
Chris Masone | 49fd306 | 2011-03-29 15:44:16 | [diff] [blame] | 56 | # Find the ebuild file, ensure the caller is workon'ing the package. |
Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 57 | if ! pkgfile=$("${EQUERYCMD}" which "${workon_name}" 2> /dev/null); then |
| 58 | if ACCEPT_KEYWORDS="~${BOARD_KEYWORD}" "${EQUERYCMD}" which "${workon_name}" \ |
| 59 | > /dev/null 2>&1; then |
Mandeep Singh Baines | 98bbb68 | 2011-06-02 17:53:25 | [diff] [blame] | 60 | die "run 'cros_workon --board ${BOARD_STR} start ${pkg}' first!" 1>&2 |
Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 61 | fi |
Mandeep Singh Baines | 98bbb68 | 2011-06-02 17:53:25 | [diff] [blame] | 62 | die "error looking up package ${pkg}" |
Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 63 | fi |
| 64 | |
| 65 | if [ "${FLAGS_scrub}" = "${FLAGS_TRUE}" ]; then |
| 66 | warn "--scrub will destroy ALL FILES unknown to git!" |
| 67 | read -p "Are you sure you want to do this? [y|N]" resp |
| 68 | if egrep -qi "^y(es)?$" <(echo -n "${resp}"); then |
| 69 | eval $(${EBUILDCMD} $(${EQUERYCMD} which ${workon_name}) info) |
| 70 | srcdir=$(readlink -m ${CROS_WORKON_SRCDIR}) |
| 71 | trunkdir=$(readlink -m ${CHROOT_TRUNK_DIR}) |
| 72 | project_path=${srcdir#${trunkdir}/} |
Mandeep Singh Baines | 58cef6d | 2011-05-11 22:42:20 | [diff] [blame] | 73 | if ! (cd "${GCLIENT_ROOT}/${project_path}" && git clean -dxf); then |
Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 74 | die "Could not scrub source directory" |
| 75 | fi |
| 76 | else |
| 77 | info "Not scrubbing; exiting gracefully" |
| 78 | fi |
| 79 | exit 0 |
| 80 | fi |
| 81 | |
Chris Masone | 49fd306 | 2011-03-29 15:44:16 | [diff] [blame] | 82 | # Find the portage work directory for this package. |
Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 83 | workpath=$(\ |
| 84 | echo "${pkgfile}" | \ |
| 85 | awk -F '/' '{ print $(NF-2) "/" $(NF-1) }')-"${unstable_suffix}" |
| 86 | |
Chris Masone | 49fd306 | 2011-03-29 15:44:16 | [diff] [blame] | 87 | # Determine if we're going to do tests, set up commands appropriately. |
Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 88 | emerge_features= |
| 89 | to_do="compile" |
| 90 | if [ "${FLAGS_test}" = "${FLAGS_TRUE}" ]; then |
| 91 | to_do="test" |
| 92 | emerge_features="test" |
Chris Masone | bde8366 | 2011-05-25 21:42:16 | [diff] [blame] | 93 | rm -f "/build/${BOARD_STR}/tmp/portage/${workpath}/.tested" |
Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 94 | fi |
Chris Masone | 49fd306 | 2011-03-29 15:44:16 | [diff] [blame] | 95 | |
Chris Masone | f59007b | 2011-05-25 23:17:36 | [diff] [blame] | 96 | workdir="/build/${BOARD_STR}/tmp/portage/${workpath}/work/${workon_name}" |
| 97 | if [ ! -h "${workdir}" ]; then |
| 98 | warn "Cleaning up stale workdir: ${workdir}" |
| 99 | FLAGS_reconf="${FLAGS_TRUE}" # To force symlinking in the user's src dir. |
| 100 | fi |
| 101 | |
Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 102 | if [ "${FLAGS_install}" = "${FLAGS_TRUE}" ]; then |
| 103 | SANDBOX_WRITE=~/trunk CROS_WORKON_INPLACE=1 \ |
Mandeep Singh Baines | 98bbb68 | 2011-06-02 17:53:25 | [diff] [blame] | 104 | FEATURES="${emerge_features} ${FEATURES}" "${EMERGECMD}" "${pkg}" |
Mandeep Singh Baines | e8c337d | 2011-03-24 21:03:49 | [diff] [blame] | 105 | exit $? |
| 106 | fi |
| 107 | |
| 108 | clean= |
| 109 | if [ "${FLAGS_reconf}" = "${FLAGS_TRUE}" ]; then |
| 110 | clean="clean" |
| 111 | else |
| 112 | rm -f "/build/${BOARD_STR}/tmp/portage/${workpath}/.compiled" |
| 113 | fi |
| 114 | SANDBOX_WRITE=~/trunk CROS_WORKON_INPLACE=1 \ |
| 115 | "${EBUILDCMD}" "${pkgfile}" ${clean} "${to_do}" |