Merge branch 'rmobile' of git://git.denx.de/u-boot-sh
[platform/kernel/u-boot.git] / tools / buildman / bsettings.py
1 # Copyright (c) 2012 The Chromium OS Authors.
2 #
3 # SPDX-License-Identifier:      GPL-2.0+
4 #
5
6 import ConfigParser
7 import os
8 import StringIO
9
10
11 def 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()
21     if fname is not None:
22         config_fname = fname
23         if config_fname == '':
24             config_fname = '%s/.buildman' % os.getenv('HOME')
25         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'
29         if config_fname:
30             settings.read(config_fname)
31
32 def AddFile(data):
33     settings.readfp(StringIO.StringIO(data))
34
35 def 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:
47         return []
48     except:
49         raise
50
51 def 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)
60
61 def 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
87 x86 = i386
88 blackfin = bfin
89 nds32 = nds32le
90 openrisc = 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();