blob: 54a61ef262a87f6839ec047c581d5bcdb8ef5f12 [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
Mandeep Singh Baines98bbb682011-06-02 17:53:2544pkg="${1}"
45if [ "${pkg}" = "." ]; then
46 if ! pkg=$(git config workon.pkg); then
47 die "workon.pkg not set in git config for this project"
48 fi
49fi
50
Mandeep Singh Bainese8c337d2011-03-24 21:03:4951unstable_suffix="9999"
Mandeep Singh Baines98bbb682011-06-02 17:53:2552workon_name="${pkg}-${unstable_suffix}"
Mandeep Singh Bainese8c337d2011-03-24 21:03:4953pkgfile=
54workpath=
55
Chris Masone49fd3062011-03-29 15:44:1656# Find the ebuild file, ensure the caller is workon'ing the package.
Mandeep Singh Bainese8c337d2011-03-24 21:03:4957if ! 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 Baines98bbb682011-06-02 17:53:2560 die "run 'cros_workon --board ${BOARD_STR} start ${pkg}' first!" 1>&2
Mandeep Singh Bainese8c337d2011-03-24 21:03:4961 fi
Mandeep Singh Baines98bbb682011-06-02 17:53:2562 die "error looking up package ${pkg}"
Mandeep Singh Bainese8c337d2011-03-24 21:03:4963fi
64
65if [ "${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 Baines58cef6d2011-05-11 22:42:2073 if ! (cd "${GCLIENT_ROOT}/${project_path}" && git clean -dxf); then
Mandeep Singh Bainese8c337d2011-03-24 21:03:4974 die "Could not scrub source directory"
75 fi
76 else
77 info "Not scrubbing; exiting gracefully"
78 fi
79 exit 0
80fi
81
Chris Masone49fd3062011-03-29 15:44:1682# Find the portage work directory for this package.
Mandeep Singh Bainese8c337d2011-03-24 21:03:4983workpath=$(\
84 echo "${pkgfile}" | \
85 awk -F '/' '{ print $(NF-2) "/" $(NF-1) }')-"${unstable_suffix}"
86
Chris Masone49fd3062011-03-29 15:44:1687# Determine if we're going to do tests, set up commands appropriately.
Mandeep Singh Bainese8c337d2011-03-24 21:03:4988emerge_features=
89to_do="compile"
90if [ "${FLAGS_test}" = "${FLAGS_TRUE}" ]; then
91 to_do="test"
92 emerge_features="test"
Chris Masonebde83662011-05-25 21:42:1693 rm -f "/build/${BOARD_STR}/tmp/portage/${workpath}/.tested"
Mandeep Singh Bainese8c337d2011-03-24 21:03:4994fi
Chris Masone49fd3062011-03-29 15:44:1695
Chris Masonef59007b2011-05-25 23:17:3696workdir="/build/${BOARD_STR}/tmp/portage/${workpath}/work/${workon_name}"
97if [ ! -h "${workdir}" ]; then
98 warn "Cleaning up stale workdir: ${workdir}"
99 FLAGS_reconf="${FLAGS_TRUE}" # To force symlinking in the user's src dir.
100fi
101
Mandeep Singh Bainese8c337d2011-03-24 21:03:49102if [ "${FLAGS_install}" = "${FLAGS_TRUE}" ]; then
103 SANDBOX_WRITE=~/trunk CROS_WORKON_INPLACE=1 \
Mandeep Singh Baines98bbb682011-06-02 17:53:25104 FEATURES="${emerge_features} ${FEATURES}" "${EMERGECMD}" "${pkg}"
Mandeep Singh Bainese8c337d2011-03-24 21:03:49105 exit $?
106fi
107
108clean=
109if [ "${FLAGS_reconf}" = "${FLAGS_TRUE}" ]; then
110 clean="clean"
111else
112 rm -f "/build/${BOARD_STR}/tmp/portage/${workpath}/.compiled"
113fi
114SANDBOX_WRITE=~/trunk CROS_WORKON_INPLACE=1 \
115 "${EBUILDCMD}" "${pkgfile}" ${clean} "${to_do}"