blob: 04866b3977c15163925e4e406887de094915abfa [file] [log] [blame]
Mandeep Singh Bainese8c337d2011-03-24 21:03:491#!/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 Bainese7c5ea12011-03-25 22:37:4310. /usr/lib/crosutils/common.sh || exit 1
Mandeep Singh Bainese8c337d2011-03-24 21:03:4911
12get_default_board
13
14DEFINE_string board "${DEFAULT_BOARD}" \
15 "Board for which to build the package."
16DEFINE_boolean test "${FLAGS_FALSE}" \
17 "Compile and run tests as well."
18DEFINE_boolean reconf "${FLAGS_FALSE}" \
19 "Re-run configure and prepare steps."
20DEFINE_boolean install "${FLAGS_FALSE}" \
21 "Incrementally build and install your package."
22DEFINE_boolean scrub "${FLAGS_FALSE}" \
23 "Blow away all in-tree files not managed by git."
24
25set -e
26# Parse command line.
27FLAGS "$@" || exit 1
28eval set -- "${FLAGS_ARGV}"
29
30if [ $# -lt 1 ]; then
31 echo "Usage: ${0} [OPTIONS] <package (read: ebuild) basename>"
32 exit 1
33fi
34
35if [ -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)"
42fi
43
44unstable_suffix="9999"
45workon_name="${1}-${unstable_suffix}"
46pkgfile=
47workpath=
48
49if ! pkgfile=$("${EQUERYCMD}" which "${workon_name}" 2> /dev/null); then
50 if ACCEPT_KEYWORDS="~${BOARD_KEYWORD}" "${EQUERYCMD}" which "${workon_name}" \
51 > /dev/null 2>&1; then
52 die "run 'cros_workon --board ${BOARD_STR} start ${1}' first!" 1>&2
53 fi
54 die "error looking up package $1"
55fi
56
57if [ "${FLAGS_scrub}" = "${FLAGS_TRUE}" ]; then
58 warn "--scrub will destroy ALL FILES unknown to git!"
59 read -p "Are you sure you want to do this? [y|N]" resp
60 if egrep -qi "^y(es)?$" <(echo -n "${resp}"); then
61 eval $(${EBUILDCMD} $(${EQUERYCMD} which ${workon_name}) info)
62 srcdir=$(readlink -m ${CROS_WORKON_SRCDIR})
63 trunkdir=$(readlink -m ${CHROOT_TRUNK_DIR})
64 project_path=${srcdir#${trunkdir}/}
65 if ! (cd "${GCLIENT_ROOT}/${project_path}" && git clean -xf); then
66 die "Could not scrub source directory"
67 fi
68 else
69 info "Not scrubbing; exiting gracefully"
70 fi
71 exit 0
72fi
73
74workpath=$(\
75 echo "${pkgfile}" | \
76 awk -F '/' '{ print $(NF-2) "/" $(NF-1) }')-"${unstable_suffix}"
77
78emerge_features=
79to_do="compile"
80if [ "${FLAGS_test}" = "${FLAGS_TRUE}" ]; then
81 to_do="test"
82 emerge_features="test"
83fi
84if [ "${FLAGS_install}" = "${FLAGS_TRUE}" ]; then
85 SANDBOX_WRITE=~/trunk CROS_WORKON_INPLACE=1 \
86 FEATURES="${emerge_features} ${FEATURES}" "${EMERGECMD}" "${1}"
87 exit $?
88fi
89
90clean=
91if [ "${FLAGS_reconf}" = "${FLAGS_TRUE}" ]; then
92 clean="clean"
93else
94 rm -f "/build/${BOARD_STR}/tmp/portage/${workpath}/.compiled"
95fi
96SANDBOX_WRITE=~/trunk CROS_WORKON_INPLACE=1 \
97 "${EBUILDCMD}" "${pkgfile}" ${clean} "${to_do}"