blob: 9b93b7a51e1bbb3944158596c95bd45211b6105b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glassfc3fe1c2013-04-03 11:07:16 +00002# Copyright (c) 2012 The Chromium OS Authors.
Simon Glassfc3fe1c2013-04-03 11:07:16 +00003
Simon Glassc05aa032019-10-31 07:42:53 -06004import configparser
Simon Glassfc3fe1c2013-04-03 11:07:16 +00005import os
Simon Glassc05aa032019-10-31 07:42:53 -06006import io
Simon Glassfc3fe1c2013-04-03 11:07:16 +00007
Simon Glass301cd742022-11-09 19:14:51 -07008config_fname = None
Simon Glassfc3fe1c2013-04-03 11:07:16 +00009
10def Setup(fname=''):
11 """Set up the buildman settings module by reading config files
12
13 Args:
14 config_fname: Config filename to read ('' for default)
15 """
16 global settings
17 global config_fname
18
Simon Glassc05aa032019-10-31 07:42:53 -060019 settings = configparser.SafeConfigParser()
Simon Glass8b985ee2014-09-05 19:00:15 -060020 if fname is not None:
21 config_fname = fname
22 if config_fname == '':
23 config_fname = '%s/.buildman' % os.getenv('HOME')
Simon Glass8e605a52016-07-27 20:32:59 -060024 if not os.path.exists(config_fname):
Simon Glassc05aa032019-10-31 07:42:53 -060025 print('No config file found ~/.buildman\nCreating one...\n')
Simon Glass8e605a52016-07-27 20:32:59 -060026 CreateBuildmanConfigFile(config_fname)
Simon Glassc05aa032019-10-31 07:42:53 -060027 print('To install tool chains, please use the --fetch-arch option')
Simon Glass8b985ee2014-09-05 19:00:15 -060028 if config_fname:
29 settings.read(config_fname)
30
31def AddFile(data):
Simon Glassc05aa032019-10-31 07:42:53 -060032 settings.readfp(io.StringIO(data))
Simon Glassfc3fe1c2013-04-03 11:07:16 +000033
34def GetItems(section):
35 """Get the items from a section of the config.
36
37 Args:
38 section: name of section to retrieve
39
40 Returns:
41 List of (name, value) tuples for the section
42 """
43 try:
44 return settings.items(section)
Simon Glassc05aa032019-10-31 07:42:53 -060045 except configparser.NoSectionError as e:
Simon Glassfc3fe1c2013-04-03 11:07:16 +000046 return []
47 except:
48 raise
Simon Glass827e37b2014-12-01 17:34:06 -070049
50def SetItem(section, tag, value):
51 """Set an item and write it back to the settings file"""
52 global settings
53 global config_fname
54
55 settings.set(section, tag, value)
56 if config_fname is not None:
57 with open(config_fname, 'w') as fd:
58 settings.write(fd)
Simon Glass8e605a52016-07-27 20:32:59 -060059
60def CreateBuildmanConfigFile(config_fname):
61 """Creates a new config file with no tool chain information.
62
63 Args:
64 config_fname: Config filename to create
65
66 Returns:
67 None
68 """
69 try:
70 f = open(config_fname, 'w')
71 except IOError:
Simon Glassc05aa032019-10-31 07:42:53 -060072 print("Couldn't create buildman config file '%s'\n" % config_fname)
Simon Glass8e605a52016-07-27 20:32:59 -060073 raise
74
Simon Glassc05aa032019-10-31 07:42:53 -060075 print('''[toolchain]
Simon Glass8e605a52016-07-27 20:32:59 -060076# name = path
77# e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux
Simon Glassfc8af382022-02-11 13:23:25 -070078other = /
Simon Glass8e605a52016-07-27 20:32:59 -060079
80[toolchain-prefix]
81# name = path to prefix
82# e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux/bin/x86_64-linux-
Simon Glass3da04ff2022-11-09 19:14:46 -070083# arc = /opt/arc/arc_gnu_2021.03_prebuilt_elf32_le_linux_install/bin/arc-elf32-
Simon Glass8e605a52016-07-27 20:32:59 -060084
85[toolchain-alias]
86# arch = alias
87# Indicates which toolchain should be used to build for that arch
Simon Glass3da04ff2022-11-09 19:14:46 -070088riscv = riscv32
89sh = sh4
Simon Glass8e605a52016-07-27 20:32:59 -060090x86 = i386
Simon Glass8e605a52016-07-27 20:32:59 -060091
92[make-flags]
93# Special flags to pass to 'make' for certain boards, e.g. to pass a test
94# flag and build tag to snapper boards:
95# snapper-boards=ENABLE_AT91_TEST=1
96# snapper9260=${snapper-boards} BUILD_TAG=442
97# snapper9g45=${snapper-boards} BUILD_TAG=443
Simon Glassc05aa032019-10-31 07:42:53 -060098''', file=f)
Simon Glass8e605a52016-07-27 20:32:59 -060099 f.close();