Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium OS Authors. |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 3 | |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 4 | import configparser |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 5 | import os |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 6 | import io |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 7 | |
| 8 | |
| 9 | def Setup(fname=''): |
| 10 | """Set up the buildman settings module by reading config files |
| 11 | |
| 12 | Args: |
| 13 | config_fname: Config filename to read ('' for default) |
| 14 | """ |
| 15 | global settings |
| 16 | global config_fname |
| 17 | |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 18 | settings = configparser.SafeConfigParser() |
Simon Glass | 8b985ee | 2014-09-05 19:00:15 -0600 | [diff] [blame] | 19 | if fname is not None: |
| 20 | config_fname = fname |
| 21 | if config_fname == '': |
| 22 | config_fname = '%s/.buildman' % os.getenv('HOME') |
Simon Glass | 8e605a5 | 2016-07-27 20:32:59 -0600 | [diff] [blame] | 23 | if not os.path.exists(config_fname): |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 24 | print('No config file found ~/.buildman\nCreating one...\n') |
Simon Glass | 8e605a5 | 2016-07-27 20:32:59 -0600 | [diff] [blame] | 25 | CreateBuildmanConfigFile(config_fname) |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 26 | print('To install tool chains, please use the --fetch-arch option') |
Simon Glass | 8b985ee | 2014-09-05 19:00:15 -0600 | [diff] [blame] | 27 | if config_fname: |
| 28 | settings.read(config_fname) |
| 29 | |
| 30 | def AddFile(data): |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 31 | settings.readfp(io.StringIO(data)) |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 32 | |
| 33 | def GetItems(section): |
| 34 | """Get the items from a section of the config. |
| 35 | |
| 36 | Args: |
| 37 | section: name of section to retrieve |
| 38 | |
| 39 | Returns: |
| 40 | List of (name, value) tuples for the section |
| 41 | """ |
| 42 | try: |
| 43 | return settings.items(section) |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 44 | except configparser.NoSectionError as e: |
Simon Glass | fc3fe1c | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 45 | return [] |
| 46 | except: |
| 47 | raise |
Simon Glass | 827e37b | 2014-12-01 17:34:06 -0700 | [diff] [blame] | 48 | |
| 49 | def SetItem(section, tag, value): |
| 50 | """Set an item and write it back to the settings file""" |
| 51 | global settings |
| 52 | global config_fname |
| 53 | |
| 54 | settings.set(section, tag, value) |
| 55 | if config_fname is not None: |
| 56 | with open(config_fname, 'w') as fd: |
| 57 | settings.write(fd) |
Simon Glass | 8e605a5 | 2016-07-27 20:32:59 -0600 | [diff] [blame] | 58 | |
| 59 | def CreateBuildmanConfigFile(config_fname): |
| 60 | """Creates a new config file with no tool chain information. |
| 61 | |
| 62 | Args: |
| 63 | config_fname: Config filename to create |
| 64 | |
| 65 | Returns: |
| 66 | None |
| 67 | """ |
| 68 | try: |
| 69 | f = open(config_fname, 'w') |
| 70 | except IOError: |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 71 | print("Couldn't create buildman config file '%s'\n" % config_fname) |
Simon Glass | 8e605a5 | 2016-07-27 20:32:59 -0600 | [diff] [blame] | 72 | raise |
| 73 | |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 74 | print('''[toolchain] |
Simon Glass | 8e605a5 | 2016-07-27 20:32:59 -0600 | [diff] [blame] | 75 | # name = path |
| 76 | # e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux |
Simon Glass | fc8af38 | 2022-02-11 13:23:25 -0700 | [diff] [blame] | 77 | other = / |
Simon Glass | 8e605a5 | 2016-07-27 20:32:59 -0600 | [diff] [blame] | 78 | |
| 79 | [toolchain-prefix] |
| 80 | # name = path to prefix |
| 81 | # e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux/bin/x86_64-linux- |
| 82 | |
| 83 | [toolchain-alias] |
| 84 | # arch = alias |
| 85 | # Indicates which toolchain should be used to build for that arch |
| 86 | x86 = i386 |
| 87 | blackfin = bfin |
| 88 | nds32 = nds32le |
| 89 | openrisc = or1k |
| 90 | |
| 91 | [make-flags] |
| 92 | # Special flags to pass to 'make' for certain boards, e.g. to pass a test |
| 93 | # flag and build tag to snapper boards: |
| 94 | # snapper-boards=ENABLE_AT91_TEST=1 |
| 95 | # snapper9260=${snapper-boards} BUILD_TAG=442 |
| 96 | # snapper9g45=${snapper-boards} BUILD_TAG=443 |
Simon Glass | c05aa03 | 2019-10-31 07:42:53 -0600 | [diff] [blame] | 97 | ''', file=f) |
Simon Glass | 8e605a5 | 2016-07-27 20:32:59 -0600 | [diff] [blame] | 98 | f.close(); |