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