X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=tools%2Fbuildman%2Ftoolchain.py;h=27dc31889b8021c64d0af0d9bdf2898253e0b993;hb=0bd51251331a341dae8c19ae2e36a3262ae2ef72;hp=e0a697037ee18c341d639488497411e1fb8f60a8;hpb=fc3fe1c287fc5ee4c528b4059405571fcd2d55bd;p=u-boot diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py index e0a697037e..27dc31889b 100644 --- a/tools/buildman/toolchain.py +++ b/tools/buildman/toolchain.py @@ -1,24 +1,9 @@ # Copyright (c) 2012 The Chromium OS Authors. # -# See file CREDITS for list of people who contributed to this -# project. -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of -# the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, -# MA 02111-1307 USA +# SPDX-License-Identifier: GPL-2.0+ # +import re import glob import os @@ -54,7 +39,8 @@ class Toolchain: # As a basic sanity check, run the C compiler with --version cmd = [fname, '--version'] if test: - result = command.RunPipe([cmd], capture=True, env=env) + result = command.RunPipe([cmd], capture=True, env=env, + raise_on_error=False) self.ok = result.return_code == 0 if verbose: print 'Tool chain test: ', @@ -80,7 +66,7 @@ class Toolchain: Returns: Priority of toolchain, 0=highest, 20=lowest. """ - priority_list = ['-elf', '-unknown-linux-gnu', '-linux', '-elf', + priority_list = ['-elf', '-unknown-linux-gnu', '-linux', '-none-linux-gnueabi', '-uclinux', '-none-eabi', '-gentoo-linux-gnu', '-linux-gnueabi', '-le-linux', '-uclinux'] for prio in range(len(priority_list)): @@ -113,13 +99,21 @@ class Toolchains: def __init__(self): self.toolchains = {} self.paths = [] - for name, value in bsettings.GetItems('toolchain'): + self._make_flags = dict(bsettings.GetItems('make-flags')) + + def GetSettings(self): + toolchains = bsettings.GetItems('toolchain') + if not toolchains: + print ("Warning: No tool chains - please add a [toolchain] section" + " to your buildman config file %s. See README for details" % + bsettings.config_fname) + + for name, value in toolchains: if '*' in value: self.paths += glob.glob(value) else: self.paths.append(value) - def Add(self, fname, test=True, verbose=False): """Add a toolchain to our list @@ -183,3 +177,73 @@ class Toolchains: if not arch in self.toolchains: raise ValueError, ("No tool chain found for arch '%s'" % arch) return self.toolchains[arch] + + def ResolveReferences(self, var_dict, args): + """Resolve variable references in a string + + This converts ${blah} within the string to the value of blah. + This function works recursively. + + Args: + var_dict: Dictionary containing variables and their values + args: String containing make arguments + Returns: + Resolved string + + >>> bsettings.Setup() + >>> tcs = Toolchains() + >>> tcs.Add('fred', False) + >>> var_dict = {'oblique' : 'OBLIQUE', 'first' : 'fi${second}rst', \ + 'second' : '2nd'} + >>> tcs.ResolveReferences(var_dict, 'this=${oblique}_set') + 'this=OBLIQUE_set' + >>> tcs.ResolveReferences(var_dict, 'this=${oblique}_set${first}nd') + 'this=OBLIQUE_setfi2ndrstnd' + """ + re_var = re.compile('(\$\{[-_a-z0-9A-Z]{1,}\})') + + while True: + m = re_var.search(args) + if not m: + break + lookup = m.group(0)[2:-1] + value = var_dict.get(lookup, '') + args = args[:m.start(0)] + value + args[m.end(0):] + return args + + def GetMakeArguments(self, board): + """Returns 'make' arguments for a given board + + The flags are in a section called 'make-flags'. Flags are named + after the target they represent, for example snapper9260=TESTING=1 + will pass TESTING=1 to make when building the snapper9260 board. + + References to other boards can be added in the string also. For + example: + + [make-flags] + at91-boards=ENABLE_AT91_TEST=1 + snapper9260=${at91-boards} BUILD_TAG=442 + snapper9g45=${at91-boards} BUILD_TAG=443 + + This will return 'ENABLE_AT91_TEST=1 BUILD_TAG=442' for snapper9260 + and 'ENABLE_AT91_TEST=1 BUILD_TAG=443' for snapper9g45. + + A special 'target' variable is set to the board target. + + Args: + board: Board object for the board to check. + Returns: + 'make' flags for that board, or '' if none + """ + self._make_flags['target'] = board.target + arg_str = self.ResolveReferences(self._make_flags, + self._make_flags.get(board.target, '')) + args = arg_str.split(' ') + i = 0 + while i < len(args): + if not args[i]: + del args[i] + else: + i += 1 + return args