Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # Common constants for build scripts | 5 # Common constants for build scripts |
| 6 # This must evaluate properly for both /bin/bash and /bin/sh | 6 # This must evaluate properly for both /bin/bash and /bin/sh |
| 7 | 7 |
| 8 # All scripts should die on error unless commands are specifically excepted | 8 # All scripts should die on error unless commands are specifically excepted |
| 9 # by prefixing with '!' or surrounded by 'set +e' / 'set -e'. | 9 # by prefixing with '!' or surrounded by 'set +e' / 'set -e'. |
| 10 # TODO: Re-enable this once shflags is less prone to dying. | 10 # TODO: Re-enable this once shflags is less prone to dying. |
| 11 #set -e | 11 #set -e |
| 12 | 12 |
| 13 # The number of jobs to pass to tools that can run in parallel (such as make | 13 # The number of jobs to pass to tools that can run in parallel (such as make |
| 14 # and dpkg-buildpackage | 14 # and dpkg-buildpackage |
| 15 NUM_JOBS=`grep -c "^processor" /proc/cpuinfo` | 15 NUM_JOBS=`grep -c "^processor" /proc/cpuinfo` |
| 16 | 16 |
| 17 # Store location of the calling script. | 17 # Store location of the calling script. |
| 18 TOP_SCRIPT_DIR="${TOP_SCRIPT_DIR:-$(dirname $0)}" | 18 TOP_SCRIPT_DIR="${TOP_SCRIPT_DIR:-$(dirname $0)}" |
| 19 | 19 |
| 20 # Detect whether we're inside a chroot or not | |
| 21 if [ -e /etc/debian_chroot ] | |
| 22 then | |
| 23 INSIDE_CHROOT=1 | |
| 24 else | |
| 25 INSIDE_CHROOT=0 | |
| 26 fi | |
| 27 | |
| 28 # Construct a list of possible locations for the source tree. This list is | |
| 29 # based on various environment variables and globals that may have been set | |
| 30 # by the calling script. | |
| 31 function get_gclient_root_list() { | |
| 32 if [ $INSIDE_CHROOT -eq 1 ]; then echo "/home/${USER}/trunk" | |
|
davidjames
2011/01/26 23:41:33
Since this isn't a one-line if statement, better t
robotboy
2011/01/26 23:59:34
Done.
| |
| 33 if [ ! -z "${SUDO_USER}" ]; then echo "/home/${SUDO_USER}/trunk"; fi | |
|
davidjames
2011/01/26 23:41:33
Any reason why you didn't use -n here (and elsewhe
robotboy
2011/01/26 23:59:34
Done.
| |
| 34 fi | |
| 35 | |
| 36 if [ ! -z "${COMMON_SH}" ]; then echo "$(dirname "$COMMON_SH")/../.."; fi | |
| 37 if [ ! -z "${BASH_SOURCE}" ]; then echo "$(dirname "$BASH_SOURCE")/../.."; fi | |
| 38 } | |
| 39 | |
| 40 # Based on the list of possible source locations we set GCLIENT_ROOT if it is | |
| 41 # not already defined by looking for a src directory in each seach path | |
| 42 # location. If we do not find a valid looking root we error out. | |
| 43 function get_gclient_root() { | |
| 44 if [ ! -z "${GCLIENT_ROOT}" ]; then | |
| 45 return | |
| 46 fi | |
| 47 | |
| 48 for path in $(get_gclient_root_list); do | |
| 49 if [ -d "${path}/src" ]; then | |
| 50 GCLIENT_ROOT=${path} | |
| 51 break | |
| 52 fi | |
| 53 done | |
| 54 | |
| 55 if [ -z "${GCLIENT_ROOT}" ]; then | |
| 56 # Using dash or sh, we don't know where we are. $0 refers to the calling | |
| 57 # script, not ourselves, so that doesn't help us. | |
| 58 echo "Unable to determine location for common.sh. If you are sourcing" | |
| 59 echo "common.sh from a script run via dash or sh, you must do it in the" | |
| 60 echo "following way:" | |
| 61 echo ' COMMON_SH="$(dirname "$0")/../../scripts/common.sh"' | |
| 62 echo ' . "$COMMON_SH"' | |
| 63 echo "where the first line is the relative path from your script to" | |
| 64 echo "common.sh." | |
| 65 exit 1 | |
| 66 fi | |
| 67 } | |
| 68 | |
| 20 # Find root of source tree | 69 # Find root of source tree |
| 21 if [ "x$GCLIENT_ROOT" != "x" ] | 70 get_gclient_root |
| 22 then | |
| 23 # GCLIENT_ROOT already set, so we're done | |
| 24 true | |
| 25 elif [ "x$COMMON_SH" != "x" ] | |
| 26 then | |
| 27 # COMMON_SH set, so assume that's us | |
| 28 GCLIENT_ROOT="$(dirname "$COMMON_SH")/../.." | |
| 29 elif [ "x$BASH_SOURCE" != "x" ] | |
| 30 then | |
| 31 # Using bash, so we can find ourselves | |
| 32 GCLIENT_ROOT="$(dirname "$BASH_SOURCE")/../.." | |
| 33 else | |
| 34 # Using dash or sh, we don't know where we are. $0 refers to the calling | |
| 35 # script, not ourselves, so that doesn't help us. | |
| 36 echo "Unable to determine location for common.sh. If you are sourcing" | |
| 37 echo "common.sh from a script run via dash or sh, you must do it in the" | |
| 38 echo "following way:" | |
| 39 echo ' COMMON_SH="$(dirname "$0")/../../scripts/common.sh"' | |
| 40 echo ' . "$COMMON_SH"' | |
| 41 echo "where the first line is the relative path from your script to" | |
| 42 echo "common.sh." | |
| 43 exit 1 | |
| 44 fi | |
| 45 | 71 |
| 46 # Canonicalize the directories for the root dir and the calling script. | 72 # Canonicalize the directories for the root dir and the calling script. |
| 47 # readlink is part of coreutils and should be present even in a bare chroot. | 73 # readlink is part of coreutils and should be present even in a bare chroot. |
| 48 # This is better than just using | 74 # This is better than just using |
| 49 # FOO = "$(cd $FOO ; pwd)" | 75 # FOO = "$(cd $FOO ; pwd)" |
| 50 # since that leaves symbolic links intact. | 76 # since that leaves symbolic links intact. |
| 51 # Note that 'realpath' is equivalent to 'readlink -f'. | 77 # Note that 'realpath' is equivalent to 'readlink -f'. |
| 52 TOP_SCRIPT_DIR=`readlink -f $TOP_SCRIPT_DIR` | 78 TOP_SCRIPT_DIR=`readlink -f $TOP_SCRIPT_DIR` |
| 53 GCLIENT_ROOT=`readlink -f $GCLIENT_ROOT` | 79 GCLIENT_ROOT=`readlink -f $GCLIENT_ROOT` |
| 54 | 80 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 fi | 135 fi |
| 110 # Strip CR | 136 # Strip CR |
| 111 ALL_BOARDS=$(echo $ALL_BOARDS) | 137 ALL_BOARDS=$(echo $ALL_BOARDS) |
| 112 # Set a default BOARD | 138 # Set a default BOARD |
| 113 #DEFAULT_BOARD=x86-generic # or... | 139 #DEFAULT_BOARD=x86-generic # or... |
| 114 DEFAULT_BOARD=$(echo $ALL_BOARDS | awk '{print $NF}') | 140 DEFAULT_BOARD=$(echo $ALL_BOARDS | awk '{print $NF}') |
| 115 | 141 |
| 116 # Enable --fast by default. | 142 # Enable --fast by default. |
| 117 DEFAULT_FAST="${FLAGS_TRUE}" | 143 DEFAULT_FAST="${FLAGS_TRUE}" |
| 118 | 144 |
| 119 # Detect whether we're inside a chroot or not | |
| 120 if [ -e /etc/debian_chroot ] | |
| 121 then | |
| 122 INSIDE_CHROOT=1 | |
| 123 else | |
| 124 INSIDE_CHROOT=0 | |
| 125 fi | |
| 126 | |
| 127 # Directory locations inside the dev chroot | 145 # Directory locations inside the dev chroot |
| 128 CHROOT_TRUNK_DIR="/home/$USER/trunk" | 146 CHROOT_TRUNK_DIR="/home/$USER/trunk" |
| 129 | 147 |
| 130 # Install make for portage ebuilds. Used by build_image and gmergefs. | 148 # Install make for portage ebuilds. Used by build_image and gmergefs. |
| 131 # TODO: Is /usr/local/autotest-chrome still used by anyone? | 149 # TODO: Is /usr/local/autotest-chrome still used by anyone? |
| 132 DEFAULT_INSTALL_MASK=" | 150 DEFAULT_INSTALL_MASK=" |
| 133 *.a | 151 *.a |
| 134 *.la | 152 *.la |
| 135 /etc/init.d | 153 /etc/init.d |
| 136 /etc/runlevels | 154 /etc/runlevels |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 | 593 |
| 576 BOARD=$(echo "$flags_board" | cut -d '_' -f 1) | 594 BOARD=$(echo "$flags_board" | cut -d '_' -f 1) |
| 577 VARIANT=${flags_variant:-$(echo "$flags_board" | cut -s -d '_' -f 2)} | 595 VARIANT=${flags_variant:-$(echo "$flags_board" | cut -s -d '_' -f 2)} |
| 578 | 596 |
| 579 if [ -n "$VARIANT" ]; then | 597 if [ -n "$VARIANT" ]; then |
| 580 BOARD_VARIANT="${BOARD}_${VARIANT}" | 598 BOARD_VARIANT="${BOARD}_${VARIANT}" |
| 581 else | 599 else |
| 582 BOARD_VARIANT="${BOARD}" | 600 BOARD_VARIANT="${BOARD}" |
| 583 fi | 601 fi |
| 584 } | 602 } |
| OLD | NEW |