1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2012 The Chromium OS Authors.
11 """Set up the buildman settings module by reading config files
14 config_fname: Config filename to read ('' for default)
19 settings = configparser.ConfigParser()
22 if config_fname == '':
23 config_fname = '%s/.buildman' % os.getenv('HOME')
24 if not os.path.exists(config_fname):
25 print('No config file found ~/.buildman\nCreating one...\n')
26 create_buildman_config_file(config_fname)
27 print('To install tool chains, please use the --fetch-arch option')
29 settings.read(config_fname)
32 settings.read_file(io.StringIO(data))
34 def get_items(section):
35 """Get the items from a section of the config.
38 section: name of section to retrieve
41 List of (name, value) tuples for the section
44 return settings.items(section)
45 except configparser.NoSectionError as e:
50 def get_global_item_value(name):
51 """Get an item from the 'global' section of the config.
54 name: name of item to retrieve
57 str: Value of item, or None if not present
59 return settings.get('global', name, fallback=None)
61 def set_item(section, tag, value):
62 """Set an item and write it back to the settings file"""
66 settings.set(section, tag, value)
67 if config_fname is not None:
68 with open(config_fname, 'w') as fd:
71 def create_buildman_config_file(config_fname):
72 """Creates a new config file with no tool chain information.
75 config_fname: Config filename to create
81 f = open(config_fname, 'w')
83 print("Couldn't create buildman config file '%s'\n" % config_fname)
88 # e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux
92 # name = path to prefix
93 # e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux/bin/x86_64-linux-
97 # Indicates which toolchain should be used to build for that arch
103 # Special flags to pass to 'make' for certain boards, e.g. to pass a test
104 # flag and build tag to snapper boards:
105 # snapper-boards=ENABLE_AT91_TEST=1
106 # snapper9260=${snapper-boards} BUILD_TAG=442
107 # snapper9g45=${snapper-boards} BUILD_TAG=443