bsettings.py 2.5 KB

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