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 | # |
| 5 | # This program is free software; you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU General Public License version 2 as |
| 7 | # published by the Free Software Foundation. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License along |
| 15 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | """Devtool build plugin""" |
| 18 | |
| 19 | import os |
| 20 | import bb |
| 21 | import logging |
| 22 | import argparse |
| 23 | import tempfile |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 24 | from devtool import exec_build_env_command, check_workspace_recipe, DevtoolError |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | |
| 26 | logger = logging.getLogger('devtool') |
| 27 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 29 | def _set_file_values(fn, values): |
| 30 | remaining = values.keys() |
| 31 | |
| 32 | def varfunc(varname, origvalue, op, newlines): |
| 33 | newvalue = values.get(varname, origvalue) |
| 34 | remaining.remove(varname) |
| 35 | return (newvalue, '=', 0, True) |
| 36 | |
| 37 | with open(fn, 'r') as f: |
| 38 | (updated, newlines) = bb.utils.edit_metadata(f, values, varfunc) |
| 39 | |
| 40 | for item in remaining: |
| 41 | updated = True |
| 42 | newlines.append('%s = "%s"' % (item, values[item])) |
| 43 | |
| 44 | if updated: |
| 45 | with open(fn, 'w') as f: |
| 46 | f.writelines(newlines) |
| 47 | return updated |
| 48 | |
| 49 | def _get_build_tasks(config): |
| 50 | tasks = config.get('Build', 'build_task', 'populate_sysroot,packagedata').split(',') |
| 51 | return ['do_%s' % task.strip() for task in tasks] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | |
| 53 | def build(args, config, basepath, workspace): |
| 54 | """Entry point for the devtool 'build' subcommand""" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 55 | workspacepn = check_workspace_recipe(workspace, args.recipename, bbclassextend=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 57 | build_tasks = _get_build_tasks(config) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 58 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 59 | bbappend = workspace[workspacepn]['bbappend'] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 60 | if args.disable_parallel_make: |
| 61 | logger.info("Disabling 'make' parallelism") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 62 | _set_file_values(bbappend, {'PARALLEL_MAKE': ''}) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | try: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 64 | bbargs = [] |
| 65 | for task in build_tasks: |
| 66 | if args.recipename.endswith('-native') and 'package' in task: |
| 67 | continue |
| 68 | bbargs.append('%s:%s' % (args.recipename, task)) |
| 69 | 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] | 70 | except bb.process.ExecutionError as e: |
| 71 | # We've already seen the output since watch=True, so just ensure we return something to the user |
| 72 | return e.exitcode |
| 73 | finally: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 74 | if args.disable_parallel_make: |
| 75 | _set_file_values(bbappend, {'PARALLEL_MAKE': None}) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 76 | |
| 77 | return 0 |
| 78 | |
| 79 | def register_commands(subparsers, context): |
| 80 | """Register devtool subcommands from this plugin""" |
| 81 | parser_build = subparsers.add_parser('build', help='Build a recipe', |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 82 | description='Builds the specified recipe using bitbake (up to and including %s)' % ', '.join(_get_build_tasks(context.config)), |
| 83 | group='working') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | parser_build.add_argument('recipename', help='Recipe to build') |
| 85 | parser_build.add_argument('-s', '--disable-parallel-make', action="store_true", help='Disable make parallelism') |
| 86 | parser_build.set_defaults(func=build) |