Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 1 | # Copyright 2014 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 | |
| 5 | """Install debug symbols for specified packages. |
| 6 | |
| 7 | Only reinstall the debug symbols if they are not already installed to save time. |
| 8 | |
| 9 | The debug symbols are packaged outside of the prebuilt package in a |
| 10 | .debug.tbz2 archive when FEATURES=separatedebug is set (by default on |
| 11 | builders). On local machines, separatedebug is not set and the debug symbols |
| 12 | are part of the prebuilt package. |
| 13 | """ |
| 14 | |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 15 | import argparse |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 16 | import functools |
Chris McDonald | 59650c3 | 2021-07-20 15:29:28 -0600 | [diff] [blame] | 17 | import logging |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 18 | import multiprocessing |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 19 | import os |
| 20 | import pickle |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 21 | import tempfile |
Mike Frysinger | e852b07 | 2021-05-21 12:39:03 -0400 | [diff] [blame] | 22 | import urllib.parse |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 23 | |
| 24 | from chromite.lib import binpkg |
Mike Frysinger | 06a51c8 | 2021-04-06 11:39:17 -0400 | [diff] [blame] | 25 | from chromite.lib import build_target_lib |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 26 | from chromite.lib import cache |
| 27 | from chromite.lib import commandline |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 28 | from chromite.lib import constants |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 29 | from chromite.lib import cros_build_lib |
Chris McDonald | 59650c3 | 2021-07-20 15:29:28 -0600 | [diff] [blame] | 30 | from chromite.lib import gs |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 31 | from chromite.lib import osutils |
Gilad Arnold | 83233ed | 2015-05-08 12:12:13 -0700 | [diff] [blame] | 32 | from chromite.lib import path_util |
Mike Frysinger | 151f5fb | 2019-10-22 20:36:25 -0400 | [diff] [blame] | 33 | from chromite.utils import outcap |
Bertrand SIMONNET | 01394c3 | 2015-02-09 17:20:25 -0800 | [diff] [blame] | 34 | |
Chris McDonald | 59650c3 | 2021-07-20 15:29:28 -0600 | [diff] [blame] | 35 | |
Bertrand SIMONNET | 01394c3 | 2015-02-09 17:20:25 -0800 | [diff] [blame] | 36 | if cros_build_lib.IsInsideChroot(): |
Mike Frysinger | 27e21b7 | 2018-07-12 14:20:21 -0400 | [diff] [blame] | 37 | # pylint: disable=import-error |
Bertrand SIMONNET | 01394c3 | 2015-02-09 17:20:25 -0800 | [diff] [blame] | 38 | from portage import create_trees |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 39 | |
Mike Frysinger | 6a2b0f2 | 2020-02-20 13:34:07 -0500 | [diff] [blame] | 40 | |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 41 | DEBUG_SYMS_EXT = '.debug.tbz2' |
| 42 | |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 43 | # We cache the package indexes. When the format of what we store changes, |
| 44 | # bump the cache version to avoid problems. |
| 45 | CACHE_VERSION = '1' |
| 46 | |
| 47 | |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 48 | class DebugSymbolsInstaller(object): |
Mike Frysinger | 151f5fb | 2019-10-22 20:36:25 -0400 | [diff] [blame] | 49 | """Container for enviromnent objects, needed to make multiprocessing work.""" |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 50 | |
| 51 | def __init__(self, vartree, gs_context, sysroot, stdout_to_null): |
| 52 | self._vartree = vartree |
| 53 | self._gs_context = gs_context |
| 54 | self._sysroot = sysroot |
| 55 | self._stdout_to_null = stdout_to_null |
Mike Frysinger | 151f5fb | 2019-10-22 20:36:25 -0400 | [diff] [blame] | 56 | self._capturer = outcap.OutputCapturer() |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 57 | |
| 58 | def __enter__(self): |
| 59 | if self._stdout_to_null: |
Mike Frysinger | 151f5fb | 2019-10-22 20:36:25 -0400 | [diff] [blame] | 60 | self._capturer.StartCapturing() |
| 61 | |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 62 | return self |
| 63 | |
| 64 | def __exit__(self, _exc_type, _exc_val, _exc_tb): |
| 65 | if self._stdout_to_null: |
Mike Frysinger | 151f5fb | 2019-10-22 20:36:25 -0400 | [diff] [blame] | 66 | self._capturer.StopCapturing() |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 67 | |
| 68 | def Install(self, cpv, url): |
| 69 | """Install the debug symbols for |cpv|. |
| 70 | |
| 71 | This will install the debug symbols tarball in PKGDIR so that it can be |
| 72 | used later. |
| 73 | |
| 74 | Args: |
| 75 | cpv: the cpv of the package to build. This assumes that the cpv is |
| 76 | installed in the sysroot. |
| 77 | url: url of the debug symbols archive. This could be a Google Storage url |
| 78 | or a local path. |
| 79 | """ |
| 80 | archive = os.path.join(self._vartree.settings['PKGDIR'], |
| 81 | cpv + DEBUG_SYMS_EXT) |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 82 | # GsContext does not understand file:// scheme so we need to extract the |
| 83 | # path ourselves. |
Mike Frysinger | 3dcacee | 2019-08-23 17:09:11 -0400 | [diff] [blame] | 84 | parsed_url = urllib.parse.urlsplit(url) |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 85 | if not parsed_url.scheme or parsed_url.scheme == 'file': |
| 86 | url = parsed_url.path |
| 87 | |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 88 | if not os.path.isfile(archive): |
| 89 | self._gs_context.Copy(url, archive, debug_level=logging.DEBUG) |
| 90 | |
Mike Frysinger | 2e169a9 | 2022-04-27 02:15:09 -0400 | [diff] [blame] | 91 | compression = cros_build_lib.CompressionDetectType(archive) |
| 92 | compressor = cros_build_lib.FindCompressor(compression) |
| 93 | |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 94 | with osutils.TempDir(sudo_rm=True) as tempdir: |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 95 | cros_build_lib.sudo_run( |
Mike Frysinger | 2e169a9 | 2022-04-27 02:15:09 -0400 | [diff] [blame] | 96 | ['tar', '-I', compressor, '-xf', archive, '-C', tempdir], quiet=True) |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 97 | |
| 98 | with open(self._vartree.getpath(cpv, filename='CONTENTS'), |
| 99 | 'a') as content_file: |
| 100 | # Merge the content of the temporary dir into the sysroot. |
| 101 | # pylint: disable=protected-access |
| 102 | link = self._vartree.dbapi._dblink(cpv) |
| 103 | link.mergeme(tempdir, self._sysroot, content_file, None, '', {}, None) |
| 104 | |
| 105 | |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 106 | def ShouldGetSymbols(cpv, vardb, remote_symbols): |
| 107 | """Return True if the symbols for cpv are available and are not installed. |
| 108 | |
| 109 | We try to check if the symbols are installed before checking availability as |
| 110 | a GS request is more expensive than checking locally. |
| 111 | |
| 112 | Args: |
| 113 | cpv: cpv of the package |
| 114 | vardb: a vartree dbapi |
| 115 | remote_symbols: a mapping from cpv to debug symbols url |
| 116 | |
| 117 | Returns: |
| 118 | True if |cpv|'s debug symbols are not installed and are available |
| 119 | """ |
| 120 | features, contents = vardb.aux_get(cpv, ['FEATURES', 'CONTENTS']) |
| 121 | |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 122 | return ('separatedebug' in features and not '/usr/lib/debug/' in contents and |
| 123 | cpv in remote_symbols) |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 124 | |
| 125 | |
| 126 | def RemoteSymbols(vartree, binhost_cache=None): |
| 127 | """Get the cpv to debug symbols mapping. |
| 128 | |
| 129 | If several binhost contain debug symbols for the same cpv, keep only the |
| 130 | highest priority one. |
| 131 | |
| 132 | Args: |
| 133 | vartree: a vartree |
| 134 | binhost_cache: a cache containing the cpv to debug symbols url for all |
| 135 | known binhosts. None if we are not caching binhosts. |
| 136 | |
| 137 | Returns: |
| 138 | a dictionary mapping the cpv to a remote debug symbols gsurl. |
| 139 | """ |
| 140 | symbols_mapping = {} |
| 141 | for binhost in vartree.settings['PORTAGE_BINHOST'].split(): |
| 142 | if binhost: |
| 143 | symbols_mapping.update(ListBinhost(binhost, binhost_cache)) |
| 144 | return symbols_mapping |
| 145 | |
| 146 | |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 147 | def GetPackageIndex(binhost, binhost_cache=None): |
| 148 | """Get the packages index for |binhost|. |
| 149 | |
| 150 | If a cache is provided, use it to a cache remote packages index. |
| 151 | |
| 152 | Args: |
| 153 | binhost: a portage binhost, local, google storage or http. |
| 154 | binhost_cache: a cache for the remote packages index. |
| 155 | |
| 156 | Returns: |
| 157 | A PackageIndex object. |
| 158 | """ |
| 159 | key = binhost.split('://')[-1] |
| 160 | key = key.rstrip('/').split('/') |
| 161 | |
| 162 | if binhost_cache and binhost_cache.Lookup(key).Exists(): |
Mike Frysinger | 8e99b37 | 2019-12-05 19:05:02 -0500 | [diff] [blame] | 163 | with open(binhost_cache.Lookup(key).path, 'rb') as f: |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 164 | return pickle.load(f) |
| 165 | |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 166 | pkgindex = binpkg.GrabRemotePackageIndex(binhost, quiet=True) |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 167 | if pkgindex and binhost_cache: |
| 168 | # Only cache remote binhosts as local binhosts can change. |
| 169 | with tempfile.NamedTemporaryFile(delete=False) as temp_file: |
| 170 | pickle.dump(pkgindex, temp_file) |
| 171 | temp_file.file.close() |
| 172 | binhost_cache.Lookup(key).Assign(temp_file.name) |
| 173 | elif pkgindex is None: |
Mike Frysinger | 3dcacee | 2019-08-23 17:09:11 -0400 | [diff] [blame] | 174 | urlparts = urllib.parse.urlsplit(binhost) |
Bertrand SIMONNET | dd66ab5 | 2015-01-08 14:48:51 -0800 | [diff] [blame] | 175 | if urlparts.scheme not in ('file', ''): |
| 176 | # Don't fail the build on network errors. Print a warning message and |
| 177 | # continue. |
Lann Martin | ffb9516 | 2018-08-28 12:02:54 -0600 | [diff] [blame] | 178 | logging.warning('Could not get package index %s', binhost) |
Bertrand SIMONNET | dd66ab5 | 2015-01-08 14:48:51 -0800 | [diff] [blame] | 179 | return None |
| 180 | |
| 181 | binhost = urlparts.path |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 182 | if not os.path.isdir(binhost): |
| 183 | raise ValueError('unrecognized binhost format for %s.') |
| 184 | pkgindex = binpkg.GrabLocalPackageIndex(binhost) |
| 185 | |
| 186 | return pkgindex |
| 187 | |
| 188 | |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 189 | def ListBinhost(binhost, binhost_cache=None): |
| 190 | """Return the cpv to debug symbols mapping for a given binhost. |
| 191 | |
| 192 | List the content of the binhost to extract the cpv to debug symbols |
| 193 | mapping. If --cachebinhost is set, we cache the result to avoid the |
| 194 | cost of gsutil every time. |
| 195 | |
| 196 | Args: |
| 197 | binhost: a portage binhost, local or on google storage. |
| 198 | binhost_cache: a cache containing mappings cpv to debug symbols url for a |
| 199 | given binhost (None if we don't want to cache). |
| 200 | |
| 201 | Returns: |
| 202 | A cpv to debug symbols url mapping. |
| 203 | """ |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 204 | |
| 205 | symbols = {} |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 206 | pkgindex = GetPackageIndex(binhost, binhost_cache) |
Bertrand SIMONNET | dd66ab5 | 2015-01-08 14:48:51 -0800 | [diff] [blame] | 207 | if pkgindex is None: |
| 208 | return symbols |
| 209 | |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 210 | for p in pkgindex.packages: |
| 211 | if p.get('DEBUG_SYMBOLS') == 'yes': |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 212 | path = p.get('PATH', p['CPV'] + '.tbz2') |
| 213 | base_url = pkgindex.header.get('URI', binhost) |
| 214 | symbols[p['CPV']] = os.path.join(base_url, |
| 215 | path.replace('.tbz2', DEBUG_SYMS_EXT)) |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 216 | |
| 217 | return symbols |
| 218 | |
| 219 | |
| 220 | def GetMatchingCPV(package, vardb): |
| 221 | """Return the cpv of the installed package matching |package|. |
| 222 | |
| 223 | Args: |
| 224 | package: package name |
| 225 | vardb: a vartree dbapi |
| 226 | |
| 227 | Returns: |
| 228 | The cpv of the installed package whose name matchex |package|. |
| 229 | """ |
| 230 | matches = vardb.match(package) |
| 231 | if not matches: |
| 232 | cros_build_lib.Die('Could not find package %s' % package) |
| 233 | if len(matches) != 1: |
| 234 | cros_build_lib.Die('Ambiguous package name: %s.\n' |
| 235 | 'Matching: %s' % (package, ' '.join(matches))) |
| 236 | return matches[0] |
| 237 | |
| 238 | |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 239 | def GetVartree(sysroot): |
| 240 | """Get the portage vartree. |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 241 | |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 242 | This must be called in subprocesses only. The vartree is not serializable, |
| 243 | and is implemented as a singleton in portage, so it always breaks the |
| 244 | parallel call when initialized before it is called. |
| 245 | """ |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 246 | trees = create_trees(target_root=sysroot, config_root=sysroot) |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 247 | return trees[sysroot]['vartree'] |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 248 | |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 249 | |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 250 | def GetBinhostCache(options): |
| 251 | """Get and optionally clear the binhost cache.""" |
Gilad Arnold | 83233ed | 2015-05-08 12:12:13 -0700 | [diff] [blame] | 252 | cache_dir = os.path.join(path_util.FindCacheDir(), |
Bertrand SIMONNET | 1e146e5 | 2014-12-11 14:11:56 -0800 | [diff] [blame] | 253 | 'cros_install_debug_syms-v' + CACHE_VERSION) |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 254 | if options.clearcache: |
| 255 | osutils.RmDir(cache_dir, ignore_missing=True) |
| 256 | |
| 257 | binhost_cache = None |
| 258 | if options.cachebinhost: |
| 259 | binhost_cache = cache.DiskCache(cache_dir) |
| 260 | |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 261 | return binhost_cache |
Bertrand SIMONNET | bef192e | 2014-12-17 14:09:16 -0800 | [diff] [blame] | 262 | |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 263 | |
| 264 | def GetInstallArgs(options, sysroot): |
| 265 | """Resolve the packages that are to have their debug symbols installed. |
| 266 | |
| 267 | This function must be called in subprocesses only since it requires the |
| 268 | portage vartree. |
| 269 | See: GetVartree |
| 270 | |
| 271 | Returns: |
| 272 | list[(pkg, binhost_url)] |
| 273 | """ |
| 274 | vartree = GetVartree(sysroot) |
| 275 | symbols_mapping = RemoteSymbols(vartree, GetBinhostCache(options)) |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 276 | |
| 277 | if options.all: |
| 278 | to_install = vartree.dbapi.cpv_all() |
| 279 | else: |
| 280 | to_install = [GetMatchingCPV(p, vartree.dbapi) for p in options.packages] |
| 281 | |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 282 | to_install = [ |
| 283 | p for p in to_install |
| 284 | if ShouldGetSymbols(p, vartree.dbapi, symbols_mapping) |
| 285 | ] |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 286 | |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 287 | return [(p, symbols_mapping[p]) for p in to_install] |
| 288 | |
| 289 | |
| 290 | def ListInstallArgs(options, sysroot): |
| 291 | """List the args for the calling process.""" |
| 292 | lines = ['%s %s' % arg for arg in GetInstallArgs(options, sysroot)] |
| 293 | print('\n'.join(lines)) |
| 294 | |
| 295 | |
| 296 | def GetInstallArgsList(argv): |
| 297 | """Get the install args from the --list reexec of the command.""" |
Alex Klein | 209066a | 2020-05-11 16:36:54 -0600 | [diff] [blame] | 298 | # Insert the --list as the first argument to prevent parsing --list as a |
| 299 | # package when a package is given. |
| 300 | cmd = [argv[0]] + ['--list'] + argv[1:] |
Mike Frysinger | 8e99b37 | 2019-12-05 19:05:02 -0500 | [diff] [blame] | 301 | result = cros_build_lib.run(cmd, capture_output=True, encoding='utf-8') |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 302 | lines = result.output.splitlines() |
| 303 | return [line.split() for line in lines if line] |
| 304 | |
| 305 | |
| 306 | def _InstallOne(sysroot, debug, args): |
| 307 | """Parallelizable wrapper for the DebugSymbolsInstaller.Install method.""" |
| 308 | vartree = GetVartree(sysroot) |
| 309 | gs_context = gs.GSContext(boto_file=vartree.settings['BOTO_CONFIG']) |
| 310 | with DebugSymbolsInstaller(vartree, gs_context, sysroot, |
| 311 | not debug) as installer: |
| 312 | installer.Install(*args) |
| 313 | |
| 314 | |
| 315 | def GetParser(): |
| 316 | """Build the argument parser.""" |
| 317 | parser = commandline.ArgumentParser(description=__doc__) |
| 318 | parser.add_argument('--board', help='Board name (required).', required=True) |
| 319 | parser.add_argument( |
| 320 | '--all', |
| 321 | action='store_true', |
| 322 | default=False, |
| 323 | help='Install the debug symbols for all installed packages') |
| 324 | parser.add_argument( |
| 325 | 'packages', |
| 326 | nargs=argparse.REMAINDER, |
| 327 | help='list of packages that need the debug symbols.') |
| 328 | |
| 329 | advanced = parser.add_argument_group('Advanced options') |
| 330 | advanced.add_argument( |
| 331 | '--nocachebinhost', |
| 332 | dest='cachebinhost', |
| 333 | default=True, |
| 334 | action='store_false', |
| 335 | help="Don't cache the list of files contained in binhosts. " |
| 336 | '(Default: cache)') |
| 337 | advanced.add_argument( |
| 338 | '--clearcache', |
| 339 | action='store_true', |
| 340 | default=False, |
| 341 | help='Clear the binhost cache.') |
| 342 | advanced.add_argument( |
| 343 | '-j', |
| 344 | '--jobs', |
| 345 | default=multiprocessing.cpu_count(), |
| 346 | type=int, |
| 347 | help='Number of processes to run in parallel.') |
| 348 | advanced.add_argument( |
| 349 | '--list', |
| 350 | action='store_true', |
| 351 | default=False, |
| 352 | help='List the packages whose debug symbols would be installed and ' |
| 353 | 'their binhost path.') |
| 354 | |
| 355 | return parser |
| 356 | |
| 357 | |
| 358 | def ParseArgs(argv): |
| 359 | """Parse and validate arguments.""" |
| 360 | parser = GetParser() |
| 361 | |
| 362 | options = parser.parse_args(argv) |
| 363 | if options.all and options.packages: |
| 364 | parser.error('Cannot use --all with a list of packages') |
| 365 | |
| 366 | options.Freeze() |
| 367 | |
| 368 | return options |
| 369 | |
| 370 | |
| 371 | def main(argv): |
| 372 | if not cros_build_lib.IsInsideChroot(): |
| 373 | raise commandline.ChrootRequiredError(argv) |
| 374 | |
Mike Frysinger | 2b1fed5 | 2022-04-27 02:15:33 -0400 | [diff] [blame^] | 375 | options = ParseArgs(argv) |
| 376 | |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 377 | cmd = [os.path.join(constants.CHROMITE_BIN_DIR, |
| 378 | 'cros_install_debug_syms')] + argv |
Ram Chandrasekar | 6975128 | 2022-02-25 21:07:36 +0000 | [diff] [blame] | 379 | if osutils.IsNonRootUser(): |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 380 | cros_build_lib.sudo_run(cmd) |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 381 | return |
| 382 | |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 383 | # sysroot must have a trailing / as the tree dictionary produced by |
| 384 | # create_trees in indexed with a trailing /. |
Mike Frysinger | 06a51c8 | 2021-04-06 11:39:17 -0400 | [diff] [blame] | 385 | sysroot = build_target_lib.get_default_sysroot_path(options.board) + '/' |
Alex Klein | 161495b | 2019-09-26 16:59:46 -0600 | [diff] [blame] | 386 | |
| 387 | if options.list: |
| 388 | ListInstallArgs(options, sysroot) |
| 389 | return |
| 390 | |
| 391 | args = GetInstallArgsList(cmd) |
| 392 | |
| 393 | if not args: |
| 394 | logging.info('No packages found needing debug symbols.') |
| 395 | return |
| 396 | |
| 397 | # Partial to simplify the arguments to parallel since the first two are the |
| 398 | # same for every call. |
| 399 | partial_install = functools.partial(_InstallOne, sysroot, options.debug) |
| 400 | pool = multiprocessing.Pool(processes=options.jobs) |
| 401 | pool.map(partial_install, args) |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 402 | |
Ralph Nathan | 5a582ff | 2015-03-20 18:18:30 -0700 | [diff] [blame] | 403 | logging.debug('installation done, updating packages index file') |
Bertrand SIMONNET | 6b6a131 | 2014-10-29 18:37:51 -0700 | [diff] [blame] | 404 | packages_dir = os.path.join(sysroot, 'packages') |
| 405 | packages_file = os.path.join(packages_dir, 'Packages') |
| 406 | # binpkg will set DEBUG_SYMBOLS automatically if it detects the debug symbols |
| 407 | # in the packages dir. |
| 408 | pkgindex = binpkg.GrabLocalPackageIndex(packages_dir) |
| 409 | with open(packages_file, 'w') as p: |
| 410 | pkgindex.Write(p) |