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