blob: 76707b4c91b1ae7843df5081a98bae7000e10875 [file] [log] [blame]
Patrick Williamsd7e96312015-09-22 08:09:05 -05001# 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
23import argparse
24import errno
25import logging
26import os
27import re
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050028import subprocess
Patrick Williamsd7e96312015-09-22 08:09:05 -050029import sys
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050030import scriptutils
Patrick Williamsd7e96312015-09-22 08:09:05 -050031
32
33logger = logging.getLogger('recipetool')
34tinfoil = None
35
36
Patrick Williamsd7e96312015-09-22 08:09:05 -050037def tinfoil_init(instance):
38 global tinfoil
39 tinfoil = instance
40
41
Patrick Williamsd7e96312015-09-22 08:09:05 -050042def layer(layerpath):
43 if not os.path.exists(os.path.join(layerpath, 'conf', 'layer.conf')):
44 raise argparse.ArgumentTypeError('{0!r} must be a path to a valid layer'.format(layerpath))
45 return layerpath
46
47
48def newappend(args):
49 import oe.recipeutils
50
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051 recipe_path = tinfoil.get_recipe_file(args.target)
Patrick Williamsd7e96312015-09-22 08:09:05 -050052
53 rd = tinfoil.config_data.createCopy()
54 rd.setVar('FILE', recipe_path)
55 append_path, path_ok = oe.recipeutils.get_bbappend_path(rd, args.destlayer, args.wildcard_version)
56 if not append_path:
57 logger.error('Unable to determine layer directory containing %s', recipe_path)
58 return 1
59
60 if not path_ok:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080061 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))
Patrick Williamsd7e96312015-09-22 08:09:05 -050062
Brad Bishop6e60e8b2018-02-01 10:27:11 -050063 layerdirs = [os.path.abspath(layerdir) for layerdir in rd.getVar('BBLAYERS').split()]
Patrick Williamsd7e96312015-09-22 08:09:05 -050064 if not os.path.abspath(args.destlayer) in layerdirs:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080065 logger.warning('Specified layer is not currently enabled in bblayers.conf, you will need to add it before this bbappend will be active')
Patrick Williamsd7e96312015-09-22 08:09:05 -050066
67 if not os.path.exists(append_path):
68 bb.utils.mkdirhier(os.path.dirname(append_path))
69
70 try:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050071 open(append_path, 'a').close()
Patrick Williamsd7e96312015-09-22 08:09:05 -050072 except (OSError, IOError) as exc:
73 logger.critical(str(exc))
74 return 1
75
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050076 if args.edit:
Brad Bishopd7bf8c12018-02-25 22:55:05 -050077 return scriptutils.run_editor([append_path, recipe_path], logger)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050078 else:
79 print(append_path)
Patrick Williamsd7e96312015-09-22 08:09:05 -050080
81
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050082def register_commands(subparsers):
Patrick Williamsd7e96312015-09-22 08:09:05 -050083 parser = subparsers.add_parser('newappend',
84 help='Create a bbappend for the specified target in the specified layer')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050085 parser.add_argument('-e', '--edit', help='Edit the new append. This obeys $VISUAL if set, otherwise $EDITOR, otherwise vi.', action='store_true')
Patrick Williamsd7e96312015-09-22 08:09:05 -050086 parser.add_argument('-w', '--wildcard-version', help='Use wildcard to make the bbappend apply to any recipe version', action='store_true')
87 parser.add_argument('destlayer', help='Base directory of the destination layer to write the bbappend to', type=layer)
88 parser.add_argument('target', help='Target recipe/provide to append')
89 parser.set_defaults(func=newappend, parserecipes=True)