shenhan | 8e8b0c2 | 2013-02-19 22:34:16 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 2 | # |
Rahul Chaudhry | 8ac4ec0 | 2014-11-01 09:31:15 -0700 | [diff] [blame] | 3 | # Copyright 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. |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 6 | |
| 7 | """Script to build the ChromeOS toolchain. |
| 8 | |
| 9 | This script sets up the toolchain if you give it the gcctools directory. |
| 10 | """ |
| 11 | |
| 12 | __author__ = "asharif@google.com (Ahmad Sharif)" |
| 13 | |
asharif | 80c6e55 | 2013-02-15 04:35:40 +0000 | [diff] [blame] | 14 | import getpass |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 15 | import optparse |
asharif | 1762130 | 2013-02-15 04:46:35 +0000 | [diff] [blame] | 16 | import os |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 17 | import sys |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 18 | import tempfile |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 19 | |
asharif | 252df0f | 2013-02-15 04:46:28 +0000 | [diff] [blame] | 20 | import tc_enter_chroot |
raymes | 01959ae | 2013-02-15 04:50:07 +0000 | [diff] [blame] | 21 | from utils import command_executer |
shenhan | ad80343 | 2013-02-16 03:14:51 +0000 | [diff] [blame] | 22 | from utils import constants |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 23 | from utils import misc |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 24 | |
asharif | 5a9bb46 | 2013-02-15 04:50:57 +0000 | [diff] [blame] | 25 | |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 26 | class ToolchainPart(object): |
| 27 | def __init__(self, name, source_path, chromeos_root, board, incremental, |
llozano | f2726d2 | 2013-03-09 01:29:37 +0000 | [diff] [blame] | 28 | build_env, gcc_enable_ccache=False): |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 29 | self._name = name |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 30 | self._source_path = misc.CanonicalizePath(source_path) |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 31 | self._chromeos_root = chromeos_root |
| 32 | self._board = board |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 33 | self._ctarget = misc.GetCtargetFromBoard(self._board, |
asharif | 77bd80d | 2013-02-15 22:49:32 +0000 | [diff] [blame] | 34 | self._chromeos_root) |
Rahul Chaudhry | 215c12f | 2014-11-04 15:18:47 -0800 | [diff] [blame] | 35 | self._gcc_libs_dest = misc.GetGccLibsDestForBoard(self._board, |
| 36 | self._chromeos_root) |
carrot | e6f773c | 2013-02-19 22:34:44 +0000 | [diff] [blame] | 37 | self.tag = "%s-%s" % (name, self._ctarget) |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 38 | self._ce = command_executer.GetCommandExecuter() |
| 39 | self._mask_file = os.path.join( |
| 40 | self._chromeos_root, |
| 41 | "chroot", |
| 42 | "etc/portage/package.mask/cross-%s" % self._ctarget) |
| 43 | self._new_mask_file = None |
| 44 | |
Han Shen | e4b6f22 | 2013-11-22 10:02:38 -0800 | [diff] [blame] | 45 | self._chroot_source_path = os.path.join(constants.MOUNTED_TOOLCHAIN_ROOT, |
llozano | 85b3715 | 2013-02-16 03:14:57 +0000 | [diff] [blame] | 46 | self._name).lstrip("/") |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 47 | self._incremental = incremental |
| 48 | self._build_env = build_env |
llozano | f2726d2 | 2013-03-09 01:29:37 +0000 | [diff] [blame] | 49 | self._gcc_enable_ccache = gcc_enable_ccache |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 50 | |
| 51 | def RunSetupBoardIfNecessary(self): |
| 52 | cross_symlink = os.path.join( |
| 53 | self._chromeos_root, |
| 54 | "chroot", |
carrot | ccae627 | 2013-02-19 22:34:51 +0000 | [diff] [blame] | 55 | "usr/local/bin/emerge-%s" % self._board) |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 56 | if not os.path.exists(cross_symlink): |
Rahul Chaudhry | 8ac4ec0 | 2014-11-01 09:31:15 -0700 | [diff] [blame] | 57 | command = ("%s/setup_board --board=%s" % |
| 58 | (misc.CHROMEOS_SCRIPTS_DIR, self._board)) |
asharif | ca3c6c1 | 2013-02-15 23:17:54 +0000 | [diff] [blame] | 59 | self._ce.ChrootRunCommand(self._chromeos_root, command) |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 60 | |
| 61 | def Build(self): |
shenhan | becf624 | 2013-02-19 20:43:32 +0000 | [diff] [blame] | 62 | rv = 1 |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 63 | try: |
asharif | 7dd6d86 | 2013-02-15 23:17:46 +0000 | [diff] [blame] | 64 | self.UninstallTool() |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 65 | self.MoveMaskFile() |
cmtice | 80d257f | 2013-02-15 23:44:51 +0000 | [diff] [blame] | 66 | self.MountSources(False) |
asharif | 9e3cf6e | 2013-02-16 03:13:38 +0000 | [diff] [blame] | 67 | self.RemoveCompiledFile() |
shenhan | becf624 | 2013-02-19 20:43:32 +0000 | [diff] [blame] | 68 | rv = self.BuildTool() |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 69 | finally: |
| 70 | self.UnMoveMaskFile() |
llozano | 9b84cb6 | 2013-03-11 21:08:31 +0000 | [diff] [blame] | 71 | return rv |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 72 | |
| 73 | def RemoveCompiledFile(self): |
| 74 | compiled_file = os.path.join(self._chromeos_root, |
| 75 | "chroot", |
| 76 | "var/tmp/portage/cross-%s" % self._ctarget, |
| 77 | "%s-9999" % self._name, |
| 78 | ".compiled") |
asharif | 9e3cf6e | 2013-02-16 03:13:38 +0000 | [diff] [blame] | 79 | command = "rm -f %s" % compiled_file |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 80 | self._ce.RunCommand(command) |
| 81 | |
cmtice | 80d257f | 2013-02-15 23:44:51 +0000 | [diff] [blame] | 82 | def MountSources(self, unmount_source): |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 83 | mount_points = [] |
| 84 | mounted_source_path = os.path.join(self._chromeos_root, |
| 85 | "chroot", |
| 86 | self._chroot_source_path) |
| 87 | src_mp = tc_enter_chroot.MountPoint( |
| 88 | self._source_path, |
| 89 | mounted_source_path, |
| 90 | getpass.getuser(), |
| 91 | "ro") |
| 92 | mount_points.append(src_mp) |
| 93 | |
| 94 | build_suffix = "build-%s" % self._ctarget |
| 95 | build_dir = "%s-%s" % (self._source_path, build_suffix) |
| 96 | |
| 97 | if not self._incremental and os.path.exists(build_dir): |
| 98 | command = "rm -rf %s/*" % build_dir |
| 99 | self._ce.RunCommand(command) |
| 100 | |
| 101 | # Create a -build directory for the objects. |
| 102 | command = "mkdir -p %s" % build_dir |
| 103 | self._ce.RunCommand(command) |
| 104 | |
| 105 | mounted_build_dir = os.path.join( |
| 106 | self._chromeos_root, "chroot", "%s-%s" % |
| 107 | (self._chroot_source_path, build_suffix)) |
| 108 | build_mp = tc_enter_chroot.MountPoint( |
| 109 | build_dir, |
| 110 | mounted_build_dir, |
| 111 | getpass.getuser()) |
| 112 | mount_points.append(build_mp) |
| 113 | |
cmtice | 80d257f | 2013-02-15 23:44:51 +0000 | [diff] [blame] | 114 | if unmount_source: |
| 115 | unmount_statuses = [mp.UnMount() == 0 for mp in mount_points] |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 116 | assert all(unmount_statuses), "Could not unmount all mount points!" |
cmtice | 80d257f | 2013-02-15 23:44:51 +0000 | [diff] [blame] | 117 | else: |
| 118 | mount_statuses = [mp.DoMount() == 0 for mp in mount_points] |
| 119 | |
| 120 | if not all(mount_statuses): |
| 121 | mounted = [mp for mp, status in zip(mount_points, mount_statuses) if status] |
| 122 | unmount_statuses = [mp.UnMount() == 0 for mp in mounted] |
| 123 | assert all(unmount_statuses), "Could not unmount all mount points!" |
| 124 | |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 125 | |
asharif | 7dd6d86 | 2013-02-15 23:17:46 +0000 | [diff] [blame] | 126 | def UninstallTool(self): |
| 127 | command = "sudo CLEAN_DELAY=0 emerge -C cross-%s/%s" % (self._ctarget, self._name) |
asharif | ca3c6c1 | 2013-02-15 23:17:54 +0000 | [diff] [blame] | 128 | self._ce.ChrootRunCommand(self._chromeos_root, command) |
asharif | 7dd6d86 | 2013-02-15 23:17:46 +0000 | [diff] [blame] | 129 | |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 130 | def BuildTool(self): |
| 131 | env = self._build_env |
asharif | 9e49916 | 2013-02-16 02:41:39 +0000 | [diff] [blame] | 132 | # FEATURES=buildpkg adds minutes of time so we disable it. |
shenhan | fdc0f57 | 2013-02-19 18:48:36 +0000 | [diff] [blame] | 133 | # TODO(shenhan): keep '-sandbox' for a while for compatibility, then remove |
| 134 | # it after a while. |
| 135 | features = "nostrip userpriv userfetch -usersandbox -sandbox noclean -buildpkg" |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 136 | env["FEATURES"] = features |
| 137 | |
| 138 | if self._incremental: |
| 139 | env["FEATURES"] += " keepwork" |
| 140 | |
cmtice | cbc868a | 2013-02-21 22:52:46 +0000 | [diff] [blame] | 141 | if "USE" in env: |
| 142 | env["USE"] += " multislot mounted_%s" % self._name |
| 143 | else: |
| 144 | env["USE"] = "multislot mounted_%s" % self._name |
| 145 | |
llozano | f2726d2 | 2013-03-09 01:29:37 +0000 | [diff] [blame] | 146 | # Disable ccache in our compilers. cache may be problematic for us. |
| 147 | # It ignores compiler environments settings and it is not clear if |
| 148 | # the cache hit algorithm verifies all the compiler binaries or |
| 149 | # just the driver. |
| 150 | if self._name == "gcc" and not self._gcc_enable_ccache: |
| 151 | env["USE"] += " -wrapper_ccache" |
| 152 | |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 153 | env["%s_SOURCE_PATH" % self._name.upper()] = ( |
| 154 | os.path.join("/", self._chroot_source_path)) |
| 155 | env["ACCEPT_KEYWORDS"] = "~*" |
| 156 | env_string = " ".join(["%s=\"%s\"" % var for var in env.items()]) |
| 157 | command = "emerge =cross-%s/%s-9999" % (self._ctarget, self._name) |
| 158 | full_command = "sudo %s %s" % (env_string, command) |
Luis Lozano | 4cea9de | 2013-03-20 12:32:56 -0700 | [diff] [blame] | 159 | rv = self._ce.ChrootRunCommand(self._chromeos_root, full_command) |
| 160 | if rv != 0: |
| 161 | return rv |
| 162 | if self._name == "gcc": |
Rahul Chaudhry | 215c12f | 2014-11-04 15:18:47 -0800 | [diff] [blame] | 163 | command = ("sudo cp -r /usr/lib/gcc/%s %s" % |
| 164 | (self._ctarget, self._gcc_libs_dest)) |
Luis Lozano | 4cea9de | 2013-03-20 12:32:56 -0700 | [diff] [blame] | 165 | rv = self._ce.ChrootRunCommand(self._chromeos_root, command) |
| 166 | return rv |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 167 | |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 168 | def MoveMaskFile(self): |
| 169 | self._new_mask_file = None |
| 170 | if os.path.isfile(self._mask_file): |
| 171 | self._new_mask_file = tempfile.mktemp() |
| 172 | command = "sudo mv %s %s" % (self._mask_file, self._new_mask_file) |
| 173 | self._ce.RunCommand(command) |
| 174 | |
| 175 | def UnMoveMaskFile(self): |
| 176 | if self._new_mask_file: |
| 177 | command = "sudo mv %s %s" % (self._new_mask_file, self._mask_file) |
| 178 | self._ce.RunCommand(command) |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 179 | |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 180 | |
asharif | 0d3535a | 2013-02-15 04:50:33 +0000 | [diff] [blame] | 181 | def Main(argv): |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 182 | """The main function.""" |
asharif | 5a9bb46 | 2013-02-15 04:50:57 +0000 | [diff] [blame] | 183 | # Common initializations |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 184 | parser = optparse.OptionParser() |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 185 | parser.add_option("-c", |
| 186 | "--chromeos_root", |
| 187 | dest="chromeos_root", |
asharif | bcdd4e5 | 2013-02-16 01:05:17 +0000 | [diff] [blame] | 188 | default="../../", |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 189 | help=("ChromeOS root checkout directory" |
| 190 | " uses ../.. if none given.")) |
| 191 | parser.add_option("-g", |
| 192 | "--gcc_dir", |
| 193 | dest="gcc_dir", |
| 194 | help="The directory where gcc resides.") |
shenhan | 8e8b0c2 | 2013-02-19 22:34:16 +0000 | [diff] [blame] | 195 | parser.add_option("--binutils_dir", |
| 196 | dest="binutils_dir", |
| 197 | help="The directory where binutils resides.") |
cmtice | 80d257f | 2013-02-15 23:44:51 +0000 | [diff] [blame] | 198 | parser.add_option("-x", |
| 199 | "--gdb_dir", |
| 200 | dest="gdb_dir", |
| 201 | help="The directory where gdb resides.") |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 202 | parser.add_option("-b", |
| 203 | "--board", |
| 204 | dest="board", |
| 205 | default="x86-agz", |
| 206 | help="The target board.") |
| 207 | parser.add_option("-n", |
| 208 | "--noincremental", |
| 209 | dest="noincremental", |
| 210 | default=False, |
asharif | d751e25 | 2013-02-15 04:35:52 +0000 | [diff] [blame] | 211 | action="store_true", |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 212 | help="Use FEATURES=keepwork to do incremental builds.") |
cmtice | e59ac27 | 2013-02-19 20:20:09 +0000 | [diff] [blame] | 213 | parser.add_option("--cflags", |
| 214 | dest="cflags", |
| 215 | default="", |
| 216 | help="Build a compiler with specified CFLAGS") |
| 217 | parser.add_option("--cxxflags", |
| 218 | dest="cxxflags", |
| 219 | default="", |
| 220 | help="Build a compiler with specified CXXFLAGS") |
carrot | 2b549ca | 2013-02-19 22:45:25 +0000 | [diff] [blame] | 221 | parser.add_option("--cflags_for_target", |
| 222 | dest="cflags_for_target", |
| 223 | default="", |
| 224 | help="Build the target libraries with specified flags") |
| 225 | parser.add_option("--cxxflags_for_target", |
| 226 | dest="cxxflags_for_target", |
| 227 | default="", |
| 228 | help="Build the target libraries with specified flags") |
cmtice | e59ac27 | 2013-02-19 20:20:09 +0000 | [diff] [blame] | 229 | parser.add_option("--ldflags", |
| 230 | dest="ldflags", |
| 231 | default="", |
| 232 | help="Build a compiler with specified LDFLAGS") |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 233 | parser.add_option("-d", |
| 234 | "--debug", |
| 235 | dest="debug", |
| 236 | default=False, |
asharif | d751e25 | 2013-02-15 04:35:52 +0000 | [diff] [blame] | 237 | action="store_true", |
cmtice | e59ac27 | 2013-02-19 20:20:09 +0000 | [diff] [blame] | 238 | help="Build a compiler with -g3 -O0 appended to both" |
| 239 | " CFLAGS and CXXFLAGS.") |
asharif | 86968c4 | 2013-02-15 23:44:37 +0000 | [diff] [blame] | 240 | parser.add_option("-m", |
| 241 | "--mount_only", |
| 242 | dest="mount_only", |
| 243 | default=False, |
| 244 | action="store_true", |
| 245 | help="Just mount the tool directories.") |
cmtice | 80d257f | 2013-02-15 23:44:51 +0000 | [diff] [blame] | 246 | parser.add_option("-u", |
| 247 | "--unmount_only", |
| 248 | dest="unmount_only", |
| 249 | default=False, |
| 250 | action="store_true", |
| 251 | help="Just unmount the tool directories.") |
cmtice | cbc868a | 2013-02-21 22:52:46 +0000 | [diff] [blame] | 252 | parser.add_option("--extra_use_flags", |
| 253 | dest="extra_use_flags", |
| 254 | default="", |
| 255 | help="Extra flag for USE, to be passed to the ebuild. " |
| 256 | "('multislot' and 'mounted_<tool>' are always passed.)") |
llozano | f2726d2 | 2013-03-09 01:29:37 +0000 | [diff] [blame] | 257 | parser.add_option("--gcc_enable_ccache", |
| 258 | dest="gcc_enable_ccache", |
| 259 | default=False, |
| 260 | action="store_true", |
| 261 | help="Enable ccache for the gcc invocations") |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 262 | |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 263 | options, _ = parser.parse_args(argv) |
asharif | 1762130 | 2013-02-15 04:46:35 +0000 | [diff] [blame] | 264 | |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 265 | chromeos_root = misc.CanonicalizePath(options.chromeos_root) |
cmtice | 80d257f | 2013-02-15 23:44:51 +0000 | [diff] [blame] | 266 | if options.gcc_dir: |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 267 | gcc_dir = misc.CanonicalizePath(options.gcc_dir) |
Luis Lozano | 4cea9de | 2013-03-20 12:32:56 -0700 | [diff] [blame] | 268 | assert gcc_dir and os.path.isdir(gcc_dir), "gcc_dir does not exist!" |
shenhan | 8e8b0c2 | 2013-02-19 22:34:16 +0000 | [diff] [blame] | 269 | if options.binutils_dir: |
| 270 | binutils_dir = misc.CanonicalizePath(options.binutils_dir) |
Luis Lozano | 4cea9de | 2013-03-20 12:32:56 -0700 | [diff] [blame] | 271 | assert os.path.isdir(binutils_dir), "binutils_dir does not exist!" |
cmtice | 80d257f | 2013-02-15 23:44:51 +0000 | [diff] [blame] | 272 | if options.gdb_dir: |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 273 | gdb_dir = misc.CanonicalizePath(options.gdb_dir) |
Luis Lozano | 4cea9de | 2013-03-20 12:32:56 -0700 | [diff] [blame] | 274 | assert os.path.isdir(gdb_dir), "gdb_dir does not exist!" |
cmtice | 80d257f | 2013-02-15 23:44:51 +0000 | [diff] [blame] | 275 | if options.unmount_only: |
| 276 | options.mount_only = False |
| 277 | elif options.mount_only: |
| 278 | options.unmount_only = False |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 279 | build_env = {} |
cmtice | e59ac27 | 2013-02-19 20:20:09 +0000 | [diff] [blame] | 280 | if options.cflags: |
carrot | 255fd46 | 2013-02-19 22:43:16 +0000 | [diff] [blame] | 281 | build_env["CFLAGS"] = "`portageq envvar CFLAGS` " + options.cflags |
cmtice | e59ac27 | 2013-02-19 20:20:09 +0000 | [diff] [blame] | 282 | if options.cxxflags: |
carrot | 255fd46 | 2013-02-19 22:43:16 +0000 | [diff] [blame] | 283 | build_env["CXXFLAGS"] = "`portageq envvar CXXFLAGS` " + options.cxxflags |
carrot | 2b549ca | 2013-02-19 22:45:25 +0000 | [diff] [blame] | 284 | if options.cflags_for_target: |
| 285 | build_env["CFLAGS_FOR_TARGET"] = options.cflags_for_target |
| 286 | if options.cxxflags_for_target: |
| 287 | build_env["CXXFLAGS_FOR_TARGET"] = options.cxxflags_for_target |
carrot | 255fd46 | 2013-02-19 22:43:16 +0000 | [diff] [blame] | 288 | if options.ldflags: |
cmtice | e59ac27 | 2013-02-19 20:20:09 +0000 | [diff] [blame] | 289 | build_env["LDFLAGS"] = options.ldflags |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 290 | if options.debug: |
| 291 | debug_flags = "-g3 -O0" |
cmtice | e59ac27 | 2013-02-19 20:20:09 +0000 | [diff] [blame] | 292 | if "CFLAGS" in build_env: |
| 293 | build_env["CFLAGS"] += " %s" % (debug_flags) |
| 294 | else: |
| 295 | build_env["CFLAGS"] = debug_flags |
| 296 | if "CXXFLAGS" in build_env: |
| 297 | build_env["CXXFLAGS"] += " %s" % (debug_flags) |
| 298 | else: |
| 299 | build_env["CXXFLAGS"] = debug_flags |
cmtice | cbc868a | 2013-02-21 22:52:46 +0000 | [diff] [blame] | 300 | if options.extra_use_flags: |
| 301 | build_env["USE"] = options.extra_use_flags |
bjanakiraman | 7f4a485 | 2013-02-15 04:35:28 +0000 | [diff] [blame] | 302 | |
asharif | 86968c4 | 2013-02-15 23:44:37 +0000 | [diff] [blame] | 303 | # Create toolchain parts |
carrot | e6f773c | 2013-02-19 22:34:44 +0000 | [diff] [blame] | 304 | toolchain_parts = {} |
asharif | 86968c4 | 2013-02-15 23:44:37 +0000 | [diff] [blame] | 305 | for board in options.board.split(","): |
| 306 | if options.gcc_dir: |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 307 | tp = ToolchainPart("gcc", gcc_dir, chromeos_root, board, |
llozano | f2726d2 | 2013-03-09 01:29:37 +0000 | [diff] [blame] | 308 | not options.noincremental, build_env, |
| 309 | options.gcc_enable_ccache) |
carrot | e6f773c | 2013-02-19 22:34:44 +0000 | [diff] [blame] | 310 | toolchain_parts[tp.tag] = tp |
| 311 | tp.RunSetupBoardIfNecessary() |
shenhan | 8e8b0c2 | 2013-02-19 22:34:16 +0000 | [diff] [blame] | 312 | if options.binutils_dir: |
| 313 | tp = ToolchainPart("binutils", binutils_dir, chromeos_root, board, |
| 314 | not options.noincremental, build_env) |
carrot | e6f773c | 2013-02-19 22:34:44 +0000 | [diff] [blame] | 315 | toolchain_parts[tp.tag] = tp |
| 316 | tp.RunSetupBoardIfNecessary() |
cmtice | 80d257f | 2013-02-15 23:44:51 +0000 | [diff] [blame] | 317 | if options.gdb_dir: |
| 318 | tp = ToolchainPart("gdb", gdb_dir, chromeos_root, board, |
| 319 | not options.noincremental, build_env) |
carrot | e6f773c | 2013-02-19 22:34:44 +0000 | [diff] [blame] | 320 | toolchain_parts[tp.tag] = tp |
| 321 | tp.RunSetupBoardIfNecessary() |
asharif | 86968c4 | 2013-02-15 23:44:37 +0000 | [diff] [blame] | 322 | |
shenhan | becf624 | 2013-02-19 20:43:32 +0000 | [diff] [blame] | 323 | rv = 0 |
asharif | 86968c4 | 2013-02-15 23:44:37 +0000 | [diff] [blame] | 324 | try: |
carrot | e6f773c | 2013-02-19 22:34:44 +0000 | [diff] [blame] | 325 | for tag in toolchain_parts: |
| 326 | tp = toolchain_parts[tag] |
cmtice | 80d257f | 2013-02-15 23:44:51 +0000 | [diff] [blame] | 327 | if options.mount_only or options.unmount_only: |
| 328 | tp.MountSources(options.unmount_only) |
asharif | 86968c4 | 2013-02-15 23:44:37 +0000 | [diff] [blame] | 329 | else: |
shenhan | becf624 | 2013-02-19 20:43:32 +0000 | [diff] [blame] | 330 | rv = rv + tp.Build() |
asharif | c97199a | 2013-02-15 22:48:45 +0000 | [diff] [blame] | 331 | finally: |
| 332 | print "Exiting..." |
llozano | 5fee82f | 2013-03-11 17:59:40 +0000 | [diff] [blame] | 333 | return rv |
asharif | 19c73dd | 2013-02-15 04:35:37 +0000 | [diff] [blame] | 334 | |
| 335 | if __name__ == "__main__": |
asharif | 2198c51 | 2013-02-15 09:21:35 +0000 | [diff] [blame] | 336 | retval = Main(sys.argv) |
| 337 | sys.exit(retval) |