bsettings.py 2.5 KB

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