Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium OS Authors. |
| 3 | # |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 4 | |
Simon Glass | cc246fb | 2013-09-23 17:35:17 -0600 | [diff] [blame] | 5 | import re |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 6 | import glob |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 7 | from html.parser import HTMLParser |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 8 | import os |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 9 | import sys |
| 10 | import tempfile |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 11 | import urllib.request, urllib.error, urllib.parse |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 12 | |
Simon Glass | f0d9c10 | 2020-04-17 18:09:02 -0600 | [diff] [blame] | 13 | from buildman import bsettings |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 14 | from u_boot_pylib import command |
| 15 | from u_boot_pylib import terminal |
| 16 | from u_boot_pylib import tools |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 17 | |
Simon Glass | f590273 | 2016-03-12 18:50:32 -0700 | [diff] [blame] | 18 | (PRIORITY_FULL_PREFIX, PRIORITY_PREFIX_GCC, PRIORITY_PREFIX_GCC_PATH, |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 19 | PRIORITY_CALC) = list(range(4)) |
Simon Glass | 7b97129 | 2016-03-06 19:45:37 -0700 | [diff] [blame] | 20 | |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 21 | (VAR_CROSS_COMPILE, VAR_PATH, VAR_ARCH, VAR_MAKE_ARGS) = range(4) |
| 22 | |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 23 | # Simple class to collect links from a page |
| 24 | class MyHTMLParser(HTMLParser): |
| 25 | def __init__(self, arch): |
| 26 | """Create a new parser |
| 27 | |
| 28 | After the parser runs, self.links will be set to a list of the links |
| 29 | to .xz archives found in the page, and self.arch_link will be set to |
| 30 | the one for the given architecture (or None if not found). |
| 31 | |
| 32 | Args: |
| 33 | arch: Architecture to search for |
| 34 | """ |
| 35 | HTMLParser.__init__(self) |
| 36 | self.arch_link = None |
| 37 | self.links = [] |
Daniel Schwierzeck | 40261f9 | 2018-05-10 07:15:53 -0400 | [diff] [blame] | 38 | self.re_arch = re.compile('[-_]%s-' % arch) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 39 | |
| 40 | def handle_starttag(self, tag, attrs): |
| 41 | if tag == 'a': |
| 42 | for tag, value in attrs: |
| 43 | if tag == 'href': |
| 44 | if value and value.endswith('.xz'): |
| 45 | self.links.append(value) |
Daniel Schwierzeck | 40261f9 | 2018-05-10 07:15:53 -0400 | [diff] [blame] | 46 | if self.re_arch.search(value): |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 47 | self.arch_link = value |
| 48 | |
| 49 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 50 | class Toolchain: |
| 51 | """A single toolchain |
| 52 | |
| 53 | Public members: |
| 54 | gcc: Full path to C compiler |
| 55 | path: Directory path containing C compiler |
| 56 | cross: Cross compile string, e.g. 'arm-linux-' |
| 57 | arch: Architecture of toolchain as determined from the first |
| 58 | component of the filename. E.g. arm-linux-gcc becomes arm |
Simon Glass | 7b97129 | 2016-03-06 19:45:37 -0700 | [diff] [blame] | 59 | priority: Toolchain priority (0=highest, 20=lowest) |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 60 | override_toolchain: Toolchain to use for sandbox, overriding the normal |
| 61 | one |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 62 | """ |
Simon Glass | c6cdd3e | 2016-03-06 19:45:38 -0700 | [diff] [blame] | 63 | def __init__(self, fname, test, verbose=False, priority=PRIORITY_CALC, |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 64 | arch=None, override_toolchain=None): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 65 | """Create a new toolchain object. |
| 66 | |
| 67 | Args: |
| 68 | fname: Filename of the gcc component |
| 69 | test: True to run the toolchain to test it |
Simon Glass | d6ece32 | 2016-03-06 19:45:35 -0700 | [diff] [blame] | 70 | verbose: True to print out the information |
Simon Glass | 7b97129 | 2016-03-06 19:45:37 -0700 | [diff] [blame] | 71 | priority: Priority to use for this toolchain, or PRIORITY_CALC to |
| 72 | calculate it |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 73 | """ |
| 74 | self.gcc = fname |
| 75 | self.path = os.path.dirname(fname) |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 76 | self.override_toolchain = override_toolchain |
Simon Glass | 28ed006 | 2014-12-01 17:33:58 -0700 | [diff] [blame] | 77 | |
| 78 | # Find the CROSS_COMPILE prefix to use for U-Boot. For example, |
| 79 | # 'arm-linux-gnueabihf-gcc' turns into 'arm-linux-gnueabihf-'. |
| 80 | basename = os.path.basename(fname) |
| 81 | pos = basename.rfind('-') |
| 82 | self.cross = basename[:pos + 1] if pos != -1 else '' |
| 83 | |
| 84 | # The architecture is the first part of the name |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 85 | pos = self.cross.find('-') |
Simon Glass | c6cdd3e | 2016-03-06 19:45:38 -0700 | [diff] [blame] | 86 | if arch: |
| 87 | self.arch = arch |
| 88 | else: |
| 89 | self.arch = self.cross[:pos] if pos != -1 else 'sandbox' |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 90 | if self.arch == 'sandbox' and override_toolchain: |
| 91 | self.gcc = override_toolchain |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 92 | |
Tom Rini | 3f6f9b2 | 2024-07-05 14:34:07 -0600 | [diff] [blame] | 93 | env = self.MakeEnvironment(False) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 94 | |
| 95 | # As a basic sanity check, run the C compiler with --version |
| 96 | cmd = [fname, '--version'] |
Simon Glass | 7b97129 | 2016-03-06 19:45:37 -0700 | [diff] [blame] | 97 | if priority == PRIORITY_CALC: |
| 98 | self.priority = self.GetPriority(fname) |
| 99 | else: |
| 100 | self.priority = priority |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 101 | if test: |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 102 | result = command.run_pipe([cmd], capture=True, env=env, |
Stephen Warren | 288d767 | 2013-10-09 14:28:09 -0600 | [diff] [blame] | 103 | raise_on_error=False) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 104 | self.ok = result.return_code == 0 |
| 105 | if verbose: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 106 | print('Tool chain test: ', end=' ') |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 107 | if self.ok: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 108 | print("OK, arch='%s', priority %d" % (self.arch, |
| 109 | self.priority)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 110 | else: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 111 | print('BAD') |
| 112 | print('Command: ', cmd) |
| 113 | print(result.stdout) |
| 114 | print(result.stderr) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 115 | else: |
| 116 | self.ok = True |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 117 | |
| 118 | def GetPriority(self, fname): |
| 119 | """Return the priority of the toolchain. |
| 120 | |
| 121 | Toolchains are ranked according to their suitability by their |
| 122 | filename prefix. |
| 123 | |
| 124 | Args: |
| 125 | fname: Filename of toolchain |
| 126 | Returns: |
Simon Glass | 7b97129 | 2016-03-06 19:45:37 -0700 | [diff] [blame] | 127 | Priority of toolchain, PRIORITY_CALC=highest, 20=lowest. |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 128 | """ |
Masahiro Yamada | fa25e1f | 2014-07-07 09:47:45 +0900 | [diff] [blame] | 129 | priority_list = ['-elf', '-unknown-linux-gnu', '-linux', |
Tom Rini | 6abc9c8 | 2017-04-14 19:47:50 -0400 | [diff] [blame] | 130 | '-none-linux-gnueabi', '-none-linux-gnueabihf', '-uclinux', |
| 131 | '-none-eabi', '-gentoo-linux-gnu', '-linux-gnueabi', |
| 132 | '-linux-gnueabihf', '-le-linux', '-uclinux'] |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 133 | for prio in range(len(priority_list)): |
| 134 | if priority_list[prio] in fname: |
Simon Glass | 7b97129 | 2016-03-06 19:45:37 -0700 | [diff] [blame] | 135 | return PRIORITY_CALC + prio |
| 136 | return PRIORITY_CALC + prio |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 137 | |
York Sun | fb197a8 | 2016-10-04 14:33:51 -0700 | [diff] [blame] | 138 | def GetWrapper(self, show_warning=True): |
| 139 | """Get toolchain wrapper from the setting file. |
| 140 | """ |
Simon Glass | 4557263 | 2019-01-07 16:44:24 -0700 | [diff] [blame] | 141 | value = '' |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 142 | for name, value in bsettings.get_items('toolchain-wrapper'): |
York Sun | fb197a8 | 2016-10-04 14:33:51 -0700 | [diff] [blame] | 143 | if not value: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 144 | print("Warning: Wrapper not found") |
York Sun | fb197a8 | 2016-10-04 14:33:51 -0700 | [diff] [blame] | 145 | if value: |
| 146 | value = value + ' ' |
| 147 | |
| 148 | return value |
| 149 | |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 150 | def GetEnvArgs(self, which): |
| 151 | """Get an environment variable/args value based on the the toolchain |
| 152 | |
| 153 | Args: |
| 154 | which: VAR_... value to get |
| 155 | |
| 156 | Returns: |
| 157 | Value of that environment variable or arguments |
| 158 | """ |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 159 | if which == VAR_CROSS_COMPILE: |
Simon Glass | 09753b3 | 2023-03-10 12:48:51 -0800 | [diff] [blame] | 160 | wrapper = self.GetWrapper() |
| 161 | base = '' if self.arch == 'sandbox' else self.path |
Jerome Forissier | aa27695 | 2024-09-11 11:58:14 +0200 | [diff] [blame] | 162 | if (base == '' and self.cross == ''): |
| 163 | return '' |
Simon Glass | 09753b3 | 2023-03-10 12:48:51 -0800 | [diff] [blame] | 164 | return wrapper + os.path.join(base, self.cross) |
Simon Glass | 48ac42e | 2019-12-05 15:59:14 -0700 | [diff] [blame] | 165 | elif which == VAR_PATH: |
| 166 | return self.path |
| 167 | elif which == VAR_ARCH: |
| 168 | return self.arch |
| 169 | elif which == VAR_MAKE_ARGS: |
| 170 | args = self.MakeArgs() |
| 171 | if args: |
| 172 | return ' '.join(args) |
| 173 | return '' |
| 174 | else: |
| 175 | raise ValueError('Unknown arg to GetEnvArgs (%d)' % which) |
| 176 | |
Simon Glass | 038a3dd | 2024-08-15 13:57:44 -0600 | [diff] [blame] | 177 | def MakeEnvironment(self, full_path, env=None): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 178 | """Returns an environment for using the toolchain. |
| 179 | |
Simon Glass | 5822546 | 2024-06-23 11:56:19 -0600 | [diff] [blame] | 180 | This takes the current environment and adds CROSS_COMPILE so that |
Daniel Schwierzeck | c9e5f0c | 2017-06-08 03:07:08 +0200 | [diff] [blame] | 181 | the tool chain will operate correctly. This also disables localized |
Simon Glass | 5822546 | 2024-06-23 11:56:19 -0600 | [diff] [blame] | 182 | output and possibly Unicode encoded output of all build tools by |
Simon Glass | 038a3dd | 2024-08-15 13:57:44 -0600 | [diff] [blame] | 183 | adding LC_ALL=C. For the case where full_path is False, it prepends |
| 184 | the toolchain to PATH |
Simon Glass | d48a46c | 2014-12-01 17:34:00 -0700 | [diff] [blame] | 185 | |
Simon Glass | 93008e2 | 2021-04-11 16:27:28 +1200 | [diff] [blame] | 186 | Note that os.environb is used to obtain the environment, since in some |
| 187 | cases the environment many contain non-ASCII characters and we see |
| 188 | errors like: |
| 189 | |
| 190 | UnicodeEncodeError: 'utf-8' codec can't encode characters in position |
| 191 | 569-570: surrogates not allowed |
| 192 | |
Simon Glass | 038a3dd | 2024-08-15 13:57:44 -0600 | [diff] [blame] | 193 | When running inside a Python venv, care is taken not to put the |
| 194 | toolchain path before the venv path, so that builds initiated by |
| 195 | buildman will still respect the venv. |
| 196 | |
Simon Glass | d48a46c | 2014-12-01 17:34:00 -0700 | [diff] [blame] | 197 | Args: |
Tom Rini | 3f6f9b2 | 2024-07-05 14:34:07 -0600 | [diff] [blame] | 198 | full_path: Return the full path in CROSS_COMPILE and don't set |
| 199 | PATH |
Simon Glass | 038a3dd | 2024-08-15 13:57:44 -0600 | [diff] [blame] | 200 | env (dict of bytes): Original environment, used for testing |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 201 | Returns: |
Simon Glass | 93008e2 | 2021-04-11 16:27:28 +1200 | [diff] [blame] | 202 | Dict containing the (bytes) environment to use. This is based on the |
Tom Rini | 3f6f9b2 | 2024-07-05 14:34:07 -0600 | [diff] [blame] | 203 | current environment, with changes as needed to CROSS_COMPILE, PATH |
| 204 | and LC_ALL. |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 205 | """ |
Simon Glass | 038a3dd | 2024-08-15 13:57:44 -0600 | [diff] [blame] | 206 | env = dict(env or os.environb) |
| 207 | |
York Sun | fb197a8 | 2016-10-04 14:33:51 -0700 | [diff] [blame] | 208 | wrapper = self.GetWrapper() |
| 209 | |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 210 | if self.override_toolchain: |
| 211 | # We'll use MakeArgs() to provide this |
| 212 | pass |
Jerome Forissier | aa27695 | 2024-09-11 11:58:14 +0200 | [diff] [blame] | 213 | elif full_path and self.cross: |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 214 | env[b'CROSS_COMPILE'] = tools.to_bytes( |
Simon Glass | 93008e2 | 2021-04-11 16:27:28 +1200 | [diff] [blame] | 215 | wrapper + os.path.join(self.path, self.cross)) |
Jerome Forissier | aa27695 | 2024-09-11 11:58:14 +0200 | [diff] [blame] | 216 | elif self.cross: |
Tom Rini | 3f6f9b2 | 2024-07-05 14:34:07 -0600 | [diff] [blame] | 217 | env[b'CROSS_COMPILE'] = tools.to_bytes(wrapper + self.cross) |
Simon Glass | 038a3dd | 2024-08-15 13:57:44 -0600 | [diff] [blame] | 218 | |
| 219 | # Detect a Python virtualenv and avoid defeating it |
| 220 | if sys.prefix != sys.base_prefix: |
| 221 | paths = env[b'PATH'].split(b':') |
| 222 | new_paths = [] |
| 223 | to_insert = tools.to_bytes(self.path) |
| 224 | insert_after = tools.to_bytes(sys.prefix) |
| 225 | for path in paths: |
| 226 | new_paths.append(path) |
| 227 | if to_insert and path.startswith(insert_after): |
| 228 | new_paths.append(to_insert) |
| 229 | to_insert = None |
| 230 | if to_insert: |
| 231 | new_paths.append(to_insert) |
| 232 | env[b'PATH'] = b':'.join(new_paths) |
| 233 | else: |
| 234 | env[b'PATH'] = tools.to_bytes(self.path) + b':' + env[b'PATH'] |
Simon Glass | d48a46c | 2014-12-01 17:34:00 -0700 | [diff] [blame] | 235 | |
Simon Glass | 93008e2 | 2021-04-11 16:27:28 +1200 | [diff] [blame] | 236 | env[b'LC_ALL'] = b'C' |
Daniel Schwierzeck | c9e5f0c | 2017-06-08 03:07:08 +0200 | [diff] [blame] | 237 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 238 | return env |
| 239 | |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 240 | def MakeArgs(self): |
| 241 | """Create the 'make' arguments for a toolchain |
| 242 | |
| 243 | This is only used when the toolchain is being overridden. Since the |
| 244 | U-Boot Makefile sets CC and HOSTCC explicitly we cannot rely on the |
| 245 | environment (and MakeEnvironment()) to override these values. This |
| 246 | function returns the arguments to accomplish this. |
| 247 | |
| 248 | Returns: |
| 249 | List of arguments to pass to 'make' |
| 250 | """ |
| 251 | if self.override_toolchain: |
| 252 | return ['HOSTCC=%s' % self.override_toolchain, |
| 253 | 'CC=%s' % self.override_toolchain] |
| 254 | return [] |
| 255 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 256 | |
| 257 | class Toolchains: |
| 258 | """Manage a list of toolchains for building U-Boot |
| 259 | |
| 260 | We select one toolchain for each architecture type |
| 261 | |
| 262 | Public members: |
| 263 | toolchains: Dict of Toolchain objects, keyed by architecture name |
Simon Glass | f590273 | 2016-03-12 18:50:32 -0700 | [diff] [blame] | 264 | prefixes: Dict of prefixes to check, keyed by architecture. This can |
| 265 | be a full path and toolchain prefix, for example |
| 266 | {'x86', 'opt/i386-linux/bin/i386-linux-'}, or the name of |
| 267 | something on the search path, for example |
| 268 | {'arm', 'arm-linux-gnueabihf-'}. Wildcards are not supported. |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 269 | paths: List of paths to check for toolchains (may contain wildcards) |
| 270 | """ |
| 271 | |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 272 | def __init__(self, override_toolchain=None): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 273 | self.toolchains = {} |
Simon Glass | f590273 | 2016-03-12 18:50:32 -0700 | [diff] [blame] | 274 | self.prefixes = {} |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 275 | self.paths = [] |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 276 | self.override_toolchain = override_toolchain |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 277 | self._make_flags = dict(bsettings.get_items('make-flags')) |
Simon Glass | ed098bb | 2014-09-05 19:00:13 -0600 | [diff] [blame] | 278 | |
Simon Glass | f38a642 | 2016-07-27 20:33:01 -0600 | [diff] [blame] | 279 | def GetPathList(self, show_warning=True): |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 280 | """Get a list of available toolchain paths |
| 281 | |
Simon Glass | f38a642 | 2016-07-27 20:33:01 -0600 | [diff] [blame] | 282 | Args: |
| 283 | show_warning: True to show a warning if there are no tool chains. |
| 284 | |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 285 | Returns: |
| 286 | List of strings, each a path to a toolchain mentioned in the |
| 287 | [toolchain] section of the settings file. |
| 288 | """ |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 289 | toolchains = bsettings.get_items('toolchain') |
Simon Glass | f38a642 | 2016-07-27 20:33:01 -0600 | [diff] [blame] | 290 | if show_warning and not toolchains: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 291 | print(("Warning: No tool chains. Please run 'buildman " |
Simon Glass | 9f1ba0f | 2016-07-27 20:33:02 -0600 | [diff] [blame] | 292 | "--fetch-arch all' to download all available toolchains, or " |
| 293 | "add a [toolchain] section to your buildman config file " |
Heinrich Schuchardt | f04e800 | 2023-01-19 16:22:10 +0100 | [diff] [blame] | 294 | "%s. See buildman.rst for details" % |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 295 | bsettings.config_fname)) |
Simon Glass | cc246fb | 2013-09-23 17:35:17 -0600 | [diff] [blame] | 296 | |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 297 | paths = [] |
Simon Glass | cc246fb | 2013-09-23 17:35:17 -0600 | [diff] [blame] | 298 | for name, value in toolchains: |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 299 | if '*' in value: |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 300 | paths += glob.glob(value) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 301 | else: |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 302 | paths.append(value) |
| 303 | return paths |
| 304 | |
Simon Glass | f38a642 | 2016-07-27 20:33:01 -0600 | [diff] [blame] | 305 | def GetSettings(self, show_warning=True): |
| 306 | """Get toolchain settings from the settings file. |
| 307 | |
| 308 | Args: |
| 309 | show_warning: True to show a warning if there are no tool chains. |
| 310 | """ |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 311 | self.prefixes = bsettings.get_items('toolchain-prefix') |
Simon Glass | f38a642 | 2016-07-27 20:33:01 -0600 | [diff] [blame] | 312 | self.paths += self.GetPathList(show_warning) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 313 | |
Simon Glass | c6cdd3e | 2016-03-06 19:45:38 -0700 | [diff] [blame] | 314 | def Add(self, fname, test=True, verbose=False, priority=PRIORITY_CALC, |
| 315 | arch=None): |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 316 | """Add a toolchain to our list |
| 317 | |
| 318 | We select the given toolchain as our preferred one for its |
| 319 | architecture if it is a higher priority than the others. |
| 320 | |
| 321 | Args: |
| 322 | fname: Filename of toolchain's gcc driver |
| 323 | test: True to run the toolchain to test it |
Simon Glass | 7b97129 | 2016-03-06 19:45:37 -0700 | [diff] [blame] | 324 | priority: Priority to use for this toolchain |
Simon Glass | c6cdd3e | 2016-03-06 19:45:38 -0700 | [diff] [blame] | 325 | arch: Toolchain architecture, or None if not known |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 326 | """ |
Simon Glass | f77ca5b | 2019-01-07 16:44:20 -0700 | [diff] [blame] | 327 | toolchain = Toolchain(fname, test, verbose, priority, arch, |
| 328 | self.override_toolchain) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 329 | add_it = toolchain.ok |
| 330 | if toolchain.arch in self.toolchains: |
| 331 | add_it = (toolchain.priority < |
| 332 | self.toolchains[toolchain.arch].priority) |
| 333 | if add_it: |
| 334 | self.toolchains[toolchain.arch] = toolchain |
Simon Glass | 7b97129 | 2016-03-06 19:45:37 -0700 | [diff] [blame] | 335 | elif verbose: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 336 | print(("Toolchain '%s' at priority %d will be ignored because " |
Simon Glass | 7b97129 | 2016-03-06 19:45:37 -0700 | [diff] [blame] | 337 | "another toolchain for arch '%s' has priority %d" % |
| 338 | (toolchain.gcc, toolchain.priority, toolchain.arch, |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 339 | self.toolchains[toolchain.arch].priority))) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 340 | |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 341 | def ScanPath(self, path, verbose): |
| 342 | """Scan a path for a valid toolchain |
| 343 | |
| 344 | Args: |
| 345 | path: Path to scan |
| 346 | verbose: True to print out progress information |
| 347 | Returns: |
| 348 | Filename of C compiler if found, else None |
| 349 | """ |
Albert ARIBAUD | d4f22cf | 2015-02-01 00:12:44 +0100 | [diff] [blame] | 350 | fnames = [] |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 351 | for subdir in ['.', 'bin', 'usr/bin']: |
| 352 | dirname = os.path.join(path, subdir) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 353 | if verbose: print(" - looking in '%s'" % dirname) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 354 | for fname in glob.glob(dirname + '/*gcc'): |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 355 | if verbose: print(" - found '%s'" % fname) |
Albert ARIBAUD | d4f22cf | 2015-02-01 00:12:44 +0100 | [diff] [blame] | 356 | fnames.append(fname) |
| 357 | return fnames |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 358 | |
Simon Glass | f590273 | 2016-03-12 18:50:32 -0700 | [diff] [blame] | 359 | def ScanPathEnv(self, fname): |
| 360 | """Scan the PATH environment variable for a given filename. |
| 361 | |
| 362 | Args: |
| 363 | fname: Filename to scan for |
| 364 | Returns: |
| 365 | List of matching pathanames, or [] if none |
| 366 | """ |
| 367 | pathname_list = [] |
| 368 | for path in os.environ["PATH"].split(os.pathsep): |
| 369 | path = path.strip('"') |
| 370 | pathname = os.path.join(path, fname) |
| 371 | if os.path.exists(pathname): |
| 372 | pathname_list.append(pathname) |
| 373 | return pathname_list |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 374 | |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 375 | def Scan(self, verbose): |
| 376 | """Scan for available toolchains and select the best for each arch. |
| 377 | |
| 378 | We look for all the toolchains we can file, figure out the |
| 379 | architecture for each, and whether it works. Then we select the |
| 380 | highest priority toolchain for each arch. |
| 381 | |
| 382 | Args: |
| 383 | verbose: True to print out progress information |
| 384 | """ |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 385 | if verbose: print('Scanning for tool chains') |
Simon Glass | f590273 | 2016-03-12 18:50:32 -0700 | [diff] [blame] | 386 | for name, value in self.prefixes: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 387 | if verbose: print(" - scanning prefix '%s'" % value) |
Simon Glass | f590273 | 2016-03-12 18:50:32 -0700 | [diff] [blame] | 388 | if os.path.exists(value): |
| 389 | self.Add(value, True, verbose, PRIORITY_FULL_PREFIX, name) |
| 390 | continue |
| 391 | fname = value + 'gcc' |
| 392 | if os.path.exists(fname): |
| 393 | self.Add(fname, True, verbose, PRIORITY_PREFIX_GCC, name) |
| 394 | continue |
| 395 | fname_list = self.ScanPathEnv(fname) |
| 396 | for f in fname_list: |
| 397 | self.Add(f, True, verbose, PRIORITY_PREFIX_GCC_PATH, name) |
| 398 | if not fname_list: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 399 | raise ValueError("No tool chain found for prefix '%s'" % |
Simon Glass | f590273 | 2016-03-12 18:50:32 -0700 | [diff] [blame] | 400 | value) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 401 | for path in self.paths: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 402 | if verbose: print(" - scanning path '%s'" % path) |
Albert ARIBAUD | d4f22cf | 2015-02-01 00:12:44 +0100 | [diff] [blame] | 403 | fnames = self.ScanPath(path, verbose) |
| 404 | for fname in fnames: |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 405 | self.Add(fname, True, verbose) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 406 | |
| 407 | def List(self): |
| 408 | """List out the selected toolchains for each architecture""" |
Simon Glass | 9f1ba0f | 2016-07-27 20:33:02 -0600 | [diff] [blame] | 409 | col = terminal.Color() |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 410 | print(col.build(col.BLUE, 'List of available toolchains (%d):' % |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 411 | len(self.toolchains))) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 412 | if len(self.toolchains): |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 413 | for key, value in sorted(self.toolchains.items()): |
| 414 | print('%-10s: %s' % (key, value.gcc)) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 415 | else: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 416 | print('None') |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 417 | |
| 418 | def Select(self, arch): |
| 419 | """Returns the toolchain for a given architecture |
| 420 | |
| 421 | Args: |
| 422 | args: Name of architecture (e.g. 'arm', 'ppc_8xx') |
| 423 | |
| 424 | returns: |
| 425 | toolchain object, or None if none found |
| 426 | """ |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 427 | for tag, value in bsettings.get_items('toolchain-alias'): |
Simon Glass | c1528c1 | 2014-12-01 17:34:05 -0700 | [diff] [blame] | 428 | if arch == tag: |
| 429 | for alias in value.split(): |
| 430 | if alias in self.toolchains: |
| 431 | return self.toolchains[alias] |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 432 | |
| 433 | if not arch in self.toolchains: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 434 | raise ValueError("No tool chain found for arch '%s'" % arch) |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 435 | return self.toolchains[arch] |
Simon Glass | cc246fb | 2013-09-23 17:35:17 -0600 | [diff] [blame] | 436 | |
| 437 | def ResolveReferences(self, var_dict, args): |
| 438 | """Resolve variable references in a string |
| 439 | |
| 440 | This converts ${blah} within the string to the value of blah. |
| 441 | This function works recursively. |
| 442 | |
| 443 | Args: |
| 444 | var_dict: Dictionary containing variables and their values |
| 445 | args: String containing make arguments |
| 446 | Returns: |
| 447 | Resolved string |
| 448 | |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 449 | >>> bsettings.setup(None) |
Simon Glass | cc246fb | 2013-09-23 17:35:17 -0600 | [diff] [blame] | 450 | >>> tcs = Toolchains() |
| 451 | >>> tcs.Add('fred', False) |
| 452 | >>> var_dict = {'oblique' : 'OBLIQUE', 'first' : 'fi${second}rst', \ |
| 453 | 'second' : '2nd'} |
| 454 | >>> tcs.ResolveReferences(var_dict, 'this=${oblique}_set') |
| 455 | 'this=OBLIQUE_set' |
| 456 | >>> tcs.ResolveReferences(var_dict, 'this=${oblique}_set${first}nd') |
| 457 | 'this=OBLIQUE_setfi2ndrstnd' |
| 458 | """ |
Simon Glass | 53e189d | 2014-08-28 09:43:40 -0600 | [diff] [blame] | 459 | re_var = re.compile('(\$\{[-_a-z0-9A-Z]{1,}\})') |
Simon Glass | cc246fb | 2013-09-23 17:35:17 -0600 | [diff] [blame] | 460 | |
| 461 | while True: |
| 462 | m = re_var.search(args) |
| 463 | if not m: |
| 464 | break |
| 465 | lookup = m.group(0)[2:-1] |
| 466 | value = var_dict.get(lookup, '') |
| 467 | args = args[:m.start(0)] + value + args[m.end(0):] |
| 468 | return args |
| 469 | |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 470 | def GetMakeArguments(self, brd): |
Simon Glass | cc246fb | 2013-09-23 17:35:17 -0600 | [diff] [blame] | 471 | """Returns 'make' arguments for a given board |
| 472 | |
| 473 | The flags are in a section called 'make-flags'. Flags are named |
| 474 | after the target they represent, for example snapper9260=TESTING=1 |
| 475 | will pass TESTING=1 to make when building the snapper9260 board. |
| 476 | |
| 477 | References to other boards can be added in the string also. For |
| 478 | example: |
| 479 | |
| 480 | [make-flags] |
| 481 | at91-boards=ENABLE_AT91_TEST=1 |
| 482 | snapper9260=${at91-boards} BUILD_TAG=442 |
| 483 | snapper9g45=${at91-boards} BUILD_TAG=443 |
| 484 | |
| 485 | This will return 'ENABLE_AT91_TEST=1 BUILD_TAG=442' for snapper9260 |
| 486 | and 'ENABLE_AT91_TEST=1 BUILD_TAG=443' for snapper9g45. |
| 487 | |
| 488 | A special 'target' variable is set to the board target. |
| 489 | |
| 490 | Args: |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 491 | brd: Board object for the board to check. |
Simon Glass | cc246fb | 2013-09-23 17:35:17 -0600 | [diff] [blame] | 492 | Returns: |
| 493 | 'make' flags for that board, or '' if none |
| 494 | """ |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 495 | self._make_flags['target'] = brd.target |
Simon Glass | cc246fb | 2013-09-23 17:35:17 -0600 | [diff] [blame] | 496 | arg_str = self.ResolveReferences(self._make_flags, |
Simon Glass | 8132f98 | 2022-07-11 19:03:57 -0600 | [diff] [blame] | 497 | self._make_flags.get(brd.target, '')) |
Cristian Ciocaltea | 9da17fb | 2019-11-24 22:30:26 +0200 | [diff] [blame] | 498 | args = re.findall("(?:\".*?\"|\S)+", arg_str) |
Simon Glass | cc246fb | 2013-09-23 17:35:17 -0600 | [diff] [blame] | 499 | i = 0 |
| 500 | while i < len(args): |
Cristian Ciocaltea | 9da17fb | 2019-11-24 22:30:26 +0200 | [diff] [blame] | 501 | args[i] = args[i].replace('"', '') |
Simon Glass | cc246fb | 2013-09-23 17:35:17 -0600 | [diff] [blame] | 502 | if not args[i]: |
| 503 | del args[i] |
| 504 | else: |
| 505 | i += 1 |
| 506 | return args |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 507 | |
| 508 | def LocateArchUrl(self, fetch_arch): |
| 509 | """Find a toolchain available online |
| 510 | |
| 511 | Look in standard places for available toolchains. At present the |
| 512 | only standard place is at kernel.org. |
| 513 | |
| 514 | Args: |
| 515 | arch: Architecture to look for, or 'list' for all |
| 516 | Returns: |
| 517 | If fetch_arch is 'list', a tuple: |
| 518 | Machine architecture (e.g. x86_64) |
| 519 | List of toolchains |
| 520 | else |
| 521 | URL containing this toolchain, if avaialble, else None |
| 522 | """ |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 523 | arch = command.output_one_line('uname', '-m') |
Matthias Brugger | fb50a26 | 2020-01-17 10:53:37 +0100 | [diff] [blame] | 524 | if arch == 'aarch64': |
| 525 | arch = 'arm64' |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 526 | base = 'https://www.kernel.org/pub/tools/crosstool/files/bin' |
Tom Rini | 3bd5ed7 | 2023-08-25 13:21:26 -0400 | [diff] [blame] | 527 | versions = ['13.2.0', '12.2.0'] |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 528 | links = [] |
| 529 | for version in versions: |
| 530 | url = '%s/%s/%s/' % (base, arch, version) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 531 | print('Checking: %s' % url) |
| 532 | response = urllib.request.urlopen(url) |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 533 | html = tools.to_string(response.read()) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 534 | parser = MyHTMLParser(fetch_arch) |
| 535 | parser.feed(html) |
| 536 | if fetch_arch == 'list': |
| 537 | links += parser.links |
| 538 | elif parser.arch_link: |
| 539 | return url + parser.arch_link |
| 540 | if fetch_arch == 'list': |
| 541 | return arch, links |
| 542 | return None |
| 543 | |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 544 | def Unpack(self, fname, dest): |
| 545 | """Unpack a tar file |
| 546 | |
| 547 | Args: |
| 548 | fname: Filename to unpack |
| 549 | dest: Destination directory |
| 550 | Returns: |
| 551 | Directory name of the first entry in the archive, without the |
| 552 | trailing / |
| 553 | """ |
Simon Glass | 840be73 | 2022-01-29 14:14:05 -0700 | [diff] [blame] | 554 | stdout = command.output('tar', 'xvfJ', fname, '-C', dest) |
Trevor Woerner | e0557a7 | 2018-11-21 03:31:12 -0500 | [diff] [blame] | 555 | dirs = stdout.splitlines()[1].split('/')[:2] |
| 556 | return '/'.join(dirs) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 557 | |
| 558 | def TestSettingsHasPath(self, path): |
Simon Glass | 43ea128 | 2016-07-27 20:33:03 -0600 | [diff] [blame] | 559 | """Check if buildman will find this toolchain |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 560 | |
| 561 | Returns: |
| 562 | True if the path is in settings, False if not |
| 563 | """ |
Simon Glass | f38a642 | 2016-07-27 20:33:01 -0600 | [diff] [blame] | 564 | paths = self.GetPathList(False) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 565 | return path in paths |
| 566 | |
| 567 | def ListArchs(self): |
| 568 | """List architectures with available toolchains to download""" |
| 569 | host_arch, archives = self.LocateArchUrl('list') |
Trevor Woerner | 10a5162 | 2018-11-21 03:31:13 -0500 | [diff] [blame] | 570 | re_arch = re.compile('[-a-z0-9.]*[-_]([^-]*)-.*') |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 571 | arch_set = set() |
| 572 | for archive in archives: |
| 573 | # Remove the host architecture from the start |
| 574 | arch = re_arch.match(archive[len(host_arch):]) |
| 575 | if arch: |
Trevor Woerner | 10a5162 | 2018-11-21 03:31:13 -0500 | [diff] [blame] | 576 | if arch.group(1) != '2.0' and arch.group(1) != '64': |
| 577 | arch_set.add(arch.group(1)) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 578 | return sorted(arch_set) |
| 579 | |
| 580 | def FetchAndInstall(self, arch): |
| 581 | """Fetch and install a new toolchain |
| 582 | |
| 583 | arch: |
| 584 | Architecture to fetch, or 'list' to list |
| 585 | """ |
| 586 | # Fist get the URL for this architecture |
Simon Glass | 9f1ba0f | 2016-07-27 20:33:02 -0600 | [diff] [blame] | 587 | col = terminal.Color() |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 588 | print(col.build(col.BLUE, "Downloading toolchain for arch '%s'" % arch)) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 589 | url = self.LocateArchUrl(arch) |
| 590 | if not url: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 591 | print(("Cannot find toolchain for arch '%s' - use 'list' to list" % |
| 592 | arch)) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 593 | return 2 |
| 594 | home = os.environ['HOME'] |
| 595 | dest = os.path.join(home, '.buildman-toolchains') |
| 596 | if not os.path.exists(dest): |
| 597 | os.mkdir(dest) |
| 598 | |
| 599 | # Download the tar file for this toolchain and unpack it |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 600 | tarfile, tmpdir = tools.download(url, '.buildman') |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 601 | if not tarfile: |
| 602 | return 1 |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 603 | print(col.build(col.GREEN, 'Unpacking to: %s' % dest), end=' ') |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 604 | sys.stdout.flush() |
| 605 | path = self.Unpack(tarfile, dest) |
| 606 | os.remove(tarfile) |
| 607 | os.rmdir(tmpdir) |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 608 | print() |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 609 | |
| 610 | # Check that the toolchain works |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 611 | print(col.build(col.GREEN, 'Testing')) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 612 | dirpath = os.path.join(dest, path) |
Simon Glass | f675750 | 2015-03-02 17:05:15 -0700 | [diff] [blame] | 613 | compiler_fname_list = self.ScanPath(dirpath, True) |
| 614 | if not compiler_fname_list: |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 615 | print('Could not locate C compiler - fetch failed.') |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 616 | return 1 |
Simon Glass | f675750 | 2015-03-02 17:05:15 -0700 | [diff] [blame] | 617 | if len(compiler_fname_list) != 1: |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 618 | print(col.build(col.RED, 'Warning, ambiguous toolchains: %s' % |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 619 | ', '.join(compiler_fname_list))) |
Simon Glass | f675750 | 2015-03-02 17:05:15 -0700 | [diff] [blame] | 620 | toolchain = Toolchain(compiler_fname_list[0], True, True) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 621 | |
| 622 | # Make sure that it will be found by buildman |
| 623 | if not self.TestSettingsHasPath(dirpath): |
Simon Glass | c78ed66 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 624 | print(("Adding 'download' to config file '%s'" % |
| 625 | bsettings.config_fname)) |
Simon Glass | 06b83a5 | 2023-07-19 17:49:05 -0600 | [diff] [blame] | 626 | bsettings.set_item('toolchain', 'download', '%s/*/*' % dest) |
Simon Glass | 7e803e1 | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 627 | return 0 |