summaryrefslogtreecommitdiffstats
path: root/scripts/lib/devtool/standard.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/devtool/standard.py')
-rw-r--r--scripts/lib/devtool/standard.py154
1 files changed, 70 insertions, 84 deletions
diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py
index 14912a9454..4d3ff02be8 100644
--- a/scripts/lib/devtool/standard.py
+++ b/scripts/lib/devtool/standard.py
@@ -25,16 +25,11 @@ import logging
25import argparse 25import argparse
26import scriptutils 26import scriptutils
27import errno 27import errno
28from devtool import exec_build_env_command, setup_tinfoil 28from devtool import exec_build_env_command, setup_tinfoil, DevtoolError
29 29
30logger = logging.getLogger('devtool') 30logger = logging.getLogger('devtool')
31 31
32 32
33class DevtoolError(Exception):
34 """Exception for handling devtool errors"""
35 pass
36
37
38def plugin_init(pluginlist): 33def plugin_init(pluginlist):
39 """Plugin initialization""" 34 """Plugin initialization"""
40 pass 35 pass
@@ -46,26 +41,27 @@ def add(args, config, basepath, workspace):
46 import oe.recipeutils 41 import oe.recipeutils
47 42
48 if args.recipename in workspace: 43 if args.recipename in workspace:
49 logger.error("recipe %s is already in your workspace" % args.recipename) 44 raise DevtoolError("recipe %s is already in your workspace" %
50 return -1 45 args.recipename)
51 46
52 reason = oe.recipeutils.validate_pn(args.recipename) 47 reason = oe.recipeutils.validate_pn(args.recipename)
53 if reason: 48 if reason:
54 logger.error(reason) 49 raise DevtoolError(reason)
55 return -1
56 50
57 srctree = os.path.abspath(args.srctree) 51 srctree = os.path.abspath(args.srctree)
58 if os.path.exists(srctree): 52 if os.path.exists(srctree):
59 if args.fetch: 53 if args.fetch:
60 if not os.path.isdir(srctree): 54 if not os.path.isdir(srctree):
61 logger.error("Cannot fetch into source tree path %s as it exists and is not a directory" % srctree) 55 raise DevtoolError("Cannot fetch into source tree path %s as "
62 return 1 56 "it exists and is not a directory" %
57 srctree)
63 elif os.listdir(srctree): 58 elif os.listdir(srctree):
64 logger.error("Cannot fetch into source tree path %s as it already exists and is non-empty" % srctree) 59 raise DevtoolError("Cannot fetch into source tree path %s as "
65 return 1 60 "it already exists and is non-empty" %
61 srctree)
66 elif not args.fetch: 62 elif not args.fetch:
67 logger.error("Specified source tree %s could not be found" % srctree) 63 raise DevtoolError("Specified source tree %s could not be found" %
68 return 1 64 srctree)
69 65
70 appendpath = os.path.join(config.workspace_path, 'appends') 66 appendpath = os.path.join(config.workspace_path, 'appends')
71 if not os.path.exists(appendpath): 67 if not os.path.exists(appendpath):
@@ -76,8 +72,7 @@ def add(args, config, basepath, workspace):
76 rfv = None 72 rfv = None
77 if args.version: 73 if args.version:
78 if '_' in args.version or ' ' in args.version: 74 if '_' in args.version or ' ' in args.version:
79 logger.error('Invalid version string "%s"' % args.version) 75 raise DevtoolError('Invalid version string "%s"' % args.version)
80 return -1
81 rfv = args.version 76 rfv = args.version
82 if args.fetch: 77 if args.fetch:
83 if args.fetch.startswith('git://'): 78 if args.fetch.startswith('git://'):
@@ -107,8 +102,7 @@ def add(args, config, basepath, workspace):
107 stdout, _ = exec_build_env_command(config.init_path, basepath, 'recipetool --color=%s create -o %s "%s" %s' % (color, recipefile, source, extracmdopts)) 102 stdout, _ = exec_build_env_command(config.init_path, basepath, 'recipetool --color=%s create -o %s "%s" %s' % (color, recipefile, source, extracmdopts))
108 logger.info('Recipe %s has been automatically created; further editing may be required to make it fully functional' % recipefile) 103 logger.info('Recipe %s has been automatically created; further editing may be required to make it fully functional' % recipefile)
109 except bb.process.ExecutionError as e: 104 except bb.process.ExecutionError as e:
110 logger.error('Command \'%s\' failed:\n%s' % (e.command, e.stdout)) 105 raise DevtoolError('Command \'%s\' failed:\n%s' % (e.command, e.stdout))
111 return 1
112 106
113 _add_md5(config, args.recipename, recipefile) 107 _add_md5(config, args.recipename, recipefile)
114 108
@@ -134,35 +128,33 @@ def add(args, config, basepath, workspace):
134def _check_compatible_recipe(pn, d): 128def _check_compatible_recipe(pn, d):
135 """Check if the recipe is supported by devtool""" 129 """Check if the recipe is supported by devtool"""
136 if pn == 'perf': 130 if pn == 'perf':
137 logger.error("The perf recipe does not actually check out source and thus cannot be supported by this tool") 131 raise DevtoolError("The perf recipe does not actually check out "
138 return False 132 "source and thus cannot be supported by this tool")
139 133
140 if pn in ['kernel-devsrc', 'package-index'] or pn.startswith('gcc-source'): 134 if pn in ['kernel-devsrc', 'package-index'] or pn.startswith('gcc-source'):
141 logger.error("The %s recipe is not supported by this tool" % pn) 135 raise DevtoolError("The %s recipe is not supported by this tool" % pn)
142 return False
143 136
144 if bb.data.inherits_class('image', d): 137 if bb.data.inherits_class('image', d):
145 logger.error("The %s recipe is an image, and therefore is not supported by this tool" % pn) 138 raise DevtoolError("The %s recipe is an image, and therefore is not "
146 return False 139 "supported by this tool" % pn)
147 140
148 if bb.data.inherits_class('populate_sdk', d): 141 if bb.data.inherits_class('populate_sdk', d):
149 logger.error("The %s recipe is an SDK, and therefore is not supported by this tool" % pn) 142 raise DevtoolError("The %s recipe is an SDK, and therefore is not "
150 return False 143 "supported by this tool" % pn)
151 144
152 if bb.data.inherits_class('packagegroup', d): 145 if bb.data.inherits_class('packagegroup', d):
153 logger.error("The %s recipe is a packagegroup, and therefore is not supported by this tool" % pn) 146 raise DevtoolError("The %s recipe is a packagegroup, and therefore is "
154 return False 147 "not supported by this tool" % pn)
155 148
156 if bb.data.inherits_class('meta', d): 149 if bb.data.inherits_class('meta', d):
157 logger.error("The %s recipe is a meta-recipe, and therefore is not supported by this tool" % pn) 150 raise DevtoolError("The %s recipe is a meta-recipe, and therefore is "
158 return False 151 "not supported by this tool" % pn)
159 152
160 if bb.data.inherits_class('externalsrc', d) and d.getVar('EXTERNALSRC', True): 153 if bb.data.inherits_class('externalsrc', d) and d.getVar('EXTERNALSRC', True):
161 logger.error("externalsrc is currently enabled for the %s recipe. This prevents the normal do_patch task from working. You will need to disable this first." % pn) 154 raise DevtoolError("externalsrc is currently enabled for the %s "
162 return False 155 "recipe. This prevents the normal do_patch task "
163 156 "from working. You will need to disable this "
164 return True 157 "first." % pn)
165
166 158
167def _get_recipe_file(cooker, pn): 159def _get_recipe_file(cooker, pn):
168 """Find recipe file corresponding a package name""" 160 """Find recipe file corresponding a package name"""
@@ -209,14 +201,14 @@ def extract(args, config, basepath, workspace):
209 201
210 rd = _parse_recipe(config, tinfoil, args.recipename, True) 202 rd = _parse_recipe(config, tinfoil, args.recipename, True)
211 if not rd: 203 if not rd:
212 return -1 204 return 1
213 205
214 srctree = os.path.abspath(args.srctree) 206 srctree = os.path.abspath(args.srctree)
215 initial_rev = _extract_source(srctree, args.keep_temp, args.branch, rd) 207 initial_rev = _extract_source(srctree, args.keep_temp, args.branch, rd)
216 if initial_rev: 208 if initial_rev:
217 return 0 209 return 0
218 else: 210 else:
219 return -1 211 return 1
220 212
221class BbTaskExecutor(object): 213class BbTaskExecutor(object):
222 """Class for executing bitbake tasks for a recipe 214 """Class for executing bitbake tasks for a recipe
@@ -262,16 +254,15 @@ def _extract_source(srctree, keep_temp, devbranch, d):
262 254
263 pn = d.getVar('PN', True) 255 pn = d.getVar('PN', True)
264 256
265 if not _check_compatible_recipe(pn, d): 257 _check_compatible_recipe(pn, d)
266 return None
267 258
268 if os.path.exists(srctree): 259 if os.path.exists(srctree):
269 if not os.path.isdir(srctree): 260 if not os.path.isdir(srctree):
270 logger.error("output path %s exists and is not a directory" % srctree) 261 raise DevtoolError("output path %s exists and is not a directory" %
271 return None 262 srctree)
272 elif os.listdir(srctree): 263 elif os.listdir(srctree):
273 logger.error("output path %s already exists and is non-empty" % srctree) 264 raise DevtoolError("output path %s already exists and is "
274 return None 265 "non-empty" % srctree)
275 266
276 # Prepare for shutil.move later on 267 # Prepare for shutil.move later on
277 bb.utils.mkdirhier(srctree) 268 bb.utils.mkdirhier(srctree)
@@ -341,8 +332,8 @@ def _extract_source(srctree, keep_temp, devbranch, d):
341 initial_rev = stdout.rstrip() 332 initial_rev = stdout.rstrip()
342 else: 333 else:
343 if not os.listdir(srcsubdir): 334 if not os.listdir(srcsubdir):
344 logger.error("no source unpacked to S, perhaps the %s recipe doesn't use any source?" % pn) 335 raise DevtoolError("no source unpacked to S, perhaps the %s "
345 return None 336 "recipe doesn't use any source?" % pn)
346 337
347 if not os.path.exists(os.path.join(srcsubdir, '.git')): 338 if not os.path.exists(os.path.join(srcsubdir, '.git')):
348 bb.process.run('git init', cwd=srcsubdir) 339 bb.process.run('git init', cwd=srcsubdir)
@@ -423,22 +414,22 @@ def modify(args, config, basepath, workspace):
423 import oe.recipeutils 414 import oe.recipeutils
424 415
425 if args.recipename in workspace: 416 if args.recipename in workspace:
426 logger.error("recipe %s is already in your workspace" % args.recipename) 417 raise DevtoolError("recipe %s is already in your workspace" %
427 return -1 418 args.recipename)
428 419
429 if not args.extract and not os.path.isdir(args.srctree): 420 if not args.extract and not os.path.isdir(args.srctree):
430 logger.error("directory %s does not exist or not a directory (specify -x to extract source from recipe)" % args.srctree) 421 raise DevtoolError("directory %s does not exist or not a directory "
431 return -1 422 "(specify -x to extract source from recipe)" %
423 args.srctree)
432 424
433 tinfoil = setup_tinfoil() 425 tinfoil = setup_tinfoil()
434 426
435 rd = _parse_recipe(config, tinfoil, args.recipename, True) 427 rd = _parse_recipe(config, tinfoil, args.recipename, True)
436 if not rd: 428 if not rd:
437 return -1 429 return 1
438 recipefile = rd.getVar('FILE', True) 430 recipefile = rd.getVar('FILE', True)
439 431
440 if not _check_compatible_recipe(args.recipename, rd): 432 _check_compatible_recipe(args.recipename, rd)
441 return -1
442 433
443 initial_rev = None 434 initial_rev = None
444 commits = [] 435 commits = []
@@ -446,7 +437,7 @@ def modify(args, config, basepath, workspace):
446 if args.extract: 437 if args.extract:
447 initial_rev = _extract_source(args.srctree, False, args.branch, rd) 438 initial_rev = _extract_source(args.srctree, False, args.branch, rd)
448 if not initial_rev: 439 if not initial_rev:
449 return -1 440 return 1
450 # Get list of commits since this revision 441 # Get list of commits since this revision
451 (stdout, _) = bb.process.run('git rev-list --reverse %s..HEAD' % initial_rev, cwd=args.srctree) 442 (stdout, _) = bb.process.run('git rev-list --reverse %s..HEAD' % initial_rev, cwd=args.srctree)
452 commits = stdout.split() 443 commits = stdout.split()
@@ -758,22 +749,22 @@ def _update_recipe_patch(args, config, srctree, rd, config_data):
758def update_recipe(args, config, basepath, workspace): 749def update_recipe(args, config, basepath, workspace):
759 """Entry point for the devtool 'update-recipe' subcommand""" 750 """Entry point for the devtool 'update-recipe' subcommand"""
760 if not args.recipename in workspace: 751 if not args.recipename in workspace:
761 logger.error("no recipe named %s in your workspace" % args.recipename) 752 raise DevtoolError("no recipe named %s in your workspace" %
762 return -1 753 args.recipename)
763 754
764 if args.append: 755 if args.append:
765 if not os.path.exists(args.append): 756 if not os.path.exists(args.append):
766 logger.error('bbappend destination layer directory "%s" does not exist' % args.append) 757 raise DevtoolError('bbappend destination layer directory "%s" '
767 return 2 758 'does not exist' % args.append)
768 if not os.path.exists(os.path.join(args.append, 'conf', 'layer.conf')): 759 if not os.path.exists(os.path.join(args.append, 'conf', 'layer.conf')):
769 logger.error('conf/layer.conf not found in bbappend destination layer "%s"' % args.append) 760 raise DevtoolError('conf/layer.conf not found in bbappend '
770 return 2 761 'destination layer "%s"' % args.append)
771 762
772 tinfoil = setup_tinfoil() 763 tinfoil = setup_tinfoil()
773 764
774 rd = _parse_recipe(config, tinfoil, args.recipename, True) 765 rd = _parse_recipe(config, tinfoil, args.recipename, True)
775 if not rd: 766 if not rd:
776 return -1 767 return 1
777 768
778 orig_src_uri = rd.getVar('SRC_URI', False) or '' 769 orig_src_uri = rd.getVar('SRC_URI', False) or ''
779 if args.mode == 'auto': 770 if args.mode == 'auto':
@@ -786,17 +777,12 @@ def update_recipe(args, config, basepath, workspace):
786 777
787 srctree = workspace[args.recipename] 778 srctree = workspace[args.recipename]
788 779
789 try: 780 if mode == 'srcrev':
790 if mode == 'srcrev': 781 _update_recipe_srcrev(args, srctree, rd, tinfoil.config_data)
791 _update_recipe_srcrev(args, srctree, rd, tinfoil.config_data) 782 elif mode == 'patch':
792 elif mode == 'patch': 783 _update_recipe_patch(args, config, srctree, rd, tinfoil.config_data)
793 _update_recipe_patch(args, config, srctree, rd, 784 else:
794 tinfoil.config_data) 785 raise DevtoolError('update_recipe: invalid mode %s' % mode)
795 else:
796 raise DevtoolError('update_recipe: invalid mode %s' % mode)
797 except DevtoolError as err:
798 logger.error(err)
799 return 1
800 786
801 return 0 787 return 0
802 788
@@ -816,15 +802,13 @@ def reset(args, config, basepath, workspace):
816 import bb 802 import bb
817 if args.recipename: 803 if args.recipename:
818 if args.all: 804 if args.all:
819 logger.error("Recipe cannot be specified if -a/--all is used") 805 raise DevtoolError("Recipe cannot be specified if -a/--all is used")
820 return -1
821 elif not args.recipename in workspace: 806 elif not args.recipename in workspace:
822 logger.error("no recipe named %s in your workspace" % args.recipename) 807 raise DevtoolError("no recipe named %s in your workspace" %
823 return -1 808 args.recipename)
824 elif not args.all: 809 elif not args.all:
825 logger.error("Recipe must be specified, or specify -a/--all to reset all recipes") 810 raise DevtoolError("Recipe must be specified, or specify -a/--all to "
826 return -1 811 "reset all recipes")
827
828 if args.all: 812 if args.all:
829 recipes = workspace 813 recipes = workspace
830 else: 814 else:
@@ -836,8 +820,10 @@ def reset(args, config, basepath, workspace):
836 try: 820 try:
837 exec_build_env_command(config.init_path, basepath, 'bitbake -c clean %s' % pn) 821 exec_build_env_command(config.init_path, basepath, 'bitbake -c clean %s' % pn)
838 except bb.process.ExecutionError as e: 822 except bb.process.ExecutionError as e:
839 logger.error('Command \'%s\' failed, output:\n%s\nIf you wish, you may specify -n/--no-clean to skip running this command when resetting' % (e.command, e.stdout)) 823 raise DevtoolError('Command \'%s\' failed, output:\n%s\nIf you '
840 return 1 824 'wish, you may specify -n/--no-clean to '
825 'skip running this command when resetting' %
826 (e.command, e.stdout))
841 827
842 _check_preserve(config, pn) 828 _check_preserve(config, pn)
843 829
@@ -861,8 +847,8 @@ def build(args, config, basepath, workspace):
861 """Entry point for the devtool 'build' subcommand""" 847 """Entry point for the devtool 'build' subcommand"""
862 import bb 848 import bb
863 if not args.recipename in workspace: 849 if not args.recipename in workspace:
864 logger.error("no recipe named %s in your workspace" % args.recipename) 850 raise DevtoolError("no recipe named %s in your workspace" %
865 return -1 851 args.recipename)
866 build_task = config.get('Build', 'build_task', 'populate_sysroot') 852 build_task = config.get('Build', 'build_task', 'populate_sysroot')
867 try: 853 try:
868 exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s' % (build_task, args.recipename), watch=True) 854 exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s' % (build_task, args.recipename), watch=True)