buildconf.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: GPL-2.0-only
  5. #
  6. import logging
  7. import os
  8. import sys
  9. from bblayers.common import LayerPlugin
  10. logger = logging.getLogger('bitbake-layers')
  11. sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
  12. import oe.buildcfg
  13. def plugin_init(plugins):
  14. return BuildConfPlugin()
  15. class BuildConfPlugin(LayerPlugin):
  16. notes_fixme = """FIXME: Please place here the detailed instructions for using this build configuration.
  17. They will be shown to the users when they set up their builds via TEMPLATECONF.
  18. """
  19. summary_fixme = """FIXME: Please place here the short summary of what this build configuration is for.
  20. It will be shown to the users when they set up their builds via TEMPLATECONF.
  21. """
  22. def _save_conf(self, templatename, templatepath, oecorepath, relpaths_to_oecore):
  23. confdir = os.path.join(os.environ["BBPATH"], "conf")
  24. destdir = os.path.join(templatepath, "conf", "templates", templatename)
  25. os.makedirs(destdir, exist_ok=True)
  26. with open(os.path.join(confdir, "local.conf")) as src:
  27. with open(os.path.join(destdir, "local.conf.sample"), 'w') as dest:
  28. dest.write(src.read())
  29. with open(os.path.join(confdir, "bblayers.conf")) as src:
  30. with open(os.path.join(destdir, "bblayers.conf.sample"), 'w') as dest:
  31. bblayers_data = src.read()
  32. for (abspath, relpath) in relpaths_to_oecore:
  33. bblayers_data = bblayers_data.replace(abspath, "##OEROOT##/" + relpath)
  34. dest.write(bblayers_data)
  35. with open(os.path.join(destdir, "conf-summary.txt"), 'w') as dest:
  36. dest.write(self.summary_fixme)
  37. with open(os.path.join(destdir, "conf-notes.txt"), 'w') as dest:
  38. dest.write(self.notes_fixme)
  39. logger.info("""Configuration template placed into {}
  40. Please review the files in there, and particularly provide a configuration summary in {}
  41. and notes in {}
  42. You can try out the configuration with
  43. TEMPLATECONF={} . {}/oe-init-build-env build-try-{}"""
  44. .format(destdir, os.path.join(destdir, "conf-summary.txt"), os.path.join(destdir, "conf-notes.txt"), destdir, oecorepath, templatename))
  45. def do_save_build_conf(self, args):
  46. """ Save the currently active build configuration (conf/local.conf, conf/bblayers.conf) as a template into a layer.\n This template can later be used for setting up builds via TEMPLATECONF. """
  47. layers = oe.buildcfg.get_layer_revisions(self.tinfoil.config_data)
  48. targetlayer = None
  49. oecore = None
  50. for l in layers:
  51. if os.path.abspath(l[0]) == os.path.abspath(args.layerpath):
  52. targetlayer = l[0]
  53. if l[1] == 'meta':
  54. oecore = os.path.dirname(l[0])
  55. if not targetlayer:
  56. logger.error("Layer {} not in one of the currently enabled layers:\n{}".format(args.layerpath, "\n".join([l[0] for l in layers])))
  57. elif not oecore:
  58. logger.error("Openembedded-core not in one of the currently enabled layers:\n{}".format("\n".join([l[0] for l in layers])))
  59. else:
  60. relpaths_to_oecore = [(l[0], os.path.relpath(l[0], start=oecore)) for l in layers]
  61. self._save_conf(args.templatename, targetlayer, oecore, relpaths_to_oecore)
  62. def register_commands(self, sp):
  63. parser_build_conf = self.add_command(sp, 'save-build-conf', self.do_save_build_conf, parserecipes=False)
  64. parser_build_conf.add_argument('layerpath',
  65. help='The path to the layer where the configuration template should be saved.')
  66. parser_build_conf.add_argument('templatename',
  67. help='The name of the configuration template.')