Blame view
tools/buildman/bsettings.py
2.49 KB
fc3fe1c28 buildman - U-Boot... |
1 2 |
# Copyright (c) 2012 The Chromium OS Authors. # |
1a4596601 Add GPL-2.0+ SPDX... |
3 |
# SPDX-License-Identifier: GPL-2.0+ |
fc3fe1c28 buildman - U-Boot... |
4 5 6 7 |
# import ConfigParser import os |
8b985eebd buildman: Avoid l... |
8 |
import StringIO |
fc3fe1c28 buildman - U-Boot... |
9 10 11 12 13 14 15 16 17 18 19 20 |
def Setup(fname=''): """Set up the buildman settings module by reading config files Args: config_fname: Config filename to read ('' for default) """ global settings global config_fname settings = ConfigParser.SafeConfigParser() |
8b985eebd buildman: Avoid l... |
21 22 23 24 |
if fname is not None: config_fname = fname if config_fname == '': config_fname = '%s/.buildman' % os.getenv('HOME') |
8e605a5e3 buildman: Automat... |
25 26 27 28 29 30 |
if not os.path.exists(config_fname): print 'No config file found ~/.buildman Creating one... ' CreateBuildmanConfigFile(config_fname) print 'To install tool chains, please use the --fetch-arch option' |
8b985eebd buildman: Avoid l... |
31 32 33 34 35 |
if config_fname: settings.read(config_fname) def AddFile(data): settings.readfp(StringIO.StringIO(data)) |
fc3fe1c28 buildman - U-Boot... |
36 37 38 39 40 41 42 43 44 45 46 47 48 |
def GetItems(section): """Get the items from a section of the config. Args: section: name of section to retrieve Returns: List of (name, value) tuples for the section """ try: return settings.items(section) except ConfigParser.NoSectionError as e: |
fc3fe1c28 buildman - U-Boot... |
49 50 51 |
return [] except: raise |
827e37b55 buildman: Add the... |
52 53 54 55 56 57 58 59 60 61 |
def SetItem(section, tag, value): """Set an item and write it back to the settings file""" global settings global config_fname settings.set(section, tag, value) if config_fname is not None: with open(config_fname, 'w') as fd: settings.write(fd) |
8e605a5e3 buildman: Automat... |
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
def CreateBuildmanConfigFile(config_fname): """Creates a new config file with no tool chain information. Args: config_fname: Config filename to create Returns: None """ try: f = open(config_fname, 'w') except IOError: print "Couldn't create buildman config file '%s' " % config_fname raise print >>f, '''[toolchain] # name = path # e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux [toolchain-prefix] # name = path to prefix # e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux/bin/x86_64-linux- [toolchain-alias] # arch = alias # Indicates which toolchain should be used to build for that arch x86 = i386 blackfin = bfin nds32 = nds32le openrisc = or1k [make-flags] # Special flags to pass to 'make' for certain boards, e.g. to pass a test # flag and build tag to snapper boards: # snapper-boards=ENABLE_AT91_TEST=1 # snapper9260=${snapper-boards} BUILD_TAG=442 # snapper9g45=${snapper-boards} BUILD_TAG=443 ''' f.close(); |