blob: 7543398d96f2208d6c6addf136ebe4acf46246d7 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Development tool - build command plugin
2#
3# Copyright (C) 2014-2015 Intel Corporation
4#
Brad Bishopc342db32019-05-15 21:57:59 -04005# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007"""Devtool build plugin"""
8
9import os
10import bb
11import logging
12import argparse
13import tempfile
Patrick Williamsf1e5d692016-03-30 15:21:19 -050014from devtool import exec_build_env_command, check_workspace_recipe, DevtoolError
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015
16logger = logging.getLogger('devtool')
17
Patrick Williamsc124f4f2015-09-15 14:41:29 -050018
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050019def _set_file_values(fn, values):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060020 remaining = list(values.keys())
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050021
22 def varfunc(varname, origvalue, op, newlines):
23 newvalue = values.get(varname, origvalue)
24 remaining.remove(varname)
25 return (newvalue, '=', 0, True)
26
27 with open(fn, 'r') as f:
28 (updated, newlines) = bb.utils.edit_metadata(f, values, varfunc)
29
30 for item in remaining:
31 updated = True
32 newlines.append('%s = "%s"' % (item, values[item]))
33
34 if updated:
35 with open(fn, 'w') as f:
36 f.writelines(newlines)
37 return updated
38
39def _get_build_tasks(config):
40 tasks = config.get('Build', 'build_task', 'populate_sysroot,packagedata').split(',')
41 return ['do_%s' % task.strip() for task in tasks]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042
43def build(args, config, basepath, workspace):
44 """Entry point for the devtool 'build' subcommand"""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050045 workspacepn = check_workspace_recipe(workspace, args.recipename, bbclassextend=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080047 if args.clean:
48 # use clean instead of cleansstate to avoid messing things up in eSDK
49 build_tasks = ['do_clean']
50 else:
51 build_tasks = _get_build_tasks(config)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050053 bbappend = workspace[workspacepn]['bbappend']
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054 if args.disable_parallel_make:
55 logger.info("Disabling 'make' parallelism")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050056 _set_file_values(bbappend, {'PARALLEL_MAKE': ''})
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057 try:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050058 bbargs = []
59 for task in build_tasks:
60 if args.recipename.endswith('-native') and 'package' in task:
61 continue
62 bbargs.append('%s:%s' % (args.recipename, task))
63 exec_build_env_command(config.init_path, basepath, 'bitbake %s' % ' '.join(bbargs), watch=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064 except bb.process.ExecutionError as e:
65 # We've already seen the output since watch=True, so just ensure we return something to the user
66 return e.exitcode
67 finally:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050068 if args.disable_parallel_make:
69 _set_file_values(bbappend, {'PARALLEL_MAKE': None})
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070
71 return 0
72
73def register_commands(subparsers, context):
74 """Register devtool subcommands from this plugin"""
75 parser_build = subparsers.add_parser('build', help='Build a recipe',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050076 description='Builds the specified recipe using bitbake (up to and including %s)' % ', '.join(_get_build_tasks(context.config)),
Brad Bishop6e60e8b2018-02-01 10:27:11 -050077 group='working', order=50)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078 parser_build.add_argument('recipename', help='Recipe to build')
79 parser_build.add_argument('-s', '--disable-parallel-make', action="store_true", help='Disable make parallelism')
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080080 parser_build.add_argument('-c', '--clean', action='store_true', help='clean up recipe building results')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081 parser_build.set_defaults(func=build)