newappend.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Recipe creation tool - newappend plugin
  2. #
  3. # This sub-command creates a bbappend for the specified target and prints the
  4. # path to the bbappend.
  5. #
  6. # Example: recipetool newappend meta-mylayer busybox
  7. #
  8. # Copyright (C) 2015 Christopher Larson <kergoth@gmail.com>
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License version 2 as
  12. # published by the Free Software Foundation.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. import argparse
  23. import errno
  24. import logging
  25. import os
  26. import re
  27. import subprocess
  28. import sys
  29. import scriptutils
  30. logger = logging.getLogger('recipetool')
  31. tinfoil = None
  32. def tinfoil_init(instance):
  33. global tinfoil
  34. tinfoil = instance
  35. def layer(layerpath):
  36. if not os.path.exists(os.path.join(layerpath, 'conf', 'layer.conf')):
  37. raise argparse.ArgumentTypeError('{0!r} must be a path to a valid layer'.format(layerpath))
  38. return layerpath
  39. def newappend(args):
  40. import oe.recipeutils
  41. recipe_path = tinfoil.get_recipe_file(args.target)
  42. rd = tinfoil.config_data.createCopy()
  43. rd.setVar('FILE', recipe_path)
  44. append_path, path_ok = oe.recipeutils.get_bbappend_path(rd, args.destlayer, args.wildcard_version)
  45. if not append_path:
  46. logger.error('Unable to determine layer directory containing %s', recipe_path)
  47. return 1
  48. if not path_ok:
  49. logger.warning('Unable to determine correct subdirectory path for bbappend file - check that what %s adds to BBFILES also matches .bbappend files. Using %s for now, but until you fix this the bbappend will not be applied.', os.path.join(args.destlayer, 'conf', 'layer.conf'), os.path.dirname(append_path))
  50. layerdirs = [os.path.abspath(layerdir) for layerdir in rd.getVar('BBLAYERS').split()]
  51. if not os.path.abspath(args.destlayer) in layerdirs:
  52. logger.warning('Specified layer is not currently enabled in bblayers.conf, you will need to add it before this bbappend will be active')
  53. if not os.path.exists(append_path):
  54. bb.utils.mkdirhier(os.path.dirname(append_path))
  55. try:
  56. open(append_path, 'a').close()
  57. except (OSError, IOError) as exc:
  58. logger.critical(str(exc))
  59. return 1
  60. if args.edit:
  61. return scriptutils.run_editor([append_path, recipe_path], logger)
  62. else:
  63. print(append_path)
  64. def register_commands(subparsers):
  65. parser = subparsers.add_parser('newappend',
  66. help='Create a bbappend for the specified target in the specified layer')
  67. parser.add_argument('-e', '--edit', help='Edit the new append. This obeys $VISUAL if set, otherwise $EDITOR, otherwise vi.', action='store_true')
  68. parser.add_argument('-w', '--wildcard-version', help='Use wildcard to make the bbappend apply to any recipe version', action='store_true')
  69. parser.add_argument('destlayer', help='Base directory of the destination layer to write the bbappend to', type=layer)
  70. parser.add_argument('target', help='Target recipe/provide to append')
  71. parser.set_defaults(func=newappend, parserecipes=True)