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