blob: 892cfa09e241ef16023c57e32ec3eec72fd62c2a [file] [log] [blame]
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001# Copyright (c) 2012 The Chromium OS Authors.
2#
Wolfgang Denk1a459662013-07-08 09:37:19 +02003# SPDX-License-Identifier: GPL-2.0+
Simon Glassfc3fe1c2013-04-03 11:07:16 +00004#
5
6import ConfigParser
7import os
Simon Glass8b985ee2014-09-05 19:00:15 -06008import StringIO
Simon Glassfc3fe1c2013-04-03 11:07:16 +00009
10
11def Setup(fname=''):
12 """Set up the buildman settings module by reading config files
13
14 Args:
15 config_fname: Config filename to read ('' for default)
16 """
17 global settings
18 global config_fname
19
20 settings = ConfigParser.SafeConfigParser()
Simon Glass8b985ee2014-09-05 19:00:15 -060021 if fname is not None:
22 config_fname = fname
23 if config_fname == '':
24 config_fname = '%s/.buildman' % os.getenv('HOME')
Simon Glass8e605a52016-07-27 20:32:59 -060025 if not os.path.exists(config_fname):
26 print 'No config file found ~/.buildman\nCreating one...\n'
27 CreateBuildmanConfigFile(config_fname)
28 print 'To install tool chains, please use the --fetch-arch option'
Simon Glass8b985ee2014-09-05 19:00:15 -060029 if config_fname:
30 settings.read(config_fname)
31
32def AddFile(data):
33 settings.readfp(StringIO.StringIO(data))
Simon Glassfc3fe1c2013-04-03 11:07:16 +000034
35def GetItems(section):
36 """Get the items from a section of the config.
37
38 Args:
39 section: name of section to retrieve
40
41 Returns:
42 List of (name, value) tuples for the section
43 """
44 try:
45 return settings.items(section)
46 except ConfigParser.NoSectionError as e:
Simon Glassfc3fe1c2013-04-03 11:07:16 +000047 return []
48 except:
49 raise
Simon Glass827e37b2014-12-01 17:34:06 -070050
51def SetItem(section, tag, value):
52 """Set an item and write it back to the settings file"""
53 global settings
54 global config_fname
55
56 settings.set(section, tag, value)
57 if config_fname is not None:
58 with open(config_fname, 'w') as fd:
59 settings.write(fd)
Simon Glass8e605a52016-07-27 20:32:59 -060060
61def CreateBuildmanConfigFile(config_fname):
62 """Creates a new config file with no tool chain information.
63
64 Args:
65 config_fname: Config filename to create
66
67 Returns:
68 None
69 """
70 try:
71 f = open(config_fname, 'w')
72 except IOError:
73 print "Couldn't create buildman config file '%s'\n" % config_fname
74 raise
75
76 print >>f, '''[toolchain]
77# name = path
78# e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux
79
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-
83
84[toolchain-alias]
85# arch = alias
86# Indicates which toolchain should be used to build for that arch
87x86 = i386
88blackfin = bfin
89nds32 = nds32le
90openrisc = or1k
91
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
98'''
99 f.close();