Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1111)

Side by Side Diff: src/scripts/enter_chroot.sh

Issue 486002: Add --official_build option, and skip checking HEAD against origin/HEAD for official builds. (Closed)
Patch Set: Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # Script to enter the chroot environment 7 # Script to enter the chroot environment
8 8
9 # Load common constants. This should be the first executable line. 9 # Load common constants. This should be the first executable line.
10 # The path to common.sh should be relative to your script's location. 10 # The path to common.sh should be relative to your script's location.
11 . "$(dirname "$0")/common.sh" 11 . "$(dirname "$0")/common.sh"
12 12
13 # Script must be run outside the chroot and as a regular user. 13 # Script must be run outside the chroot and as a regular user.
14 assert_outside_chroot 14 assert_outside_chroot
15 assert_not_root_user 15 assert_not_root_user
16 16
17 # Define command line flags 17 # Define command line flags
18 # See http://code.google.com/p/shflags/wiki/Documentation10x 18 # See http://code.google.com/p/shflags/wiki/Documentation10x
19 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ 19 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \
20 "The destination dir for the chroot environment." "d" 20 "The destination dir for the chroot environment." "d"
21 DEFINE_string trunk "$GCLIENT_ROOT" \ 21 DEFINE_string trunk "$GCLIENT_ROOT" \
22 "The source trunk to bind mount within the chroot." "s" 22 "The source trunk to bind mount within the chroot." "s"
23 DEFINE_string build_number "" \ 23 DEFINE_string build_number "" \
24 "The build-bot build number (when called by buildbot only)." "b" 24 "The build-bot build number (when called by buildbot only)." "b"
25 25
26 DEFINE_boolean official_build $FLAGS_FALSE "Set CHROMEOS_OFFICIAL=1 for release builds."
26 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts." 27 DEFINE_boolean mount $FLAGS_FALSE "Only set up mounts."
27 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts." 28 DEFINE_boolean unmount $FLAGS_FALSE "Only tear down mounts."
28 29
29 # More useful help 30 # More useful help
30 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"] 31 FLAGS_HELP="USAGE: $0 [flags] [VAR=value] [-- \"command\"]
31 32
32 One or more VAR=value pairs can be specified to export variables into 33 One or more VAR=value pairs can be specified to export variables into
33 the chroot environment. For example: 34 the chroot environment. For example:
34 35
35 $0 FOO=bar BAZ=bel 36 $0 FOO=bar BAZ=bel
36 37
37 If [-- \"command\"] is present, runs the command inside the chroot, 38 If [-- \"command\"] is present, runs the command inside the chroot,
38 after changing directory to /$USER/trunk/src/scripts. Note that the 39 after changing directory to /$USER/trunk/src/scripts. Note that the
39 command should be enclosed in quotes to prevent interpretation by the 40 command should be enclosed in quotes to prevent interpretation by the
40 shell before getting into the chroot. For example: 41 shell before getting into the chroot. For example:
41 42
42 $0 -- \"./build_platform_packages.sh\" 43 $0 -- \"./build_platform_packages.sh\"
43 44
44 Otherwise, provides an interactive shell. 45 Otherwise, provides an interactive shell.
45 " 46 "
46 47
47 # Parse command line flags 48 # Parse command line flags
48 FLAGS "$@" || exit 1 49 FLAGS "$@" || exit 1
49 eval set -- "${FLAGS_ARGV}" 50 eval set -- "${FLAGS_ARGV}"
50 51
52 if [ $FLAGS_official_build -eq $FLAGS_TRUE ]
53 then
54 CHROMEOS_OFFICIAL=1
55 fi
56
51 # Only now can we die on error. shflags functions leak non-zero error codes, 57 # Only now can we die on error. shflags functions leak non-zero error codes,
52 # so will die prematurely if 'set -e' is specified before now. 58 # so will die prematurely if 'set -e' is specified before now.
53 # TODO: replace shflags with something less error-prone, or contribute a fix. 59 # TODO: replace shflags with something less error-prone, or contribute a fix.
54 set -e 60 set -e
55 61
56 function setup_env { 62 function setup_env {
57 echo "Mounting chroot environment." 63 echo "Mounting chroot environment."
58 64
59 # Mount only if not already mounted 65 # Mount only if not already mounted
60 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")" 66 MOUNTED_PATH="$(readlink -f "$FLAGS_chroot/proc")"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 110
105 # Get the git revision to pass into the chroot. 111 # Get the git revision to pass into the chroot.
106 # 112 #
107 # This must be determined outside the chroot because (1) there is no 113 # This must be determined outside the chroot because (1) there is no
108 # git inside the chroot, and (2) if there were it would likely be 114 # git inside the chroot, and (2) if there were it would likely be
109 # the wrong version, which would mess up the .git directories. 115 # the wrong version, which would mess up the .git directories.
110 # 116 #
111 # Note that this fixes $CHROMEOS_REVISION at the time the chroot is 117 # Note that this fixes $CHROMEOS_REVISION at the time the chroot is
112 # entered. That's ok for the main use case of automated builds, 118 # entered. That's ok for the main use case of automated builds,
113 # which pass each command line into a separate call to enter_chroot 119 # which pass each command line into a separate call to enter_chroot
114 # so always have up-to-date info. For developer builds, there isn't 120 # so always have up-to-date info. For developer builds, there may not
115 # really a single revision anyway, since the developer may have 121 # be a single revision, since the developer may have
116 # hand-sync'd some subdirs and edited files in others. 122 # hand-sync'd some subdirs and edited files in others.
123 # In that case, check against origin/HEAD and mark** revision.
117 # Use git:8 chars of sha1 124 # Use git:8 chars of sha1
118 REVISION=$(git rev-parse HEAD) 125 REVISION=$(git rev-parse HEAD)
119 ORIGIN_REVISION=$(git rev-parse origin/HEAD) 126 ORIGIN_REVISION=$(git rev-parse origin/HEAD)
120 if [ "$REVISION" != "$ORIGIN_REVISION" ] 127 # Do not check for clean revision on official builds. They are coming directly
128 # from a branch rev and cannot compare to origin/HEAD.
129 if [ $FLAGS_official_build != $FLAGS_TRUE ] && \
130 [ "$REVISION" != "$ORIGIN_REVISION" ]
121 then 131 then
122 # Mark dirty tree with "**" 132 # Mark dirty tree with "**"
123 REVISION="${REVISION:0:8}**" 133 REVISION="${REVISION:0:8}**"
124 else 134 else
125 REVISION="${REVISION:0:8}" 135 REVISION="${REVISION:0:8}"
126 fi 136 fi
127 REVISION="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number" 137 CHROOT_PASSTHRU="CHROMEOS_REVISION=$REVISION BUILDBOT_BUILD=$FLAGS_build_number CHROMEOS_OFFICIAL=$CHROMEOS_OFFICIAL"
128 138
129 # Run command or interactive shell. Also include the non-chrooted path to 139 # Run command or interactive shell. Also include the non-chrooted path to
130 # the source trunk for scripts that may need to print it (e.g. 140 # the source trunk for scripts that may need to print it (e.g.
131 # build_image.sh). 141 # build_image.sh).
132 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $REVISION \ 142 sudo chroot "$FLAGS_chroot" sudo -i -u $USER $CHROOT_PASSTHRU \
133 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" "$@" 143 EXTERNAL_TRUNK_PATH="${FLAGS_trunk}" "$@"
134 144
135 # Remove trap and explicitly unmount 145 # Remove trap and explicitly unmount
136 trap - EXIT 146 trap - EXIT
137 teardown_env 147 teardown_env
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698