Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # Development tool - build command plugin |
| 2 | # |
| 3 | # Copyright (C) 2014-2015 Intel Corporation |
| 4 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 5 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | """Devtool build plugin""" |
| 8 | |
| 9 | import os |
| 10 | import bb |
| 11 | import logging |
| 12 | import argparse |
| 13 | import tempfile |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 14 | from devtool import exec_build_env_command, check_workspace_recipe, DevtoolError |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | |
| 16 | logger = logging.getLogger('devtool') |
| 17 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 19 | def _set_file_values(fn, values): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 20 | remaining = list(values.keys()) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 21 | |
| 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 | |
| 39 | def _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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | |
| 43 | def build(args, config, basepath, workspace): |
| 44 | """Entry point for the devtool 'build' subcommand""" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 45 | workspacepn = check_workspace_recipe(workspace, args.recipename, bbclassextend=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 47 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 53 | bbappend = workspace[workspacepn]['bbappend'] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | if args.disable_parallel_make: |
| 55 | logger.info("Disabling 'make' parallelism") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 56 | _set_file_values(bbappend, {'PARALLEL_MAKE': ''}) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | try: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 58 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 64 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 68 | if args.disable_parallel_make: |
| 69 | _set_file_values(bbappend, {'PARALLEL_MAKE': None}) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | |
| 71 | return 0 |
| 72 | |
| 73 | def register_commands(subparsers, context): |
| 74 | """Register devtool subcommands from this plugin""" |
| 75 | parser_build = subparsers.add_parser('build', help='Build a recipe', |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 76 | description='Builds the specified recipe using bitbake (up to and including %s)' % ', '.join(_get_build_tasks(context.config)), |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 77 | group='working', order=50) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 78 | 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 80 | parser_build.add_argument('-c', '--clean', action='store_true', help='clean up recipe building results') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 81 | parser_build.set_defaults(func=build) |