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 |
| 33 echo "/home/${USER}/trunk" |
| 34 |
| 35 if [ -n "${SUDO_USER}" ]; then echo "/home/${SUDO_USER}/trunk"; fi |
| 36 fi |
| 37 |
| 38 if [ -n "${COMMON_SH}" ]; then echo "$(dirname "$COMMON_SH")/../.."; fi |
| 39 if [ -n "${BASH_SOURCE}" ]; then echo "$(dirname "$BASH_SOURCE")/../.."; fi |
| 40 } |
| 41 |
| 42 # Based on the list of possible source locations we set GCLIENT_ROOT if it is |
| 43 # not already defined by looking for a src directory in each seach path |
| 44 # location. If we do not find a valid looking root we error out. |
| 45 function get_gclient_root() { |
| 46 if [ -n "${GCLIENT_ROOT}" ]; then |
| 47 return |
| 48 fi |
| 49 |
| 50 for path in $(get_gclient_root_list); do |
| 51 if [ -d "${path}/src" ]; then |
| 52 GCLIENT_ROOT=${path} |
| 53 break |
| 54 fi |
| 55 done |
| 56 |
| 57 if [ -z "${GCLIENT_ROOT}" ]; then |
| 58 # Using dash or sh, we don't know where we are. $0 refers to the calling |
| 59 # script, not ourselves, so that doesn't help us. |
| 60 echo "Unable to determine location for common.sh. If you are sourcing" |
| 61 echo "common.sh from a script run via dash or sh, you must do it in the" |
| 62 echo "following way:" |
| 63 echo ' COMMON_SH="$(dirname "$0")/../../scripts/common.sh"' |
| 64 echo ' . "$COMMON_SH"' |
| 65 echo "where the first line is the relative path from your script to" |
| 66 echo "common.sh." |
| 67 exit 1 |
| 68 fi |
| 69 } |
| 70 |
20 # Find root of source tree | 71 # Find root of source tree |
21 if [ "x$GCLIENT_ROOT" != "x" ] | 72 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 | 73 |
46 # Canonicalize the directories for the root dir and the calling script. | 74 # 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. | 75 # readlink is part of coreutils and should be present even in a bare chroot. |
48 # This is better than just using | 76 # This is better than just using |
49 # FOO = "$(cd $FOO ; pwd)" | 77 # FOO = "$(cd $FOO ; pwd)" |
50 # since that leaves symbolic links intact. | 78 # since that leaves symbolic links intact. |
51 # Note that 'realpath' is equivalent to 'readlink -f'. | 79 # Note that 'realpath' is equivalent to 'readlink -f'. |
52 TOP_SCRIPT_DIR=`readlink -f $TOP_SCRIPT_DIR` | 80 TOP_SCRIPT_DIR=`readlink -f $TOP_SCRIPT_DIR` |
53 GCLIENT_ROOT=`readlink -f $GCLIENT_ROOT` | 81 GCLIENT_ROOT=`readlink -f $GCLIENT_ROOT` |
54 | 82 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 fi | 137 fi |
110 # Strip CR | 138 # Strip CR |
111 ALL_BOARDS=$(echo $ALL_BOARDS) | 139 ALL_BOARDS=$(echo $ALL_BOARDS) |
112 # Set a default BOARD | 140 # Set a default BOARD |
113 #DEFAULT_BOARD=x86-generic # or... | 141 #DEFAULT_BOARD=x86-generic # or... |
114 DEFAULT_BOARD=$(echo $ALL_BOARDS | awk '{print $NF}') | 142 DEFAULT_BOARD=$(echo $ALL_BOARDS | awk '{print $NF}') |
115 | 143 |
116 # Enable --fast by default. | 144 # Enable --fast by default. |
117 DEFAULT_FAST="${FLAGS_TRUE}" | 145 DEFAULT_FAST="${FLAGS_TRUE}" |
118 | 146 |
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 | 147 # Directory locations inside the dev chroot |
128 CHROOT_TRUNK_DIR="/home/$USER/trunk" | 148 CHROOT_TRUNK_DIR="/home/$USER/trunk" |
129 | 149 |
130 # Install make for portage ebuilds. Used by build_image and gmergefs. | 150 # Install make for portage ebuilds. Used by build_image and gmergefs. |
131 # TODO: Is /usr/local/autotest-chrome still used by anyone? | 151 # TODO: Is /usr/local/autotest-chrome still used by anyone? |
132 DEFAULT_INSTALL_MASK=" | 152 DEFAULT_INSTALL_MASK=" |
133 *.a | 153 *.a |
134 *.la | 154 *.la |
135 /etc/init.d | 155 /etc/init.d |
136 /etc/runlevels | 156 /etc/runlevels |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 | 595 |
576 BOARD=$(echo "$flags_board" | cut -d '_' -f 1) | 596 BOARD=$(echo "$flags_board" | cut -d '_' -f 1) |
577 VARIANT=${flags_variant:-$(echo "$flags_board" | cut -s -d '_' -f 2)} | 597 VARIANT=${flags_variant:-$(echo "$flags_board" | cut -s -d '_' -f 2)} |
578 | 598 |
579 if [ -n "$VARIANT" ]; then | 599 if [ -n "$VARIANT" ]; then |
580 BOARD_VARIANT="${BOARD}_${VARIANT}" | 600 BOARD_VARIANT="${BOARD}_${VARIANT}" |
581 else | 601 else |
582 BOARD_VARIANT="${BOARD}" | 602 BOARD_VARIANT="${BOARD}" |
583 fi | 603 fi |
584 } | 604 } |
OLD | NEW |