Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Mike Frysinger | 750c5f5 | 2014-09-16 16:16:57 -0400 | [diff] [blame] | 5 | """This script manages the installed toolchains in the chroot.""" |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 6 | |
Mike Frysinger | 3ed4772 | 2017-08-08 14:59:08 -0400 | [diff] [blame] | 7 | import errno |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 8 | import glob |
Mike Frysinger | 3ed4772 | 2017-08-08 14:59:08 -0400 | [diff] [blame] | 9 | import hashlib |
Mike Frysinger | 7ccee99 | 2012-06-01 21:27:59 -0400 | [diff] [blame] | 10 | import json |
Chris McDonald | 59650c3 | 2021-07-20 15:29:28 -0600 | [diff] [blame] | 11 | import logging |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 12 | import os |
Rahul Chaudhry | a8127bb | 2016-07-22 15:53:17 -0700 | [diff] [blame] | 13 | import re |
Tobias Bosch | ddd1649 | 2019-08-14 09:29:54 -0700 | [diff] [blame] | 14 | import shutil |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 15 | |
Chris McDonald | 59650c3 | 2021-07-20 15:29:28 -0600 | [diff] [blame] | 16 | from chromite.third_party import lddtree |
| 17 | |
Mike Frysinger | 506e75f | 2012-12-17 14:21:13 -0500 | [diff] [blame] | 18 | from chromite.lib import commandline |
Mike Frysinger | 9545270 | 2021-01-23 00:07:22 -0500 | [diff] [blame] | 19 | from chromite.lib import constants |
Brian Harring | 503f3ab | 2012-03-09 21:39:41 -0800 | [diff] [blame] | 20 | from chromite.lib import cros_build_lib |
Brian Harring | af019fb | 2012-05-10 15:06:13 -0700 | [diff] [blame] | 21 | from chromite.lib import osutils |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 22 | from chromite.lib import parallel |
David James | 27ac4ae | 2012-12-03 23:16:15 -0800 | [diff] [blame] | 23 | from chromite.lib import toolchain |
Mike Frysinger | e652ba1 | 2019-09-08 00:57:43 -0400 | [diff] [blame] | 24 | from chromite.utils import key_value_store |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 25 | |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 26 | |
Mike Frysinger | 3159600 | 2012-12-03 23:54:24 -0500 | [diff] [blame] | 27 | if cros_build_lib.IsInsideChroot(): |
| 28 | # Only import portage after we've checked that we're inside the chroot. |
| 29 | # Outside may not have portage, in which case the above may not happen. |
| 30 | # We'll check in main() if the operation needs portage. |
Mike Frysinger | 27e21b7 | 2018-07-12 14:20:21 -0400 | [diff] [blame] | 31 | # pylint: disable=import-error |
Mike Frysinger | 3159600 | 2012-12-03 23:54:24 -0500 | [diff] [blame] | 32 | import portage |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 33 | |
| 34 | |
Matt Tennant | f1e3097 | 2012-03-02 16:30:07 -0800 | [diff] [blame] | 35 | EMERGE_CMD = os.path.join(constants.CHROMITE_BIN_DIR, 'parallel_emerge') |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 36 | PACKAGE_STABLE = '[stable]' |
Zdenek Behan | 4eb6fd2 | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 37 | |
Mike Frysinger | 4cd80b6 | 2022-05-04 20:39:01 -0400 | [diff] [blame] | 38 | CHROMIUMOS_OVERLAY = os.path.join( |
| 39 | constants.CHROOT_SOURCE_ROOT, constants.CHROMIUMOS_OVERLAY_DIR) |
| 40 | ECLASS_OVERLAY = os.path.join( |
| 41 | constants.CHROOT_SOURCE_ROOT, constants.ECLASS_OVERLAY_DIR) |
| 42 | STABLE_OVERLAY = os.path.join( |
| 43 | constants.CHROOT_SOURCE_ROOT, constants.PORTAGE_STABLE_OVERLAY_DIR) |
Zdenek Behan | 4eb6fd2 | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 44 | CROSSDEV_OVERLAY = '/usr/local/portage/crossdev' |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 45 | |
| 46 | |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 47 | # The exact list of host toolchain packages we care about. These are the |
| 48 | # packages that bots/devs install only from binpkgs and rely on the SDK bot |
| 49 | # (chromiumos-sdk) to validate+uprev. |
| 50 | # |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 51 | # We don't use crossdev to manage the host toolchain for us, especially since |
| 52 | # we diverge significantly now (with llvm/clang/etc...), and we don't need or |
| 53 | # want crossdev managing /etc/portage config files for the sdk |
| 54 | HOST_PACKAGES = ( |
| 55 | 'dev-lang/go', |
Yunlian Jiang | 2cb91dc | 2018-03-08 10:56:27 -0800 | [diff] [blame] | 56 | 'dev-libs/elfutils', |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 57 | 'sys-devel/binutils', |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 58 | 'sys-devel/gcc', |
| 59 | 'sys-devel/llvm', |
| 60 | 'sys-kernel/linux-headers', |
| 61 | 'sys-libs/glibc', |
| 62 | 'sys-libs/libcxx', |
| 63 | 'sys-libs/libcxxabi', |
Manoj Gupta | de64cb2 | 2019-03-31 18:48:58 -0700 | [diff] [blame] | 64 | 'sys-libs/llvm-libunwind', |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 65 | ) |
| 66 | |
Mike Frysinger | 785b0c3 | 2017-09-13 01:35:59 -0400 | [diff] [blame] | 67 | # These packages are also installed into the host SDK. However, they require |
| 68 | # the cross-compilers to be installed first (because they need them to actually |
| 69 | # build), so we have to delay their installation. |
| 70 | HOST_POST_CROSS_PACKAGES = ( |
Manoj Gupta | 65f8844 | 2018-04-12 22:42:19 -0700 | [diff] [blame] | 71 | 'dev-lang/rust', |
George Burgess IV | 9d1e232 | 2021-04-30 09:54:45 -0700 | [diff] [blame] | 72 | 'dev-lang/rust-bootstrap', |
Mike Frysinger | 61a2439 | 2017-10-17 17:14:27 -0400 | [diff] [blame] | 73 | 'virtual/target-sdk-post-cross', |
Patrick Georgi | 043ce6e | 2019-02-20 22:27:09 +0100 | [diff] [blame] | 74 | 'dev-embedded/coreboot-sdk', |
Dan Callaghan | 7cc58ff | 2022-02-16 08:38:13 +1100 | [diff] [blame] | 75 | 'dev-embedded/hps-sdk', |
George Burgess IV | 288ecc8 | 2021-04-21 07:52:45 -0700 | [diff] [blame] | 76 | 'dev-embedded/ti50-sdk', |
Mike Frysinger | 785b0c3 | 2017-09-13 01:35:59 -0400 | [diff] [blame] | 77 | ) |
| 78 | |
| 79 | # New packages that we're in the process of adding to the SDK. Since the SDK |
| 80 | # bot hasn't had a chance to run yet, there are no binary packages available, |
| 81 | # so we have to list them here and wait. Once it completes, entries here can |
| 82 | # be removed so they'll end up on bots & dev's systems. |
George Burgess IV | 66e199c | 2021-05-05 15:38:40 -0700 | [diff] [blame] | 83 | NEW_PACKAGES = () |
Mike Frysinger | 785b0c3 | 2017-09-13 01:35:59 -0400 | [diff] [blame] | 84 | |
Rahul Chaudhry | 4b80305 | 2015-05-13 15:25:56 -0700 | [diff] [blame] | 85 | # Enable the Go compiler for these targets. |
| 86 | TARGET_GO_ENABLED = ( |
| 87 | 'x86_64-cros-linux-gnu', |
Rahul Chaudhry | 4b80305 | 2015-05-13 15:25:56 -0700 | [diff] [blame] | 88 | 'armv7a-cros-linux-gnueabi', |
Yunlian Jiang | 16c1a42 | 2017-10-04 10:33:22 -0700 | [diff] [blame] | 89 | 'armv7a-cros-linux-gnueabihf', |
Rahul Chaudhry | 4d41658 | 2017-10-25 12:31:58 -0700 | [diff] [blame] | 90 | 'aarch64-cros-linux-gnu', |
Rahul Chaudhry | 4b80305 | 2015-05-13 15:25:56 -0700 | [diff] [blame] | 91 | ) |
| 92 | CROSSDEV_GO_ARGS = ['--ex-pkg', 'dev-lang/go'] |
| 93 | |
Adrian Ratiu | bf0b9af | 2022-05-02 14:48:15 +0300 | [diff] [blame] | 94 | CROSSDEV_LIBXCRYPT_ARGS = ['--ex-pkg', 'sys-libs/libxcrypt'] |
| 95 | |
Manoj Gupta | 1b5642e | 2017-03-08 16:44:12 -0800 | [diff] [blame] | 96 | # Enable llvm's compiler-rt for these targets. |
| 97 | TARGET_COMPILER_RT_ENABLED = ( |
| 98 | 'armv7a-cros-linux-gnueabi', |
Yunlian Jiang | 1b77ee4 | 2017-10-06 13:44:29 -0700 | [diff] [blame] | 99 | 'armv7a-cros-linux-gnueabihf', |
Manoj Gupta | 946abb4 | 2017-04-12 14:27:19 -0700 | [diff] [blame] | 100 | 'aarch64-cros-linux-gnu', |
Manoj Gupta | bf1b642 | 2021-11-08 09:50:20 -0800 | [diff] [blame] | 101 | 'arm-none-eabi', |
Manoj Gupta | 21f3a08 | 2018-03-06 21:25:39 -0800 | [diff] [blame] | 102 | 'armv7m-cros-eabi', |
Manoj Gupta | 1b5642e | 2017-03-08 16:44:12 -0800 | [diff] [blame] | 103 | ) |
| 104 | CROSSDEV_COMPILER_RT_ARGS = ['--ex-pkg', 'sys-libs/compiler-rt'] |
| 105 | |
Manoj Gupta | 946abb4 | 2017-04-12 14:27:19 -0700 | [diff] [blame] | 106 | TARGET_LLVM_PKGS_ENABLED = ( |
Manoj Gupta | 847b609 | 2022-06-01 10:26:34 -0700 | [diff] [blame^] | 107 | 'armv7m-cros-eabi', |
Manoj Gupta | 946abb4 | 2017-04-12 14:27:19 -0700 | [diff] [blame] | 108 | 'armv7a-cros-linux-gnueabi', |
Yunlian Jiang | 16c1a42 | 2017-10-04 10:33:22 -0700 | [diff] [blame] | 109 | 'armv7a-cros-linux-gnueabihf', |
Manoj Gupta | 946abb4 | 2017-04-12 14:27:19 -0700 | [diff] [blame] | 110 | 'aarch64-cros-linux-gnu', |
Mike Frysinger | d96d544 | 2021-11-09 05:12:34 -0500 | [diff] [blame] | 111 | 'i686-cros-linux-gnu', |
Manoj Gupta | 946abb4 | 2017-04-12 14:27:19 -0700 | [diff] [blame] | 112 | 'x86_64-cros-linux-gnu', |
| 113 | ) |
| 114 | |
| 115 | LLVM_PKGS_TABLE = { |
Manoj Gupta | 6502bcd | 2021-08-07 14:25:01 -0700 | [diff] [blame] | 116 | 'ex_llvm-libunwind' : ['--ex-pkg', 'sys-libs/llvm-libunwind'], |
Yunlian Jiang | bb2a3d3 | 2017-04-26 14:44:09 -0700 | [diff] [blame] | 117 | 'ex_libcxxabi' : ['--ex-pkg', 'sys-libs/libcxxabi'], |
| 118 | 'ex_libcxx' : ['--ex-pkg', 'sys-libs/libcxx'], |
Manoj Gupta | 946abb4 | 2017-04-12 14:27:19 -0700 | [diff] [blame] | 119 | } |
| 120 | |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 121 | class Crossdev(object): |
| 122 | """Class for interacting with crossdev and caching its output.""" |
| 123 | |
| 124 | _CACHE_FILE = os.path.join(CROSSDEV_OVERLAY, '.configured.json') |
| 125 | _CACHE = {} |
Han Shen | e23782f | 2016-02-18 12:20:00 -0800 | [diff] [blame] | 126 | # Packages that needs separate handling, in addition to what we have from |
| 127 | # crossdev. |
| 128 | MANUAL_PKGS = { |
George Burgess IV | ca1d761 | 2020-10-01 00:38:32 -0700 | [diff] [blame] | 129 | 'rust': 'dev-lang', |
Han Shen | e23782f | 2016-02-18 12:20:00 -0800 | [diff] [blame] | 130 | 'llvm': 'sys-devel', |
Manoj Gupta | 6502bcd | 2021-08-07 14:25:01 -0700 | [diff] [blame] | 131 | 'llvm-libunwind': 'sys-libs', |
Manoj Gupta | 20cfc6c | 2017-07-19 15:49:55 -0700 | [diff] [blame] | 132 | 'libcxxabi': 'sys-libs', |
| 133 | 'libcxx': 'sys-libs', |
Yunlian Jiang | da3ce5f | 2018-04-25 14:10:01 -0700 | [diff] [blame] | 134 | 'elfutils': 'dev-libs', |
Han Shen | e23782f | 2016-02-18 12:20:00 -0800 | [diff] [blame] | 135 | } |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 136 | |
| 137 | @classmethod |
| 138 | def Load(cls, reconfig): |
Mike Frysinger | 3ed4772 | 2017-08-08 14:59:08 -0400 | [diff] [blame] | 139 | """Load crossdev cache from disk. |
| 140 | |
| 141 | We invalidate the cache when crossdev updates or this script changes. |
| 142 | """ |
David James | 90239b9 | 2012-11-05 15:31:34 -0800 | [diff] [blame] | 143 | crossdev_version = GetStablePackageVersion('sys-devel/crossdev', True) |
Mike Frysinger | 3ed4772 | 2017-08-08 14:59:08 -0400 | [diff] [blame] | 144 | # If we run the compiled/cached .pyc file, we'll read/hash that when we |
| 145 | # really always want to track the source .py file. |
| 146 | script = os.path.abspath(__file__) |
| 147 | if script.endswith('.pyc'): |
| 148 | script = script[:-1] |
Mike Frysinger | b3202be | 2019-11-15 22:25:59 -0500 | [diff] [blame] | 149 | setup_toolchains_hash = hashlib.md5( |
| 150 | osutils.ReadFile(script, mode='rb')).hexdigest() |
Mike Frysinger | 3ed4772 | 2017-08-08 14:59:08 -0400 | [diff] [blame] | 151 | |
| 152 | cls._CACHE = { |
| 153 | 'crossdev_version': crossdev_version, |
| 154 | 'setup_toolchains_hash': setup_toolchains_hash, |
| 155 | } |
| 156 | |
| 157 | logging.debug('cache: checking file: %s', cls._CACHE_FILE) |
| 158 | if reconfig: |
| 159 | logging.debug('cache: forcing regen due to reconfig') |
| 160 | return |
| 161 | |
| 162 | try: |
| 163 | file_data = osutils.ReadFile(cls._CACHE_FILE) |
| 164 | except IOError as e: |
| 165 | if e.errno != errno.ENOENT: |
| 166 | logging.warning('cache: reading failed: %s', e) |
| 167 | osutils.SafeUnlink(cls._CACHE_FILE) |
| 168 | return |
| 169 | |
| 170 | try: |
| 171 | data = json.loads(file_data) |
| 172 | except ValueError as e: |
| 173 | logging.warning('cache: ignoring invalid content: %s', e) |
| 174 | return |
| 175 | |
| 176 | if crossdev_version != data.get('crossdev_version'): |
| 177 | logging.debug('cache: rebuilding after crossdev upgrade') |
| 178 | elif setup_toolchains_hash != data.get('setup_toolchains_hash'): |
| 179 | logging.debug('cache: rebuilding after cros_setup_toolchains change') |
| 180 | else: |
| 181 | logging.debug('cache: content is up-to-date!') |
| 182 | cls._CACHE = data |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 183 | |
| 184 | @classmethod |
| 185 | def Save(cls): |
| 186 | """Store crossdev cache on disk.""" |
| 187 | # Save the cache from the successful run. |
| 188 | with open(cls._CACHE_FILE, 'w') as f: |
| 189 | json.dump(cls._CACHE, f) |
| 190 | |
| 191 | @classmethod |
| 192 | def GetConfig(cls, target): |
| 193 | """Returns a map of crossdev provided variables about a tuple.""" |
| 194 | CACHE_ATTR = '_target_tuple_map' |
| 195 | |
| 196 | val = cls._CACHE.setdefault(CACHE_ATTR, {}) |
| 197 | if not target in val: |
Mike Frysinger | 785b0c3 | 2017-09-13 01:35:59 -0400 | [diff] [blame] | 198 | if target.startswith('host'): |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 199 | conf = { |
| 200 | 'crosspkgs': [], |
| 201 | 'target': toolchain.GetHostTuple(), |
| 202 | } |
Mike Frysinger | 785b0c3 | 2017-09-13 01:35:59 -0400 | [diff] [blame] | 203 | if target == 'host': |
| 204 | packages_list = HOST_PACKAGES |
| 205 | else: |
| 206 | packages_list = HOST_POST_CROSS_PACKAGES |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 207 | manual_pkgs = dict((pkg, cat) for cat, pkg in |
Mike Frysinger | 785b0c3 | 2017-09-13 01:35:59 -0400 | [diff] [blame] | 208 | [x.split('/') for x in packages_list]) |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 209 | else: |
| 210 | # Build the crossdev command. |
| 211 | cmd = ['crossdev', '--show-target-cfg', '--ex-gdb'] |
Adrian Ratiu | bf0b9af | 2022-05-02 14:48:15 +0300 | [diff] [blame] | 212 | # Enable libxcrypt for all linux-gnu targets. |
| 213 | if 'cros-linux-gnu' in target: |
| 214 | cmd.extend(CROSSDEV_LIBXCRYPT_ARGS) |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 215 | if target in TARGET_COMPILER_RT_ENABLED: |
| 216 | cmd.extend(CROSSDEV_COMPILER_RT_ARGS) |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 217 | if target in TARGET_LLVM_PKGS_ENABLED: |
| 218 | for pkg in LLVM_PKGS_TABLE: |
| 219 | cmd.extend(LLVM_PKGS_TABLE[pkg]) |
Manoj Gupta | 7860728 | 2021-05-24 16:58:13 +0000 | [diff] [blame] | 220 | if target in TARGET_GO_ENABLED: |
| 221 | cmd.extend(CROSSDEV_GO_ARGS) |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 222 | cmd.extend(['-t', target]) |
| 223 | # Catch output of crossdev. |
Mike Frysinger | 45602c7 | 2019-09-22 02:15:11 -0400 | [diff] [blame] | 224 | out = cros_build_lib.run( |
Mike Frysinger | 0282d22 | 2019-12-17 17:15:48 -0500 | [diff] [blame] | 225 | cmd, print_cmd=False, stdout=True, |
Mike Frysinger | b3202be | 2019-11-15 22:25:59 -0500 | [diff] [blame] | 226 | encoding='utf-8').stdout.splitlines() |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 227 | # List of tuples split at the first '=', converted into dict. |
| 228 | conf = dict((k, cros_build_lib.ShellUnquote(v)) |
| 229 | for k, v in (x.split('=', 1) for x in out)) |
| 230 | conf['crosspkgs'] = conf['crosspkgs'].split() |
Han Shen | e23782f | 2016-02-18 12:20:00 -0800 | [diff] [blame] | 231 | |
Mike Frysinger | 66bfde5 | 2017-09-12 16:42:57 -0400 | [diff] [blame] | 232 | manual_pkgs = cls.MANUAL_PKGS |
| 233 | |
| 234 | for pkg, cat in manual_pkgs.items(): |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 235 | conf[pkg + '_pn'] = pkg |
| 236 | conf[pkg + '_category'] = cat |
| 237 | if pkg not in conf['crosspkgs']: |
| 238 | conf['crosspkgs'].append(pkg) |
Han Shen | e23782f | 2016-02-18 12:20:00 -0800 | [diff] [blame] | 239 | |
| 240 | val[target] = conf |
| 241 | |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 242 | return val[target] |
| 243 | |
| 244 | @classmethod |
| 245 | def UpdateTargets(cls, targets, usepkg, config_only=False): |
| 246 | """Calls crossdev to initialize a cross target. |
| 247 | |
| 248 | Args: |
Manoj Gupta | 4d016f6 | 2021-10-19 16:39:34 -0700 | [diff] [blame] | 249 | targets: The dict of targets to initialize using crossdev. |
Don Garrett | 25f309a | 2014-03-19 14:02:12 -0700 | [diff] [blame] | 250 | usepkg: Copies the commandline opts. |
| 251 | config_only: Just update. |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 252 | """ |
| 253 | configured_targets = cls._CACHE.setdefault('configured_targets', []) |
Manoj Gupta | 4d016f6 | 2021-10-19 16:39:34 -0700 | [diff] [blame] | 254 | started_targets = set() |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 255 | |
Manoj Gupta | 4d016f6 | 2021-10-19 16:39:34 -0700 | [diff] [blame] | 256 | # Schedule all of the targets in parallel, and let them run. |
| 257 | with parallel.BackgroundTaskRunner(cls._UpdateTarget) as queue: |
| 258 | for target_name in targets: |
| 259 | # We already started this target in this loop. |
| 260 | if target_name in started_targets: |
| 261 | continue |
| 262 | # The target is already configured. |
| 263 | if config_only and target_name in configured_targets: |
| 264 | continue |
| 265 | queue.put([target_name, targets[target_name], usepkg, config_only]) |
| 266 | started_targets.add(target_name) |
| 267 | |
| 268 | @classmethod |
| 269 | def _UpdateTarget(cls, target_name, target, usepkg, config_only): |
| 270 | """Calls crossdev to initialize a cross target. |
| 271 | |
| 272 | Args: |
| 273 | target_name: The name of the target to initialize. |
| 274 | target: The target info for initializing. |
| 275 | usepkg: Copies the commandline opts. |
| 276 | config_only: Just update. |
| 277 | """ |
| 278 | configured_targets = cls._CACHE.setdefault('configured_targets', []) |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 279 | cmdbase = ['crossdev', '--show-fail-log'] |
| 280 | cmdbase.extend(['--env', 'FEATURES=splitdebug']) |
| 281 | # Pick stable by default, and override as necessary. |
| 282 | cmdbase.extend(['-P', '--oneshot']) |
| 283 | if usepkg: |
| 284 | cmdbase.extend(['-P', '--getbinpkg', |
| 285 | '-P', '--usepkgonly', |
| 286 | '--without-headers']) |
| 287 | |
Christopher Wiley | b22c071 | 2015-06-02 10:37:03 -0700 | [diff] [blame] | 288 | overlays = ' '.join((CHROMIUMOS_OVERLAY, ECLASS_OVERLAY, STABLE_OVERLAY)) |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 289 | cmdbase.extend(['--overlays', overlays]) |
| 290 | cmdbase.extend(['--ov-output', CROSSDEV_OVERLAY]) |
| 291 | |
Manoj Gupta | 4d016f6 | 2021-10-19 16:39:34 -0700 | [diff] [blame] | 292 | cmd = cmdbase + ['-t', target_name] |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 293 | |
Manoj Gupta | 4d016f6 | 2021-10-19 16:39:34 -0700 | [diff] [blame] | 294 | for pkg in GetTargetPackages(target_name): |
| 295 | if pkg == 'gdb': |
| 296 | # Gdb does not have selectable versions. |
| 297 | cmd.append('--ex-gdb') |
Adrian Ratiu | bf0b9af | 2022-05-02 14:48:15 +0300 | [diff] [blame] | 298 | elif pkg == 'ex_libxcrypt': |
| 299 | cmd.extend(CROSSDEV_LIBXCRYPT_ARGS) |
Manoj Gupta | 4d016f6 | 2021-10-19 16:39:34 -0700 | [diff] [blame] | 300 | elif pkg == 'ex_compiler-rt': |
| 301 | cmd.extend(CROSSDEV_COMPILER_RT_ARGS) |
| 302 | elif pkg == 'ex_go': |
| 303 | # Go does not have selectable versions. |
| 304 | cmd.extend(CROSSDEV_GO_ARGS) |
| 305 | elif pkg in LLVM_PKGS_TABLE: |
| 306 | cmd.extend(LLVM_PKGS_TABLE[pkg]) |
| 307 | elif pkg in cls.MANUAL_PKGS: |
| 308 | pass |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 309 | else: |
Manoj Gupta | 4d016f6 | 2021-10-19 16:39:34 -0700 | [diff] [blame] | 310 | # The first of the desired versions is the "primary" one. |
| 311 | version = GetDesiredPackageVersions(target_name, pkg)[0] |
| 312 | cmd.extend(['--%s' % pkg, version]) |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 313 | |
Manoj Gupta | 4d016f6 | 2021-10-19 16:39:34 -0700 | [diff] [blame] | 314 | cmd.extend(target['crossdev'].split()) |
| 315 | |
| 316 | if config_only: |
| 317 | # In this case we want to just quietly reinit |
| 318 | cmd.append('--init-target') |
| 319 | cros_build_lib.run(cmd, print_cmd=False, stdout=True) |
| 320 | else: |
| 321 | cros_build_lib.run(cmd) |
| 322 | |
| 323 | configured_targets.append(target_name) |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 324 | |
Zdenek Behan | 4eb6fd2 | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 325 | |
Zdenek Behan | f4d18a0 | 2012-03-22 15:45:05 +0100 | [diff] [blame] | 326 | def GetTargetPackages(target): |
| 327 | """Returns a list of packages for a given target.""" |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 328 | conf = Crossdev.GetConfig(target) |
Zdenek Behan | f4d18a0 | 2012-03-22 15:45:05 +0100 | [diff] [blame] | 329 | # Undesired packages are denoted by empty ${pkg}_pn variable. |
Han Shen | e23782f | 2016-02-18 12:20:00 -0800 | [diff] [blame] | 330 | return [x for x in conf['crosspkgs'] if conf.get(x+'_pn')] |
Zdenek Behan | f4d18a0 | 2012-03-22 15:45:05 +0100 | [diff] [blame] | 331 | |
| 332 | |
Zdenek Behan | 4eb6fd2 | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 333 | # Portage helper functions: |
| 334 | def GetPortagePackage(target, package): |
| 335 | """Returns a package name for the given target.""" |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 336 | conf = Crossdev.GetConfig(target) |
Zdenek Behan | 4eb6fd2 | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 337 | # Portage category: |
Mike Frysinger | 785b0c3 | 2017-09-13 01:35:59 -0400 | [diff] [blame] | 338 | if target.startswith('host') or package in Crossdev.MANUAL_PKGS: |
Zdenek Behan | 4eb6fd2 | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 339 | category = conf[package + '_category'] |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 340 | else: |
Zdenek Behan | 4eb6fd2 | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 341 | category = conf['category'] |
| 342 | # Portage package: |
| 343 | pn = conf[package + '_pn'] |
| 344 | # Final package name: |
Mike Frysinger | 422faf4 | 2014-11-12 23:16:48 -0500 | [diff] [blame] | 345 | assert category |
| 346 | assert pn |
Zdenek Behan | 4eb6fd2 | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 347 | return '%s/%s' % (category, pn) |
| 348 | |
| 349 | |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 350 | def PortageTrees(root): |
| 351 | """Return the portage trees for a given root.""" |
| 352 | if root == '/': |
| 353 | return portage.db['/'] |
| 354 | # The portage logic requires the path always end in a slash. |
| 355 | root = root.rstrip('/') + '/' |
| 356 | return portage.create_trees(target_root=root, config_root=root)[root] |
| 357 | |
| 358 | |
| 359 | def GetInstalledPackageVersions(atom, root='/'): |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 360 | """Extracts the list of current versions of a target, package pair. |
| 361 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 362 | Args: |
| 363 | atom: The atom to operate on (e.g. sys-devel/gcc) |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 364 | root: The root to check for installed packages. |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 365 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 366 | Returns: |
| 367 | The list of versions of the package currently installed. |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 368 | """ |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 369 | versions = [] |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 370 | for pkg in PortageTrees(root)['vartree'].dbapi.match(atom, use_cache=0): |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 371 | version = portage.versions.cpv_getversion(pkg) |
| 372 | versions.append(version) |
| 373 | return versions |
| 374 | |
| 375 | |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 376 | def GetStablePackageVersion(atom, installed, root='/'): |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 377 | """Extracts the current stable version for a given package. |
| 378 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 379 | Args: |
Mike Frysinger | d96d544 | 2021-11-09 05:12:34 -0500 | [diff] [blame] | 380 | atom: The target/package to operate on e.g. i686-cros-linux-gnu/gcc |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 381 | installed: Whether we want installed packages or ebuilds |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 382 | root: The root to use when querying packages. |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 383 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 384 | Returns: |
| 385 | A string containing the latest version. |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 386 | """ |
David James | 90239b9 | 2012-11-05 15:31:34 -0800 | [diff] [blame] | 387 | pkgtype = 'vartree' if installed else 'porttree' |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 388 | cpv = portage.best(PortageTrees(root)[pkgtype].dbapi.match(atom, use_cache=0)) |
David James | 90239b9 | 2012-11-05 15:31:34 -0800 | [diff] [blame] | 389 | return portage.versions.cpv_getversion(cpv) if cpv else None |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 390 | |
| 391 | |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 392 | def VersionListToNumeric(target, package, versions, installed, root='/'): |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 393 | """Resolves keywords in a given version list for a particular package. |
| 394 | |
| 395 | Resolving means replacing PACKAGE_STABLE with the actual number. |
| 396 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 397 | Args: |
Mike Frysinger | d96d544 | 2021-11-09 05:12:34 -0500 | [diff] [blame] | 398 | target: The target to operate on (e.g. i686-cros-linux-gnu) |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 399 | package: The target/package to operate on (e.g. gcc) |
| 400 | versions: List of versions to resolve |
| 401 | installed: Query installed packages |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 402 | root: The install root to use; ignored if |installed| is False. |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 403 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 404 | Returns: |
| 405 | List of purely numeric versions equivalent to argument |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 406 | """ |
| 407 | resolved = [] |
David James | 90239b9 | 2012-11-05 15:31:34 -0800 | [diff] [blame] | 408 | atom = GetPortagePackage(target, package) |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 409 | if not installed: |
| 410 | root = '/' |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 411 | for version in versions: |
| 412 | if version == PACKAGE_STABLE: |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 413 | resolved.append(GetStablePackageVersion(atom, installed, root=root)) |
Mike Frysinger | 7f0e198 | 2017-09-12 17:08:50 -0400 | [diff] [blame] | 414 | else: |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 415 | resolved.append(version) |
| 416 | return resolved |
| 417 | |
| 418 | |
| 419 | def GetDesiredPackageVersions(target, package): |
| 420 | """Produces the list of desired versions for each target, package pair. |
| 421 | |
| 422 | The first version in the list is implicitly treated as primary, ie. |
| 423 | the version that will be initialized by crossdev and selected. |
| 424 | |
| 425 | If the version is PACKAGE_STABLE, it really means the current version which |
| 426 | is emerged by using the package atom with no particular version key. |
| 427 | Since crossdev unmasks all packages by default, this will actually |
| 428 | mean 'unstable' in most cases. |
| 429 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 430 | Args: |
Mike Frysinger | d96d544 | 2021-11-09 05:12:34 -0500 | [diff] [blame] | 431 | target: The target to operate on (e.g. i686-cros-linux-gnu) |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 432 | package: The target/package to operate on (e.g. gcc) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 433 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 434 | Returns: |
| 435 | A list composed of either a version string, PACKAGE_STABLE |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 436 | """ |
Mike Frysinger | d23be27 | 2017-09-12 17:18:44 -0400 | [diff] [blame] | 437 | if package in GetTargetPackages(target): |
| 438 | return [PACKAGE_STABLE] |
| 439 | else: |
| 440 | return [] |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 441 | |
| 442 | |
| 443 | def TargetIsInitialized(target): |
| 444 | """Verifies if the given list of targets has been correctly initialized. |
| 445 | |
| 446 | This determines whether we have to call crossdev while emerging |
| 447 | toolchain packages or can do it using emerge. Emerge is naturally |
| 448 | preferred, because all packages can be updated in a single pass. |
| 449 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 450 | Args: |
Mike Frysinger | d96d544 | 2021-11-09 05:12:34 -0500 | [diff] [blame] | 451 | target: The target to operate on (e.g. i686-cros-linux-gnu) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 452 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 453 | Returns: |
| 454 | True if |target| is completely initialized, else False |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 455 | """ |
| 456 | # Check if packages for the given target all have a proper version. |
| 457 | try: |
Zdenek Behan | f4d18a0 | 2012-03-22 15:45:05 +0100 | [diff] [blame] | 458 | for package in GetTargetPackages(target): |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 459 | atom = GetPortagePackage(target, package) |
Zdenek Behan | 4eb6fd2 | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 460 | # Do we even want this package && is it initialized? |
Mike Frysinger | 7f0e198 | 2017-09-12 17:08:50 -0400 | [diff] [blame] | 461 | if not (GetStablePackageVersion(atom, True) and |
| 462 | GetStablePackageVersion(atom, False)): |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 463 | return False |
| 464 | return True |
| 465 | except cros_build_lib.RunCommandError: |
| 466 | # Fails - The target has likely never been initialized before. |
| 467 | return False |
| 468 | |
| 469 | |
| 470 | def RemovePackageMask(target): |
| 471 | """Removes a package.mask file for the given platform. |
| 472 | |
| 473 | The pre-existing package.mask files can mess with the keywords. |
| 474 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 475 | Args: |
Mike Frysinger | d96d544 | 2021-11-09 05:12:34 -0500 | [diff] [blame] | 476 | target: The target to operate on (e.g. i686-cros-linux-gnu) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 477 | """ |
| 478 | maskfile = os.path.join('/etc/portage/package.mask', 'cross-' + target) |
Brian Harring | af019fb | 2012-05-10 15:06:13 -0700 | [diff] [blame] | 479 | osutils.SafeUnlink(maskfile) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 480 | |
| 481 | |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 482 | # Main functions performing the actual update steps. |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 483 | def RebuildLibtool(root='/'): |
Mike Frysinger | c880a96 | 2013-11-08 13:59:06 -0500 | [diff] [blame] | 484 | """Rebuild libtool as needed |
| 485 | |
| 486 | Libtool hardcodes full paths to internal gcc files, so whenever we upgrade |
| 487 | gcc, libtool will break. We can't use binary packages either as those will |
| 488 | most likely be compiled against the previous version of gcc. |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 489 | |
| 490 | Args: |
| 491 | root: The install root where we want libtool rebuilt. |
Mike Frysinger | c880a96 | 2013-11-08 13:59:06 -0500 | [diff] [blame] | 492 | """ |
| 493 | needs_update = False |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 494 | with open(os.path.join(root, 'usr/bin/libtool')) as f: |
Mike Frysinger | c880a96 | 2013-11-08 13:59:06 -0500 | [diff] [blame] | 495 | for line in f: |
| 496 | # Look for a line like: |
| 497 | # sys_lib_search_path_spec="..." |
| 498 | # It'll be a list of paths and gcc will be one of them. |
| 499 | if line.startswith('sys_lib_search_path_spec='): |
| 500 | line = line.rstrip() |
| 501 | for path in line.split('=', 1)[1].strip('"').split(): |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 502 | root_path = os.path.join(root, path.lstrip(os.path.sep)) |
| 503 | logging.debug('Libtool: checking %s', root_path) |
| 504 | if not os.path.exists(root_path): |
| 505 | logging.info('Rebuilding libtool after gcc upgrade') |
| 506 | logging.info(' %s', line) |
| 507 | logging.info(' missing path: %s', path) |
Mike Frysinger | c880a96 | 2013-11-08 13:59:06 -0500 | [diff] [blame] | 508 | needs_update = True |
| 509 | break |
| 510 | |
| 511 | if needs_update: |
| 512 | break |
| 513 | |
| 514 | if needs_update: |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 515 | cmd = [EMERGE_CMD, '--oneshot'] |
| 516 | if root != '/': |
| 517 | cmd.extend(['--sysroot=%s' % root, '--root=%s' % root]) |
| 518 | cmd.append('sys-devel/libtool') |
Mike Frysinger | 45602c7 | 2019-09-22 02:15:11 -0400 | [diff] [blame] | 519 | cros_build_lib.run(cmd) |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 520 | else: |
| 521 | logging.debug('Libtool is up-to-date; no need to rebuild') |
Mike Frysinger | c880a96 | 2013-11-08 13:59:06 -0500 | [diff] [blame] | 522 | |
| 523 | |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 524 | def UpdateTargets(targets, usepkg, root='/'): |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 525 | """Determines which packages need update/unmerge and defers to portage. |
| 526 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 527 | Args: |
| 528 | targets: The list of targets to update |
| 529 | usepkg: Copies the commandline option |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 530 | root: The install root in which we want packages updated. |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 531 | """ |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 532 | # For each target, we do two things. Figure out the list of updates, |
| 533 | # and figure out the appropriate keywords/masks. Crossdev will initialize |
| 534 | # these, but they need to be regenerated on every update. |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 535 | logging.info('Determining required toolchain updates...') |
David James | 90239b9 | 2012-11-05 15:31:34 -0800 | [diff] [blame] | 536 | mergemap = {} |
ChromeOS Developer | eb8a5c4 | 2021-01-12 00:05:02 +0000 | [diff] [blame] | 537 | # Used to keep track of post-cross packages. These are allowed to have |
| 538 | # implicit dependencies on toolchain packages, and therefore need to |
| 539 | # be built last. |
| 540 | post_cross_pkgs = set() |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 541 | for target in targets: |
ChromeOS Developer | eb8a5c4 | 2021-01-12 00:05:02 +0000 | [diff] [blame] | 542 | is_post_cross_target = target.endswith('-post-cross') |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 543 | logging.debug('Updating target %s', target) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 544 | # Record the highest needed version for each target, for masking purposes. |
| 545 | RemovePackageMask(target) |
Zdenek Behan | f4d18a0 | 2012-03-22 15:45:05 +0100 | [diff] [blame] | 546 | for package in GetTargetPackages(target): |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 547 | # Portage name for the package |
Mike Frysinger | 7f0e198 | 2017-09-12 17:08:50 -0400 | [diff] [blame] | 548 | logging.debug(' Checking package %s', package) |
Zdenek Behan | 4eb6fd2 | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 549 | pkg = GetPortagePackage(target, package) |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 550 | current = GetInstalledPackageVersions(pkg, root=root) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 551 | desired = GetDesiredPackageVersions(target, package) |
Zdenek Behan | 699ddd3 | 2012-04-13 07:14:08 +0200 | [diff] [blame] | 552 | desired_num = VersionListToNumeric(target, package, desired, False) |
Mike Frysinger | 785b0c3 | 2017-09-13 01:35:59 -0400 | [diff] [blame] | 553 | if pkg in NEW_PACKAGES and usepkg: |
| 554 | # Skip this binary package (for now). |
| 555 | continue |
Zdenek Behan | 4eb6fd2 | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 556 | mergemap[pkg] = set(desired_num).difference(current) |
Mike Frysinger | 7f0e198 | 2017-09-12 17:08:50 -0400 | [diff] [blame] | 557 | logging.debug(' %s -> %s', current, desired_num) |
ChromeOS Developer | eb8a5c4 | 2021-01-12 00:05:02 +0000 | [diff] [blame] | 558 | if is_post_cross_target: |
| 559 | post_cross_pkgs.add(pkg) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 560 | |
Mike Frysinger | 7f0e198 | 2017-09-12 17:08:50 -0400 | [diff] [blame] | 561 | packages = [pkg for pkg, vers in mergemap.items() if vers] |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 562 | if not packages: |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 563 | logging.info('Nothing to update!') |
David James | f8c672f | 2012-11-06 13:38:11 -0800 | [diff] [blame] | 564 | return False |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 565 | |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 566 | logging.info('Updating packages:') |
| 567 | logging.info('%s', packages) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 568 | |
Zdenek Behan | 7e33b4e | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 569 | cmd = [EMERGE_CMD, '--oneshot', '--update'] |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 570 | if usepkg: |
| 571 | cmd.extend(['--getbinpkg', '--usepkgonly']) |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 572 | if root != '/': |
| 573 | cmd.extend(['--sysroot=%s' % root, '--root=%s' % root]) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 574 | |
ChromeOS Developer | eb8a5c4 | 2021-01-12 00:05:02 +0000 | [diff] [blame] | 575 | if usepkg: |
| 576 | # Since we are not building from source, we can handle |
| 577 | # all packages in one go. |
| 578 | cmd.extend(packages) |
| 579 | cros_build_lib.run(cmd) |
| 580 | else: |
George Burgess IV | d7762ab | 2021-04-29 10:54:55 -0700 | [diff] [blame] | 581 | pre_cross_items = [pkg for pkg in packages if pkg not in post_cross_pkgs] |
| 582 | if pre_cross_items: |
| 583 | cros_build_lib.run(cmd + pre_cross_items) |
ChromeOS Developer | eb8a5c4 | 2021-01-12 00:05:02 +0000 | [diff] [blame] | 584 | post_cross_items = [pkg for pkg in packages if pkg in post_cross_pkgs] |
George Burgess IV | d7762ab | 2021-04-29 10:54:55 -0700 | [diff] [blame] | 585 | if post_cross_items: |
| 586 | cros_build_lib.run(cmd + post_cross_items) |
David James | f8c672f | 2012-11-06 13:38:11 -0800 | [diff] [blame] | 587 | return True |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 588 | |
| 589 | |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 590 | def CleanTargets(targets, root='/'): |
| 591 | """Unmerges old packages that are assumed unnecessary. |
| 592 | |
| 593 | Args: |
| 594 | targets: The list of targets to clean up. |
| 595 | root: The install root in which we want packages cleaned up. |
| 596 | """ |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 597 | unmergemap = {} |
| 598 | for target in targets: |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 599 | logging.debug('Cleaning target %s', target) |
Zdenek Behan | f4d18a0 | 2012-03-22 15:45:05 +0100 | [diff] [blame] | 600 | for package in GetTargetPackages(target): |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 601 | logging.debug(' Cleaning package %s', package) |
Zdenek Behan | 4eb6fd2 | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 602 | pkg = GetPortagePackage(target, package) |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 603 | current = GetInstalledPackageVersions(pkg, root=root) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 604 | desired = GetDesiredPackageVersions(target, package) |
Gilad Arnold | 2fcb0aa | 2015-05-21 14:51:41 -0700 | [diff] [blame] | 605 | # NOTE: This refers to installed packages (vartree) rather than the |
| 606 | # Portage version (porttree and/or bintree) when determining the current |
| 607 | # version. While this isn't the most accurate thing to do, it is probably |
| 608 | # a good simple compromise, which should have the desired result of |
| 609 | # uninstalling everything but the latest installed version. In |
| 610 | # particular, using the bintree (--usebinpkg) requires a non-trivial |
| 611 | # binhost sync and is probably more complex than useful. |
Zdenek Behan | 699ddd3 | 2012-04-13 07:14:08 +0200 | [diff] [blame] | 612 | desired_num = VersionListToNumeric(target, package, desired, True) |
| 613 | if not set(desired_num).issubset(current): |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 614 | logging.warning('Error detecting stable version for %s, ' |
| 615 | 'skipping clean!', pkg) |
Zdenek Behan | 699ddd3 | 2012-04-13 07:14:08 +0200 | [diff] [blame] | 616 | return |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 617 | unmergemap[pkg] = set(current).difference(desired_num) |
| 618 | |
| 619 | # Cleaning doesn't care about consistency and rebuilding package.* files. |
| 620 | packages = [] |
Mike Frysinger | 0bdbc10 | 2019-06-13 15:27:29 -0400 | [diff] [blame] | 621 | for pkg, vers in unmergemap.items(): |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 622 | packages.extend('=%s-%s' % (pkg, ver) for ver in vers if ver != '9999') |
| 623 | |
| 624 | if packages: |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 625 | logging.info('Cleaning packages:') |
| 626 | logging.info('%s', packages) |
Zdenek Behan | 7e33b4e | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 627 | cmd = [EMERGE_CMD, '--unmerge'] |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 628 | if root != '/': |
| 629 | cmd.extend(['--sysroot=%s' % root, '--root=%s' % root]) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 630 | cmd.extend(packages) |
Mike Frysinger | 45602c7 | 2019-09-22 02:15:11 -0400 | [diff] [blame] | 631 | cros_build_lib.run(cmd) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 632 | else: |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 633 | logging.info('Nothing to clean!') |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 634 | |
| 635 | |
Adrian Ratiu | 78e534d | 2021-01-06 19:58:38 +0200 | [diff] [blame] | 636 | def SelectActiveToolchains(targets, root='/'): |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 637 | """Runs gcc-config and binutils-config to select the desired. |
| 638 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 639 | Args: |
| 640 | targets: The targets to select |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 641 | root: The root where we want to select toolchain versions. |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 642 | """ |
| 643 | for package in ['gcc', 'binutils']: |
| 644 | for target in targets: |
Mike Frysinger | 785b0c3 | 2017-09-13 01:35:59 -0400 | [diff] [blame] | 645 | # See if this package is part of this target. |
| 646 | if package not in GetTargetPackages(target): |
| 647 | logging.debug('%s: %s is not used', target, package) |
| 648 | continue |
| 649 | |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 650 | # Pick the first version in the numbered list as the selected one. |
| 651 | desired = GetDesiredPackageVersions(target, package) |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 652 | desired_num = VersionListToNumeric(target, package, desired, True, |
| 653 | root=root) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 654 | desired = desired_num[0] |
| 655 | # *-config does not play revisions, strip them, keep just PV. |
| 656 | desired = portage.versions.pkgsplit('%s-%s' % (package, desired))[1] |
| 657 | |
Mike Frysinger | 785b0c3 | 2017-09-13 01:35:59 -0400 | [diff] [blame] | 658 | if target.startswith('host'): |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 659 | # *-config is the only tool treating host identically (by tuple). |
David James | 27ac4ae | 2012-12-03 23:16:15 -0800 | [diff] [blame] | 660 | target = toolchain.GetHostTuple() |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 661 | |
| 662 | # And finally, attach target to it. |
| 663 | desired = '%s-%s' % (target, desired) |
| 664 | |
David James | 7ec5efc | 2012-11-06 09:39:49 -0800 | [diff] [blame] | 665 | extra_env = {'CHOST': target} |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 666 | if root != '/': |
| 667 | extra_env['ROOT'] = root |
David James | 7ec5efc | 2012-11-06 09:39:49 -0800 | [diff] [blame] | 668 | cmd = ['%s-config' % package, '-c', target] |
Mike Frysinger | 45602c7 | 2019-09-22 02:15:11 -0400 | [diff] [blame] | 669 | result = cros_build_lib.run( |
Mike Frysinger | 0282d22 | 2019-12-17 17:15:48 -0500 | [diff] [blame] | 670 | cmd, print_cmd=False, stdout=True, encoding='utf-8', |
Mike Frysinger | b3202be | 2019-11-15 22:25:59 -0500 | [diff] [blame] | 671 | extra_env=extra_env) |
Mike Frysinger | d6e2df0 | 2014-11-26 02:55:04 -0500 | [diff] [blame] | 672 | current = result.output.splitlines()[0] |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 673 | |
| 674 | # Do not reconfig when the current is live or nothing needs to be done. |
| 675 | extra_env = {'ROOT': root} if root != '/' else None |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 676 | if current != desired and current != '9999': |
Mike Frysinger | d6e2df0 | 2014-11-26 02:55:04 -0500 | [diff] [blame] | 677 | cmd = [package + '-config', desired] |
Mike Frysinger | 45602c7 | 2019-09-22 02:15:11 -0400 | [diff] [blame] | 678 | cros_build_lib.run(cmd, print_cmd=False, extra_env=extra_env) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 679 | |
| 680 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 681 | def ExpandTargets(targets_wanted): |
| 682 | """Expand any possible toolchain aliases into full targets |
| 683 | |
| 684 | This will expand 'all' and 'sdk' into the respective toolchain tuples. |
| 685 | |
| 686 | Args: |
| 687 | targets_wanted: The targets specified by the user. |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 688 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 689 | Returns: |
Gilad Arnold | 8195b53 | 2015-04-07 10:56:30 +0300 | [diff] [blame] | 690 | Dictionary of concrete targets and their toolchain tuples. |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 691 | """ |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 692 | targets_wanted = set(targets_wanted) |
Don Garrett | c0c7400 | 2015-10-09 12:58:19 -0700 | [diff] [blame] | 693 | if targets_wanted == set(['boards']): |
| 694 | # Only pull targets from the included boards. |
Gilad Arnold | 8195b53 | 2015-04-07 10:56:30 +0300 | [diff] [blame] | 695 | return {} |
| 696 | |
| 697 | all_targets = toolchain.GetAllTargets() |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 698 | if targets_wanted == set(['all']): |
Gilad Arnold | 8195b53 | 2015-04-07 10:56:30 +0300 | [diff] [blame] | 699 | return all_targets |
| 700 | if targets_wanted == set(['sdk']): |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 701 | # Filter out all the non-sdk toolchains as we don't want to mess |
| 702 | # with those in all of our builds. |
Gilad Arnold | 8195b53 | 2015-04-07 10:56:30 +0300 | [diff] [blame] | 703 | return toolchain.FilterToolchains(all_targets, 'sdk', True) |
| 704 | |
| 705 | # Verify user input. |
| 706 | nonexistent = targets_wanted.difference(all_targets) |
| 707 | if nonexistent: |
Mike Frysinger | cd79066 | 2019-10-17 00:23:13 -0400 | [diff] [blame] | 708 | raise ValueError('Invalid targets: %s' % (','.join(nonexistent),)) |
Gilad Arnold | 8195b53 | 2015-04-07 10:56:30 +0300 | [diff] [blame] | 709 | return {t: all_targets[t] for t in targets_wanted} |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 710 | |
| 711 | |
David James | f8c672f | 2012-11-06 13:38:11 -0800 | [diff] [blame] | 712 | def UpdateToolchains(usepkg, deleteold, hostonly, reconfig, |
Don Garrett | c0c7400 | 2015-10-09 12:58:19 -0700 | [diff] [blame] | 713 | targets_wanted, boards_wanted, root='/'): |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 714 | """Performs all steps to create a synchronized toolchain enviroment. |
| 715 | |
Mike Frysinger | dc649ae | 2014-11-26 19:29:24 -0500 | [diff] [blame] | 716 | Args: |
| 717 | usepkg: Use prebuilt packages |
| 718 | deleteold: Unmerge deprecated packages |
| 719 | hostonly: Only setup the host toolchain |
| 720 | reconfig: Reload crossdev config and reselect toolchains |
| 721 | targets_wanted: All the targets to update |
| 722 | boards_wanted: Load targets from these boards |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 723 | root: The root in which to install the toolchains. |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 724 | """ |
David James | f8c672f | 2012-11-06 13:38:11 -0800 | [diff] [blame] | 725 | targets, crossdev_targets, reconfig_targets = {}, {}, {} |
Zdenek Behan | 7e33b4e | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 726 | if not hostonly: |
| 727 | # For hostonly, we can skip most of the below logic, much of which won't |
| 728 | # work on bare systems where this is useful. |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 729 | targets = ExpandTargets(targets_wanted) |
Mike Frysinger | 7ccee99 | 2012-06-01 21:27:59 -0400 | [diff] [blame] | 730 | |
Mike Frysinger | d246fb9 | 2021-10-26 16:08:39 -0400 | [diff] [blame] | 731 | # Filter out toolchains that don't (yet) have a binpkg available. |
| 732 | if usepkg: |
| 733 | for target in list(targets.keys()): |
| 734 | if not targets[target]['have-binpkg']: |
| 735 | del targets[target] |
| 736 | |
Don Garrett | c0c7400 | 2015-10-09 12:58:19 -0700 | [diff] [blame] | 737 | # Now re-add any targets that might be from this board. This is to |
Gilad Arnold | 8195b53 | 2015-04-07 10:56:30 +0300 | [diff] [blame] | 738 | # allow unofficial boards to declare their own toolchains. |
Mike Frysinger | 7ccee99 | 2012-06-01 21:27:59 -0400 | [diff] [blame] | 739 | for board in boards_wanted: |
David James | 27ac4ae | 2012-12-03 23:16:15 -0800 | [diff] [blame] | 740 | targets.update(toolchain.GetToolchainsForBoard(board)) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 741 | |
Zdenek Behan | 7e33b4e | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 742 | # First check and initialize all cross targets that need to be. |
Mike Frysinger | 7ccee99 | 2012-06-01 21:27:59 -0400 | [diff] [blame] | 743 | for target in targets: |
| 744 | if TargetIsInitialized(target): |
| 745 | reconfig_targets[target] = targets[target] |
| 746 | else: |
| 747 | crossdev_targets[target] = targets[target] |
Zdenek Behan | 7e33b4e | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 748 | if crossdev_targets: |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 749 | logging.info('The following targets need to be re-initialized:') |
| 750 | logging.info('%s', crossdev_targets) |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 751 | Crossdev.UpdateTargets(crossdev_targets, usepkg) |
Zdenek Behan | 8be29ba | 2012-05-29 23:10:34 +0200 | [diff] [blame] | 752 | # Those that were not initialized may need a config update. |
David James | 66a09c4 | 2012-11-05 13:31:38 -0800 | [diff] [blame] | 753 | Crossdev.UpdateTargets(reconfig_targets, usepkg, config_only=True) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 754 | |
Mike Frysinger | 66814c3 | 2017-10-09 18:11:46 -0400 | [diff] [blame] | 755 | # If we're building a subset of toolchains for a board, we might not have |
| 756 | # all the tuples that the packages expect. We don't define the "full" set |
| 757 | # of tuples currently other than "whatever the full sdk has normally". |
| 758 | if usepkg or set(('all', 'sdk')) & targets_wanted: |
| 759 | # Since we have cross-compilers now, we can update these packages. |
| 760 | targets['host-post-cross'] = {} |
Mike Frysinger | 785b0c3 | 2017-09-13 01:35:59 -0400 | [diff] [blame] | 761 | |
Zdenek Behan | 7e33b4e | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 762 | # We want host updated. |
Mike Frysinger | 7ccee99 | 2012-06-01 21:27:59 -0400 | [diff] [blame] | 763 | targets['host'] = {} |
Zdenek Behan | 7e33b4e | 2012-03-12 17:00:56 +0100 | [diff] [blame] | 764 | |
| 765 | # Now update all packages. |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 766 | if UpdateTargets(targets, usepkg, root=root) or crossdev_targets or reconfig: |
Adrian Ratiu | 78e534d | 2021-01-06 19:58:38 +0200 | [diff] [blame] | 767 | SelectActiveToolchains(targets, root=root) |
David James | 7ec5efc | 2012-11-06 09:39:49 -0800 | [diff] [blame] | 768 | |
| 769 | if deleteold: |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 770 | CleanTargets(targets, root=root) |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 771 | |
Mike Frysinger | c880a96 | 2013-11-08 13:59:06 -0500 | [diff] [blame] | 772 | # Now that we've cleared out old versions, see if we need to rebuild |
| 773 | # anything. Can't do this earlier as it might not be broken. |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 774 | RebuildLibtool(root=root) |
Mike Frysinger | c880a96 | 2013-11-08 13:59:06 -0500 | [diff] [blame] | 775 | |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 776 | |
Bertrand SIMONNET | cae9d5f | 2015-03-09 15:58:01 -0700 | [diff] [blame] | 777 | def ShowConfig(name): |
| 778 | """Show the toolchain tuples used by |name| |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 779 | |
| 780 | Args: |
Don Garrett | c0c7400 | 2015-10-09 12:58:19 -0700 | [diff] [blame] | 781 | name: The board name to query. |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 782 | """ |
Don Garrett | c0c7400 | 2015-10-09 12:58:19 -0700 | [diff] [blame] | 783 | toolchains = toolchain.GetToolchainsForBoard(name) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 784 | # Make sure we display the default toolchain first. |
Mike Frysinger | 3bba503 | 2016-09-20 14:15:04 -0400 | [diff] [blame] | 785 | # Note: Do not use logging here as this is meant to be used by other tools. |
Mike Frysinger | 383367e | 2014-09-16 15:06:17 -0400 | [diff] [blame] | 786 | print(','.join( |
Mike Frysinger | 818d963 | 2019-08-24 14:43:05 -0400 | [diff] [blame] | 787 | list(toolchain.FilterToolchains(toolchains, 'default', True)) + |
| 788 | list(toolchain.FilterToolchains(toolchains, 'default', False)))) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 789 | |
| 790 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 791 | def GeneratePathWrapper(root, wrappath, path): |
| 792 | """Generate a shell script to execute another shell script |
| 793 | |
| 794 | Since we can't symlink a wrapped ELF (see GenerateLdsoWrapper) because the |
| 795 | argv[0] won't be pointing to the correct path, generate a shell script that |
| 796 | just executes another program with its full path. |
| 797 | |
| 798 | Args: |
| 799 | root: The root tree to generate scripts inside of |
| 800 | wrappath: The full path (inside |root|) to create the wrapper |
| 801 | path: The target program which this wrapper will execute |
| 802 | """ |
| 803 | replacements = { |
| 804 | 'path': path, |
| 805 | 'relroot': os.path.relpath('/', os.path.dirname(wrappath)), |
| 806 | } |
Takuto Ikuta | 5840397 | 2018-08-16 18:52:51 +0900 | [diff] [blame] | 807 | |
| 808 | # Do not use exec here, because exec invokes script with absolute path in |
| 809 | # argv0. Keeping relativeness allows us to remove abs path from compile result |
| 810 | # and leads directory independent build cache sharing in some distributed |
| 811 | # build system. |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 812 | wrapper = """#!/bin/sh |
Takuto Ikuta | 5840397 | 2018-08-16 18:52:51 +0900 | [diff] [blame] | 813 | basedir=$(dirname "$0") |
| 814 | "${basedir}/%(relroot)s%(path)s" "$@" |
| 815 | exit "$?" |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 816 | """ % replacements |
| 817 | root_wrapper = root + wrappath |
| 818 | if os.path.islink(root_wrapper): |
| 819 | os.unlink(root_wrapper) |
| 820 | else: |
| 821 | osutils.SafeMakedirs(os.path.dirname(root_wrapper)) |
| 822 | osutils.WriteFile(root_wrapper, wrapper) |
Mike Frysinger | 60ec101 | 2013-10-21 00:11:10 -0400 | [diff] [blame] | 823 | os.chmod(root_wrapper, 0o755) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 824 | |
| 825 | |
Rahul Chaudhry | a8127bb | 2016-07-22 15:53:17 -0700 | [diff] [blame] | 826 | def FixClangXXWrapper(root, path): |
| 827 | """Fix wrapper shell scripts and symlinks for invoking clang++ |
| 828 | |
| 829 | In a typical installation, clang++ symlinks to clang, which symlinks to the |
| 830 | elf executable. The executable distinguishes between clang and clang++ based |
| 831 | on argv[0]. |
| 832 | |
| 833 | When invoked through the LdsoWrapper, argv[0] always contains the path to the |
| 834 | executable elf file, making clang/clang++ invocations indistinguishable. |
| 835 | |
| 836 | This function detects if the elf executable being wrapped is clang-X.Y, and |
| 837 | fixes wrappers/symlinks as necessary so that clang++ will work correctly. |
| 838 | |
| 839 | The calling sequence now becomes: |
| 840 | -) clang++ invocation turns into clang++-3.9 (which is a copy of clang-3.9, |
| 841 | the Ldsowrapper). |
| 842 | -) clang++-3.9 uses the Ldso to invoke clang++-3.9.elf, which is a symlink |
| 843 | to the original clang-3.9 elf. |
| 844 | -) The difference this time is that inside the elf file execution, $0 is |
| 845 | set as .../usr/bin/clang++-3.9.elf, which contains 'clang++' in the name. |
| 846 | |
Manoj Gupta | ae26814 | 2018-04-27 23:28:36 -0700 | [diff] [blame] | 847 | Update: Starting since clang 7, the clang and clang++ are symlinks to |
| 848 | clang-7 binary, not clang-7.0. The pattern match is extended to handle |
| 849 | both clang-7 and clang-7.0 cases for now. (https://crbug.com/837889) |
| 850 | |
Rahul Chaudhry | a8127bb | 2016-07-22 15:53:17 -0700 | [diff] [blame] | 851 | Args: |
| 852 | root: The root tree to generate scripts / symlinks inside of |
| 853 | path: The target elf for which LdsoWrapper was created |
| 854 | """ |
Manoj Gupta | ae26814 | 2018-04-27 23:28:36 -0700 | [diff] [blame] | 855 | if re.match(r'/usr/bin/clang-\d+(\.\d+)*$', path): |
Rahul Chaudhry | a8127bb | 2016-07-22 15:53:17 -0700 | [diff] [blame] | 856 | logging.info('fixing clang++ invocation for %s', path) |
| 857 | clangdir = os.path.dirname(root + path) |
| 858 | clang = os.path.basename(path) |
| 859 | clangxx = clang.replace('clang', 'clang++') |
| 860 | |
| 861 | # Create a symlink clang++-X.Y.elf to point to clang-X.Y.elf |
| 862 | os.symlink(clang + '.elf', os.path.join(clangdir, clangxx + '.elf')) |
| 863 | |
| 864 | # Create a hardlink clang++-X.Y pointing to clang-X.Y |
| 865 | os.link(os.path.join(clangdir, clang), os.path.join(clangdir, clangxx)) |
| 866 | |
| 867 | # Adjust the clang++ symlink to point to clang++-X.Y |
| 868 | os.unlink(os.path.join(clangdir, 'clang++')) |
| 869 | os.symlink(clangxx, os.path.join(clangdir, 'clang++')) |
| 870 | |
| 871 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 872 | def FileIsCrosSdkElf(elf): |
| 873 | """Determine if |elf| is an ELF that we execute in the cros_sdk |
| 874 | |
| 875 | We don't need this to be perfect, just quick. It makes sure the ELF |
| 876 | is a 64bit LSB x86_64 ELF. That is the native type of cros_sdk. |
| 877 | |
| 878 | Args: |
| 879 | elf: The file to check |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 880 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 881 | Returns: |
| 882 | True if we think |elf| is a native ELF |
| 883 | """ |
Mike Frysinger | 4a12bf1 | 2019-12-04 04:20:10 -0500 | [diff] [blame] | 884 | with open(elf, 'rb') as f: |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 885 | data = f.read(20) |
| 886 | # Check the magic number, EI_CLASS, EI_DATA, and e_machine. |
Mike Frysinger | 4a12bf1 | 2019-12-04 04:20:10 -0500 | [diff] [blame] | 887 | return (data[0:4] == b'\x7fELF' and |
Mike Frysinger | dd34dfe | 2019-12-10 16:25:47 -0500 | [diff] [blame] | 888 | data[4:5] == b'\x02' and |
| 889 | data[5:6] == b'\x01' and |
| 890 | data[18:19] == b'\x3e') |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 891 | |
| 892 | |
| 893 | def IsPathPackagable(ptype, path): |
| 894 | """Should the specified file be included in a toolchain package? |
| 895 | |
| 896 | We only need to handle files as we'll create dirs as we need them. |
| 897 | |
| 898 | Further, trim files that won't be useful: |
| 899 | - non-english translations (.mo) since it'd require env vars |
| 900 | - debug files since these are for the host compiler itself |
| 901 | - info/man pages as they're big, and docs are online, and the |
| 902 | native docs should work fine for the most part (`man gcc`) |
| 903 | |
| 904 | Args: |
| 905 | ptype: A string describing the path type (i.e. 'file' or 'dir' or 'sym') |
| 906 | path: The full path to inspect |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 907 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 908 | Returns: |
| 909 | True if we want to include this path in the package |
| 910 | """ |
| 911 | return not (ptype in ('dir',) or |
| 912 | path.startswith('/usr/lib/debug/') or |
| 913 | os.path.splitext(path)[1] == '.mo' or |
| 914 | ('/man/' in path or '/info/' in path)) |
| 915 | |
| 916 | |
| 917 | def ReadlinkRoot(path, root): |
| 918 | """Like os.readlink(), but relative to a |root| |
| 919 | |
| 920 | Args: |
| 921 | path: The symlink to read |
| 922 | root: The path to use for resolving absolute symlinks |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 923 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 924 | Returns: |
| 925 | A fully resolved symlink path |
| 926 | """ |
| 927 | while os.path.islink(root + path): |
| 928 | path = os.path.join(os.path.dirname(path), os.readlink(root + path)) |
| 929 | return path |
| 930 | |
| 931 | |
| 932 | def _GetFilesForTarget(target, root='/'): |
| 933 | """Locate all the files to package for |target| |
| 934 | |
| 935 | This does not cover ELF dependencies. |
| 936 | |
| 937 | Args: |
| 938 | target: The toolchain target name |
| 939 | root: The root path to pull all packages from |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 940 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 941 | Returns: |
| 942 | A tuple of a set of all packable paths, and a set of all paths which |
| 943 | are also native ELFs |
| 944 | """ |
| 945 | paths = set() |
| 946 | elfs = set() |
| 947 | |
| 948 | # Find all the files owned by the packages for this target. |
| 949 | for pkg in GetTargetPackages(target): |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 950 | |
Rahul Chaudhry | 4b80305 | 2015-05-13 15:25:56 -0700 | [diff] [blame] | 951 | # Skip Go compiler from redistributable packages. |
| 952 | # The "go" executable has GOROOT=/usr/lib/go/${CTARGET} hardcoded |
| 953 | # into it. Due to this, the toolchain cannot be unpacked anywhere |
| 954 | # else and be readily useful. To enable packaging Go, we need to: |
| 955 | # -) Tweak the wrappers/environment to override GOROOT |
| 956 | # automatically based on the unpack location. |
| 957 | # -) Make sure the ELF dependency checking and wrapping logic |
| 958 | # below skips the Go toolchain executables and libraries. |
| 959 | # -) Make sure the packaging process maintains the relative |
| 960 | # timestamps of precompiled standard library packages. |
| 961 | # (see dev-lang/go ebuild for details). |
| 962 | if pkg == 'ex_go': |
| 963 | continue |
| 964 | |
Yunlian Jiang | 36f3524 | 2018-04-27 10:18:40 -0700 | [diff] [blame] | 965 | # Use armv7a-cros-linux-gnueabi/compiler-rt for |
| 966 | # armv7a-cros-linux-gnueabihf/compiler-rt. |
| 967 | # Currently the armv7a-cros-linux-gnueabi is actually |
| 968 | # the same as armv7a-cros-linux-gnueabihf with different names. |
| 969 | # Because of that, for compiler-rt, it generates the same binary in |
| 970 | # the same location. To avoid the installation conflict, we do not |
| 971 | # install anything for 'armv7a-cros-linux-gnueabihf'. This would cause |
| 972 | # problem if other people try to use standalone armv7a-cros-linux-gnueabihf |
| 973 | # toolchain. |
| 974 | if 'compiler-rt' in pkg and 'armv7a-cros-linux-gnueabi' in target: |
| 975 | atom = GetPortagePackage(target, pkg) |
| 976 | cat, pn = atom.split('/') |
| 977 | ver = GetInstalledPackageVersions(atom, root=root)[0] |
Yunlian Jiang | 36f3524 | 2018-04-27 10:18:40 -0700 | [diff] [blame] | 978 | dblink = portage.dblink(cat, pn + '-' + ver, myroot=root, |
| 979 | settings=portage.settings) |
| 980 | contents = dblink.getcontents() |
| 981 | if not contents: |
| 982 | if 'hf' in target: |
| 983 | new_target = 'armv7a-cros-linux-gnueabi' |
| 984 | else: |
| 985 | new_target = 'armv7a-cros-linux-gnueabihf' |
| 986 | atom = GetPortagePackage(new_target, pkg) |
| 987 | else: |
| 988 | atom = GetPortagePackage(target, pkg) |
| 989 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 990 | cat, pn = atom.split('/') |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 991 | ver = GetInstalledPackageVersions(atom, root=root)[0] |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 992 | logging.info('packaging %s-%s', atom, ver) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 993 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 994 | dblink = portage.dblink(cat, pn + '-' + ver, myroot=root, |
| 995 | settings=portage.settings) |
| 996 | contents = dblink.getcontents() |
| 997 | for obj in contents: |
| 998 | ptype = contents[obj][0] |
| 999 | if not IsPathPackagable(ptype, obj): |
| 1000 | continue |
| 1001 | |
| 1002 | if ptype == 'obj': |
| 1003 | # For native ELFs, we need to pull in their dependencies too. |
| 1004 | if FileIsCrosSdkElf(obj): |
Mike Frysinger | 60a2f6c | 2019-12-04 04:18:58 -0500 | [diff] [blame] | 1005 | logging.debug('Adding ELF %s', obj) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1006 | elfs.add(obj) |
Mike Frysinger | 60a2f6c | 2019-12-04 04:18:58 -0500 | [diff] [blame] | 1007 | logging.debug('Adding path %s', obj) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1008 | paths.add(obj) |
| 1009 | |
| 1010 | return paths, elfs |
| 1011 | |
| 1012 | |
| 1013 | def _BuildInitialPackageRoot(output_dir, paths, elfs, ldpaths, |
Mike Frysinger | d6e2df0 | 2014-11-26 02:55:04 -0500 | [diff] [blame] | 1014 | path_rewrite_func=lambda x: x, root='/'): |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1015 | """Link in all packable files and their runtime dependencies |
| 1016 | |
| 1017 | This also wraps up executable ELFs with helper scripts. |
| 1018 | |
| 1019 | Args: |
| 1020 | output_dir: The output directory to store files |
| 1021 | paths: All the files to include |
| 1022 | elfs: All the files which are ELFs (a subset of |paths|) |
| 1023 | ldpaths: A dict of static ldpath information |
| 1024 | path_rewrite_func: User callback to rewrite paths in output_dir |
| 1025 | root: The root path to pull all packages/files from |
| 1026 | """ |
| 1027 | # Link in all the files. |
Mike Frysinger | 221bd82 | 2017-09-29 02:51:47 -0400 | [diff] [blame] | 1028 | sym_paths = {} |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1029 | for path in paths: |
| 1030 | new_path = path_rewrite_func(path) |
Mike Frysinger | 60a2f6c | 2019-12-04 04:18:58 -0500 | [diff] [blame] | 1031 | logging.debug('Transformed %s to %s', path, new_path) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1032 | dst = output_dir + new_path |
| 1033 | osutils.SafeMakedirs(os.path.dirname(dst)) |
| 1034 | |
| 1035 | # Is this a symlink which we have to rewrite or wrap? |
| 1036 | # Delay wrap check until after we have created all paths. |
| 1037 | src = root + path |
| 1038 | if os.path.islink(src): |
| 1039 | tgt = os.readlink(src) |
| 1040 | if os.path.sep in tgt: |
Mike Frysinger | 221bd82 | 2017-09-29 02:51:47 -0400 | [diff] [blame] | 1041 | sym_paths[lddtree.normpath(ReadlinkRoot(src, root))] = new_path |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1042 | |
| 1043 | # Rewrite absolute links to relative and then generate the symlink |
| 1044 | # ourselves. All other symlinks can be hardlinked below. |
| 1045 | if tgt[0] == '/': |
| 1046 | tgt = os.path.relpath(tgt, os.path.dirname(new_path)) |
| 1047 | os.symlink(tgt, dst) |
| 1048 | continue |
| 1049 | |
Mike Frysinger | 60a2f6c | 2019-12-04 04:18:58 -0500 | [diff] [blame] | 1050 | logging.debug('Linking path %s -> %s', src, dst) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1051 | os.link(src, dst) |
| 1052 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1053 | # Locate all the dependencies for all the ELFs. Stick them all in the |
| 1054 | # top level "lib" dir to make the wrapper simpler. This exact path does |
| 1055 | # not matter since we execute ldso directly, and we tell the ldso the |
| 1056 | # exact path to search for its libraries. |
| 1057 | libdir = os.path.join(output_dir, 'lib') |
| 1058 | osutils.SafeMakedirs(libdir) |
| 1059 | donelibs = set() |
Mike Frysinger | 9fe0234 | 2019-12-12 17:52:53 -0500 | [diff] [blame] | 1060 | basenamelibs = set() |
Mike Frysinger | 4331fc6 | 2017-09-28 14:03:25 -0400 | [diff] [blame] | 1061 | glibc_re = re.compile(r'/lib(c|pthread)-[0-9.]+\.so$') |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1062 | for elf in elfs: |
Mike Frysinger | ea7688e | 2014-07-31 22:40:33 -0400 | [diff] [blame] | 1063 | e = lddtree.ParseELF(elf, root=root, ldpaths=ldpaths) |
Mike Frysinger | 60a2f6c | 2019-12-04 04:18:58 -0500 | [diff] [blame] | 1064 | logging.debug('Parsed elf %s data: %s', elf, e) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1065 | interp = e['interp'] |
Mike Frysinger | 221bd82 | 2017-09-29 02:51:47 -0400 | [diff] [blame] | 1066 | |
Mike Frysinger | 9fe0234 | 2019-12-12 17:52:53 -0500 | [diff] [blame] | 1067 | # TODO(crbug.com/917193): Drop this hack once libopcodes linkage is fixed. |
| 1068 | if os.path.basename(elf).startswith('libopcodes-'): |
| 1069 | continue |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1070 | |
Mike Frysinger | 00b129f | 2021-04-21 18:11:48 -0400 | [diff] [blame] | 1071 | # Copy all the dependencies before we copy the program & generate wrappers. |
Mike Frysinger | 9fe0234 | 2019-12-12 17:52:53 -0500 | [diff] [blame] | 1072 | for lib, lib_data in e['libs'].items(): |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1073 | src = path = lib_data['path'] |
| 1074 | if path is None: |
Ralph Nathan | 446aee9 | 2015-03-23 14:44:56 -0700 | [diff] [blame] | 1075 | logging.warning('%s: could not locate %s', elf, lib) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1076 | continue |
Mike Frysinger | 9fe0234 | 2019-12-12 17:52:53 -0500 | [diff] [blame] | 1077 | |
| 1078 | # No need to try and copy the same source lib multiple times. |
| 1079 | if path in donelibs: |
| 1080 | continue |
| 1081 | donelibs.add(path) |
| 1082 | |
| 1083 | # Die if we try to normalize different source libs with the same basename. |
| 1084 | if lib in basenamelibs: |
| 1085 | logging.error('Multiple sources detected for %s:\n new: %s\n old: %s', |
| 1086 | os.path.join('/lib', lib), path, |
| 1087 | ' '.join(x for x in donelibs |
| 1088 | if x != path and os.path.basename(x) == lib)) |
| 1089 | # TODO(crbug.com/917193): Make this fatal. |
| 1090 | # cros_build_lib.Die('Unable to resolve lib conflicts') |
| 1091 | continue |
| 1092 | basenamelibs.add(lib) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1093 | |
| 1094 | # Needed libs are the SONAME, but that is usually a symlink, not a |
| 1095 | # real file. So link in the target rather than the symlink itself. |
| 1096 | # We have to walk all the possible symlinks (SONAME could point to a |
| 1097 | # symlink which points to a symlink), and we have to handle absolute |
| 1098 | # ourselves (since we have a "root" argument). |
| 1099 | dst = os.path.join(libdir, os.path.basename(path)) |
| 1100 | src = ReadlinkRoot(src, root) |
| 1101 | |
Mike Frysinger | 60a2f6c | 2019-12-04 04:18:58 -0500 | [diff] [blame] | 1102 | logging.debug('Linking lib %s -> %s', root + src, dst) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1103 | os.link(root + src, dst) |
| 1104 | |
Mike Frysinger | 00b129f | 2021-04-21 18:11:48 -0400 | [diff] [blame] | 1105 | # Do not create wrapper for libc. crbug.com/766827 |
| 1106 | if interp and not glibc_re.search(elf): |
| 1107 | # Generate a wrapper if it is executable. |
| 1108 | interp = os.path.join('/lib', os.path.basename(interp)) |
| 1109 | lddtree.GenerateLdsoWrapper(output_dir, path_rewrite_func(elf), interp, |
| 1110 | libpaths=e['rpath'] + e['runpath']) |
| 1111 | FixClangXXWrapper(output_dir, path_rewrite_func(elf)) |
| 1112 | |
| 1113 | # Wrap any symlinks to the wrapper. |
| 1114 | if elf in sym_paths: |
| 1115 | link = sym_paths[elf] |
| 1116 | GeneratePathWrapper(output_dir, link, elf) |
| 1117 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1118 | |
| 1119 | def _EnvdGetVar(envd, var): |
| 1120 | """Given a Gentoo env.d file, extract a var from it |
| 1121 | |
| 1122 | Args: |
| 1123 | envd: The env.d file to load (may be a glob path) |
| 1124 | var: The var to extract |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 1125 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1126 | Returns: |
| 1127 | The value of |var| |
| 1128 | """ |
| 1129 | envds = glob.glob(envd) |
| 1130 | assert len(envds) == 1, '%s: should have exactly 1 env.d file' % envd |
| 1131 | envd = envds[0] |
Mike Frysinger | e652ba1 | 2019-09-08 00:57:43 -0400 | [diff] [blame] | 1132 | return key_value_store.LoadFile(envd)[var] |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1133 | |
| 1134 | |
| 1135 | def _ProcessBinutilsConfig(target, output_dir): |
| 1136 | """Do what binutils-config would have done""" |
| 1137 | binpath = os.path.join('/bin', target + '-') |
Mike Frysinger | d4d40fd | 2014-11-06 17:30:57 -0500 | [diff] [blame] | 1138 | |
Adrian Ratiu | 78e534d | 2021-01-06 19:58:38 +0200 | [diff] [blame] | 1139 | # Locate the bin dir holding the linker and perform some sanity checks |
Mike Frysinger | d4d40fd | 2014-11-06 17:30:57 -0500 | [diff] [blame] | 1140 | binutils_bin_path = os.path.join(output_dir, 'usr', toolchain.GetHostTuple(), |
| 1141 | target, 'binutils-bin') |
Adrian Ratiu | 78e534d | 2021-01-06 19:58:38 +0200 | [diff] [blame] | 1142 | globpath = os.path.join(binutils_bin_path, '*') |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1143 | srcpath = glob.glob(globpath) |
Adrian Ratiu | 78e534d | 2021-01-06 19:58:38 +0200 | [diff] [blame] | 1144 | assert len(srcpath) == 1, ('%s: matched more than one path. Is Gold enabled?' |
| 1145 | % globpath) |
| 1146 | srcpath = srcpath[0] |
| 1147 | ld_path = os.path.join(srcpath, 'ld') |
| 1148 | assert os.path.exists(ld_path), '%s: linker is missing!' % ld_path |
| 1149 | ld_path = os.path.join(srcpath, 'ld.bfd') |
| 1150 | assert os.path.exists(ld_path), '%s: linker is missing!' % ld_path |
Rahul Chaudhry | 4891b4d | 2017-03-08 10:31:27 -0800 | [diff] [blame] | 1151 | |
Mike Frysinger | 78b7a81 | 2014-11-26 19:45:23 -0500 | [diff] [blame] | 1152 | srcpath = srcpath[len(output_dir):] |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1153 | gccpath = os.path.join('/usr', 'libexec', 'gcc') |
| 1154 | for prog in os.listdir(output_dir + srcpath): |
| 1155 | # Skip binaries already wrapped. |
| 1156 | if not prog.endswith('.real'): |
| 1157 | GeneratePathWrapper(output_dir, binpath + prog, |
| 1158 | os.path.join(srcpath, prog)) |
| 1159 | GeneratePathWrapper(output_dir, os.path.join(gccpath, prog), |
| 1160 | os.path.join(srcpath, prog)) |
| 1161 | |
David James | 27ac4ae | 2012-12-03 23:16:15 -0800 | [diff] [blame] | 1162 | libpath = os.path.join('/usr', toolchain.GetHostTuple(), target, 'lib') |
Mike Frysinger | d4d40fd | 2014-11-06 17:30:57 -0500 | [diff] [blame] | 1163 | envd = os.path.join(output_dir, 'etc', 'env.d', 'binutils', '*') |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1164 | srcpath = _EnvdGetVar(envd, 'LIBPATH') |
| 1165 | os.symlink(os.path.relpath(srcpath, os.path.dirname(libpath)), |
| 1166 | output_dir + libpath) |
| 1167 | |
| 1168 | |
| 1169 | def _ProcessGccConfig(target, output_dir): |
| 1170 | """Do what gcc-config would have done""" |
| 1171 | binpath = '/bin' |
| 1172 | envd = os.path.join(output_dir, 'etc', 'env.d', 'gcc', '*') |
| 1173 | srcpath = _EnvdGetVar(envd, 'GCC_PATH') |
| 1174 | for prog in os.listdir(output_dir + srcpath): |
| 1175 | # Skip binaries already wrapped. |
| 1176 | if (not prog.endswith('.real') and |
| 1177 | not prog.endswith('.elf') and |
| 1178 | prog.startswith(target)): |
| 1179 | GeneratePathWrapper(output_dir, os.path.join(binpath, prog), |
| 1180 | os.path.join(srcpath, prog)) |
| 1181 | return srcpath |
| 1182 | |
| 1183 | |
Frank Henigman | 179ec7c | 2015-02-06 03:01:09 -0500 | [diff] [blame] | 1184 | def _ProcessSysrootWrappers(_target, output_dir, srcpath): |
| 1185 | """Remove chroot-specific things from our sysroot wrappers""" |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1186 | # Disable ccache since we know it won't work outside of chroot. |
Tobias Bosch | ddd1649 | 2019-08-14 09:29:54 -0700 | [diff] [blame] | 1187 | |
Tobias Bosch | ddd1649 | 2019-08-14 09:29:54 -0700 | [diff] [blame] | 1188 | # Use the version of the wrapper that does not use ccache. |
Frank Henigman | 179ec7c | 2015-02-06 03:01:09 -0500 | [diff] [blame] | 1189 | for sysroot_wrapper in glob.glob(os.path.join( |
Tobias Bosch | ddd1649 | 2019-08-14 09:29:54 -0700 | [diff] [blame] | 1190 | output_dir + srcpath, 'sysroot_wrapper*.ccache')): |
| 1191 | # Can't update the wrapper in place to not affect the chroot, |
| 1192 | # but only the extracted toolchain. |
| 1193 | os.unlink(sysroot_wrapper) |
| 1194 | shutil.copy(sysroot_wrapper[:-6] + 'noccache', sysroot_wrapper) |
Tobias Bosch | 7bc907a | 2019-10-09 11:52:40 -0700 | [diff] [blame] | 1195 | shutil.copy(sysroot_wrapper[:-6] + 'noccache.elf', sysroot_wrapper + '.elf') |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1196 | |
| 1197 | |
Manoj Gupta | 61bf9db | 2020-03-23 21:28:04 -0700 | [diff] [blame] | 1198 | def _ProcessClangWrappers(target, output_dir): |
| 1199 | """Remove chroot-specific things from our sysroot wrappers""" |
| 1200 | clang_bin_path = '/usr/bin' |
| 1201 | # Disable ccache from clang wrappers. |
| 1202 | _ProcessSysrootWrappers(target, output_dir, clang_bin_path) |
| 1203 | GeneratePathWrapper(output_dir, f'/bin/{target}-clang', |
| 1204 | f'/usr/bin/{target}-clang') |
| 1205 | GeneratePathWrapper(output_dir, f'/bin/{target}-clang++', |
| 1206 | f'/usr/bin/{target}-clang++') |
| 1207 | |
| 1208 | |
Yunlian Jiang | 5ad6b51 | 2017-09-20 09:27:45 -0700 | [diff] [blame] | 1209 | def _CreateMainLibDir(target, output_dir): |
| 1210 | """Create some lib dirs so that compiler can get the right Gcc paths""" |
| 1211 | osutils.SafeMakedirs(os.path.join(output_dir, 'usr', target, 'lib')) |
| 1212 | osutils.SafeMakedirs(os.path.join(output_dir, 'usr', target, 'usr/lib')) |
| 1213 | |
| 1214 | |
Manoj Gupta | df8b387 | 2022-01-13 11:57:36 -0800 | [diff] [blame] | 1215 | def _CreateRemoteToolchainFile(output_dir): |
| 1216 | """Create a remote_toolchain_inputs file for reclient/RBE""" |
| 1217 | # The inputs file lists all files/shared libraries needed to run clang. |
| 1218 | # All inputs are relative to location of clang binary and one input |
| 1219 | # location per line of file e.g. |
| 1220 | # clang-13.elf |
| 1221 | # clang++-13.elf |
| 1222 | # relative/path/to/clang/resource/directory |
| 1223 | |
| 1224 | clang_path = os.path.join(output_dir, 'usr/bin') |
| 1225 | # Add needed shared libraries and internal files e.g. allowlists. |
| 1226 | toolchain_inputs = ['../../lib'] |
| 1227 | clang_shared_dirs = glob.glob( |
| 1228 | os.path.join(output_dir, 'usr/lib64/clang/*/share')) |
| 1229 | for clang_dir in clang_shared_dirs: |
| 1230 | toolchain_inputs.append(os.path.relpath(clang_dir, clang_path)) |
| 1231 | |
| 1232 | # Add actual clang binaries/wrappers. |
| 1233 | for clang_files in glob.glob(os.path.join(clang_path, 'clang*-[0-9]*')): |
| 1234 | toolchain_inputs.append(os.path.basename(clang_files)) |
| 1235 | |
| 1236 | with open(os.path.join(clang_path, 'remote_toolchain_inputs'), 'w') as f: |
| 1237 | f.writelines('%s\n' % line for line in toolchain_inputs) |
| 1238 | |
| 1239 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1240 | def _ProcessDistroCleanups(target, output_dir): |
| 1241 | """Clean up the tree and remove all distro-specific requirements |
| 1242 | |
| 1243 | Args: |
| 1244 | target: The toolchain target name |
| 1245 | output_dir: The output directory to clean up |
| 1246 | """ |
| 1247 | _ProcessBinutilsConfig(target, output_dir) |
| 1248 | gcc_path = _ProcessGccConfig(target, output_dir) |
Frank Henigman | 179ec7c | 2015-02-06 03:01:09 -0500 | [diff] [blame] | 1249 | _ProcessSysrootWrappers(target, output_dir, gcc_path) |
Manoj Gupta | 61bf9db | 2020-03-23 21:28:04 -0700 | [diff] [blame] | 1250 | _ProcessClangWrappers(target, output_dir) |
Yunlian Jiang | 5ad6b51 | 2017-09-20 09:27:45 -0700 | [diff] [blame] | 1251 | _CreateMainLibDir(target, output_dir) |
Manoj Gupta | df8b387 | 2022-01-13 11:57:36 -0800 | [diff] [blame] | 1252 | _CreateRemoteToolchainFile(output_dir) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1253 | |
| 1254 | osutils.RmDir(os.path.join(output_dir, 'etc')) |
| 1255 | |
| 1256 | |
| 1257 | def CreatePackagableRoot(target, output_dir, ldpaths, root='/'): |
| 1258 | """Setup a tree from the packages for the specified target |
| 1259 | |
| 1260 | This populates a path with all the files from toolchain packages so that |
| 1261 | a tarball can easily be generated from the result. |
| 1262 | |
| 1263 | Args: |
| 1264 | target: The target to create a packagable root from |
| 1265 | output_dir: The output directory to place all the files |
| 1266 | ldpaths: A dict of static ldpath information |
| 1267 | root: The root path to pull all packages/files from |
| 1268 | """ |
| 1269 | # Find all the files owned by the packages for this target. |
| 1270 | paths, elfs = _GetFilesForTarget(target, root=root) |
| 1271 | |
| 1272 | # Link in all the package's files, any ELF dependencies, and wrap any |
| 1273 | # executable ELFs with helper scripts. |
| 1274 | def MoveUsrBinToBin(path): |
Han Shen | 699ea19 | 2016-03-02 10:42:47 -0800 | [diff] [blame] | 1275 | """Move /usr/bin to /bin so people can just use that toplevel dir |
| 1276 | |
George Burgess IV | ca1d761 | 2020-10-01 00:38:32 -0700 | [diff] [blame] | 1277 | Note we do not apply this to clang or rust - there is correlation between |
| 1278 | clang's search path for libraries / inclusion and its installation path. |
Han Shen | 699ea19 | 2016-03-02 10:42:47 -0800 | [diff] [blame] | 1279 | """ |
Manoj Gupta | 61bf9db | 2020-03-23 21:28:04 -0700 | [diff] [blame] | 1280 | NO_MOVE_PATTERNS = ('clang', 'rust', 'cargo', 'sysroot_wrapper') |
George Burgess IV | ca1d761 | 2020-10-01 00:38:32 -0700 | [diff] [blame] | 1281 | if (path.startswith('/usr/bin/') and |
Manoj Gupta | 61bf9db | 2020-03-23 21:28:04 -0700 | [diff] [blame] | 1282 | not any(x in path for x in NO_MOVE_PATTERNS)): |
Han Shen | 699ea19 | 2016-03-02 10:42:47 -0800 | [diff] [blame] | 1283 | return path[4:] |
| 1284 | return path |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1285 | _BuildInitialPackageRoot(output_dir, paths, elfs, ldpaths, |
| 1286 | path_rewrite_func=MoveUsrBinToBin, root=root) |
| 1287 | |
| 1288 | # The packages, when part of the normal distro, have helper scripts |
| 1289 | # that setup paths and such. Since we are making this standalone, we |
| 1290 | # need to preprocess all that ourselves. |
| 1291 | _ProcessDistroCleanups(target, output_dir) |
| 1292 | |
| 1293 | |
| 1294 | def CreatePackages(targets_wanted, output_dir, root='/'): |
| 1295 | """Create redistributable cross-compiler packages for the specified targets |
| 1296 | |
| 1297 | This creates toolchain packages that should be usable in conjunction with |
| 1298 | a downloaded sysroot (created elsewhere). |
| 1299 | |
| 1300 | Tarballs (one per target) will be created in $PWD. |
| 1301 | |
| 1302 | Args: |
Don Garrett | 25f309a | 2014-03-19 14:02:12 -0700 | [diff] [blame] | 1303 | targets_wanted: The targets to package up. |
| 1304 | output_dir: The directory to put the packages in. |
| 1305 | root: The root path to pull all packages/files from. |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1306 | """ |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 1307 | logging.info('Writing tarballs to %s', output_dir) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1308 | osutils.SafeMakedirs(output_dir) |
| 1309 | ldpaths = lddtree.LoadLdpaths(root) |
| 1310 | targets = ExpandTargets(targets_wanted) |
| 1311 | |
Mike Frysinger | 221bd82 | 2017-09-29 02:51:47 -0400 | [diff] [blame] | 1312 | with osutils.TempDir(prefix='create-packages') as tempdir: |
| 1313 | logging.debug('Using tempdir: %s', tempdir) |
| 1314 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1315 | # We have to split the root generation from the compression stages. This is |
| 1316 | # because we hardlink in all the files (to avoid overhead of reading/writing |
| 1317 | # the copies multiple times). But tar gets angry if a file's hardlink count |
| 1318 | # changes from when it starts reading a file to when it finishes. |
| 1319 | with parallel.BackgroundTaskRunner(CreatePackagableRoot) as queue: |
| 1320 | for target in targets: |
| 1321 | output_target_dir = os.path.join(tempdir, target) |
| 1322 | queue.put([target, output_target_dir, ldpaths, root]) |
| 1323 | |
| 1324 | # Build the tarball. |
| 1325 | with parallel.BackgroundTaskRunner(cros_build_lib.CreateTarball) as queue: |
| 1326 | for target in targets: |
| 1327 | tar_file = os.path.join(output_dir, target + '.tar.xz') |
| 1328 | queue.put([tar_file, os.path.join(tempdir, target)]) |
| 1329 | |
| 1330 | |
Mike Frysinger | 07534cf | 2017-09-12 17:40:21 -0400 | [diff] [blame] | 1331 | def GetParser(): |
| 1332 | """Return a command line parser.""" |
Mike Frysinger | 0c80845 | 2014-11-06 17:30:23 -0500 | [diff] [blame] | 1333 | parser = commandline.ArgumentParser(description=__doc__) |
| 1334 | parser.add_argument('-u', '--nousepkg', |
| 1335 | action='store_false', dest='usepkg', default=True, |
| 1336 | help='Use prebuilt packages if possible') |
| 1337 | parser.add_argument('-d', '--deleteold', |
| 1338 | action='store_true', dest='deleteold', default=False, |
| 1339 | help='Unmerge deprecated packages') |
| 1340 | parser.add_argument('-t', '--targets', |
| 1341 | dest='targets', default='sdk', |
Mike Frysinger | 80de501 | 2019-08-01 14:10:53 -0400 | [diff] [blame] | 1342 | help='Comma separated list of tuples. Special keywords ' |
Don Garrett | c0c7400 | 2015-10-09 12:58:19 -0700 | [diff] [blame] | 1343 | "'host', 'sdk', 'boards', and 'all' are " |
Gilad Arnold | 8195b53 | 2015-04-07 10:56:30 +0300 | [diff] [blame] | 1344 | "allowed. Defaults to 'sdk'.") |
| 1345 | parser.add_argument('--include-boards', default='', metavar='BOARDS', |
| 1346 | help='Comma separated list of boards whose toolchains we ' |
| 1347 | 'will always include. Default: none') |
Mike Frysinger | 0c80845 | 2014-11-06 17:30:23 -0500 | [diff] [blame] | 1348 | parser.add_argument('--hostonly', |
| 1349 | dest='hostonly', default=False, action='store_true', |
| 1350 | help='Only setup the host toolchain. ' |
| 1351 | 'Useful for bootstrapping chroot') |
Bertrand SIMONNET | cae9d5f | 2015-03-09 15:58:01 -0700 | [diff] [blame] | 1352 | parser.add_argument('--show-board-cfg', '--show-cfg', |
| 1353 | dest='cfg_name', default=None, |
Don Garrett | c0c7400 | 2015-10-09 12:58:19 -0700 | [diff] [blame] | 1354 | help='Board to list toolchains tuples for') |
Mike Frysinger | 91f5288 | 2017-09-13 00:16:58 -0400 | [diff] [blame] | 1355 | parser.add_argument('--show-packages', default=None, |
| 1356 | help='List all packages the specified target uses') |
Mike Frysinger | 0c80845 | 2014-11-06 17:30:23 -0500 | [diff] [blame] | 1357 | parser.add_argument('--create-packages', |
| 1358 | action='store_true', default=False, |
| 1359 | help='Build redistributable packages') |
| 1360 | parser.add_argument('--output-dir', default=os.getcwd(), type='path', |
| 1361 | help='Output directory') |
| 1362 | parser.add_argument('--reconfig', default=False, action='store_true', |
| 1363 | help='Reload crossdev config and reselect toolchains') |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 1364 | parser.add_argument('--sysroot', type='path', |
| 1365 | help='The sysroot in which to install the toolchains') |
Mike Frysinger | 07534cf | 2017-09-12 17:40:21 -0400 | [diff] [blame] | 1366 | return parser |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 1367 | |
Mike Frysinger | 07534cf | 2017-09-12 17:40:21 -0400 | [diff] [blame] | 1368 | |
| 1369 | def main(argv): |
| 1370 | parser = GetParser() |
Mike Frysinger | 0c80845 | 2014-11-06 17:30:23 -0500 | [diff] [blame] | 1371 | options = parser.parse_args(argv) |
| 1372 | options.Freeze() |
Zdenek Behan | 508dcce | 2011-12-05 15:39:32 +0100 | [diff] [blame] | 1373 | |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1374 | # Figure out what we're supposed to do and reject conflicting options. |
Mike Frysinger | 91f5288 | 2017-09-13 00:16:58 -0400 | [diff] [blame] | 1375 | conflicting_options = ( |
| 1376 | options.cfg_name, |
| 1377 | options.show_packages, |
| 1378 | options.create_packages, |
| 1379 | ) |
| 1380 | if sum(bool(x) for x in conflicting_options) > 1: |
| 1381 | parser.error('conflicting options: create-packages & show-packages & ' |
| 1382 | 'show-board-cfg') |
Mike Frysinger | 984d062 | 2012-06-01 16:08:44 -0400 | [diff] [blame] | 1383 | |
Gilad Arnold | 8195b53 | 2015-04-07 10:56:30 +0300 | [diff] [blame] | 1384 | targets_wanted = set(options.targets.split(',')) |
| 1385 | boards_wanted = (set(options.include_boards.split(',')) |
| 1386 | if options.include_boards else set()) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1387 | |
Manoj Gupta | 847b609 | 2022-06-01 10:26:34 -0700 | [diff] [blame^] | 1388 | # pylint: disable=global-statement |
| 1389 | # Disable installing libc++ for armv7m-cros-eabi till new binary prebuilt |
| 1390 | # package is available. TODO(b/234507656): Remove once done. |
| 1391 | global TARGET_LLVM_PKGS_ENABLED |
| 1392 | if options.usepkg: |
| 1393 | TARGET_LLVM_PKGS_ENABLED = ( |
| 1394 | 'armv7a-cros-linux-gnueabi', |
| 1395 | 'armv7a-cros-linux-gnueabihf', |
| 1396 | 'aarch64-cros-linux-gnu', |
| 1397 | 'i686-cros-linux-gnu', |
| 1398 | 'x86_64-cros-linux-gnu', |
| 1399 | ) |
Bertrand SIMONNET | cae9d5f | 2015-03-09 15:58:01 -0700 | [diff] [blame] | 1400 | if options.cfg_name: |
| 1401 | ShowConfig(options.cfg_name) |
Mike Frysinger | 91f5288 | 2017-09-13 00:16:58 -0400 | [diff] [blame] | 1402 | elif options.show_packages is not None: |
| 1403 | cros_build_lib.AssertInsideChroot() |
| 1404 | target = options.show_packages |
| 1405 | Crossdev.Load(False) |
| 1406 | for package in GetTargetPackages(target): |
| 1407 | print(GetPortagePackage(target, package)) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1408 | elif options.create_packages: |
| 1409 | cros_build_lib.AssertInsideChroot() |
| 1410 | Crossdev.Load(False) |
Gilad Arnold | 8195b53 | 2015-04-07 10:56:30 +0300 | [diff] [blame] | 1411 | CreatePackages(targets_wanted, options.output_dir) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1412 | else: |
| 1413 | cros_build_lib.AssertInsideChroot() |
| 1414 | # This has to be always run as root. |
Ram Chandrasekar | 6975128 | 2022-02-25 21:07:36 +0000 | [diff] [blame] | 1415 | if osutils.IsNonRootUser(): |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1416 | cros_build_lib.Die('this script must be run as root') |
| 1417 | |
| 1418 | Crossdev.Load(options.reconfig) |
Gilad Arnold | 2dab78c | 2015-05-21 14:43:33 -0700 | [diff] [blame] | 1419 | root = options.sysroot or '/' |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1420 | UpdateToolchains(options.usepkg, options.deleteold, options.hostonly, |
Gilad Arnold | 8195b53 | 2015-04-07 10:56:30 +0300 | [diff] [blame] | 1421 | options.reconfig, targets_wanted, boards_wanted, |
Don Garrett | c0c7400 | 2015-10-09 12:58:19 -0700 | [diff] [blame] | 1422 | root=root) |
Mike Frysinger | 35247af | 2012-11-16 18:58:06 -0500 | [diff] [blame] | 1423 | Crossdev.Save() |
| 1424 | |
| 1425 | return 0 |