blob: 03d7439aa5436f5ee143a749808ec6bb2e94830d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glassc05694f2013-04-03 11:07:16 +00002# Copyright (c) 2012 The Chromium OS Authors.
Simon Glassc05694f2013-04-03 11:07:16 +00003
4import ConfigParser
5import os
Simon Glass5e0441d2014-09-05 19:00:15 -06006import StringIO
Simon Glassc05694f2013-04-03 11:07:16 +00007
8
9def 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
18 settings = ConfigParser.SafeConfigParser()
Simon Glass5e0441d2014-09-05 19:00:15 -060019 if fname is not None:
20 config_fname = fname
21 if config_fname == '':
22 config_fname = '%s/.buildman' % os.getenv('HOME')
Simon Glassdd195172016-07-27 20:32:59 -060023 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'
Simon Glass5e0441d2014-09-05 19:00:15 -060027 if config_fname:
28 settings.read(config_fname)
29
30def AddFile(data):
31 settings.readfp(StringIO.StringIO(data))
Simon Glassc05694f2013-04-03 11:07:16 +000032
33def 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)
44 except ConfigParser.NoSectionError as e:
Simon Glassc05694f2013-04-03 11:07:16 +000045 return []
46 except:
47 raise
Simon Glass7e803e12014-12-01 17:34:06 -070048
49def 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 Glassdd195172016-07-27 20:32:59 -060058
59def 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:
71 print "Couldn't create buildman config file '%s'\n" % config_fname
72 raise
73
74 print >>f, '''[toolchain]
75# name = path
76# e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux
77
78[toolchain-prefix]
79# name = path to prefix
80# e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux/bin/x86_64-linux-
81
82[toolchain-alias]
83# arch = alias
84# Indicates which toolchain should be used to build for that arch
85x86 = i386
86blackfin = bfin
87nds32 = nds32le
88openrisc = or1k
89
90[make-flags]
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
96'''
97 f.close();