1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2012 The Chromium OS Authors.
10 """Set up the buildman settings module by reading config files
13 config_fname: Config filename to read ('' for default)
18 settings = ConfigParser.SafeConfigParser()
21 if config_fname == '':
22 config_fname = '%s/.buildman' % os.getenv('HOME')
23 if not os.path.exists(config_fname):
24 print 'No config file found ~/.buildman\nCreating one...\n'
25 CreateBuildmanConfigFile(config_fname)
26 print 'To install tool chains, please use the --fetch-arch option'
28 settings.read(config_fname)
31 settings.readfp(StringIO.StringIO(data))
33 def GetItems(section):
34 """Get the items from a section of the config.
37 section: name of section to retrieve
40 List of (name, value) tuples for the section
43 return settings.items(section)
44 except ConfigParser.NoSectionError as e:
49 def SetItem(section, tag, value):
50 """Set an item and write it back to the settings file"""
54 settings.set(section, tag, value)
55 if config_fname is not None:
56 with open(config_fname, 'w') as fd:
59 def CreateBuildmanConfigFile(config_fname):
60 """Creates a new config file with no tool chain information.
63 config_fname: Config filename to create
69 f = open(config_fname, 'w')
71 print "Couldn't create buildman config file '%s'\n" % config_fname
74 print >>f, '''[toolchain]
76 # e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux
79 # name = path to prefix
80 # e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux/bin/x86_64-linux-
84 # Indicates which toolchain should be used to build for that arch
91 # Special flags to pass to 'make' for certain boards, e.g. to pass a test
92 # flag and build tag to snapper boards:
93 # snapper-boards=ENABLE_AT91_TEST=1
94 # snapper9260=${snapper-boards} BUILD_TAG=442
95 # snapper9g45=${snapper-boards} BUILD_TAG=443