blob: 252379e9b25df8336668b83ffbc431827c7f444b [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#
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
19import os
20import bb
21import logging
22import argparse
23import tempfile
Patrick Williamsf1e5d692016-03-30 15:21:19 -050024from devtool import exec_build_env_command, check_workspace_recipe, DevtoolError
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025
26logger = logging.getLogger('devtool')
27
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050029def _set_file_values(fn, values):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060030 remaining = list(values.keys())
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050031
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
49def _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 Williamsc124f4f2015-09-15 14:41:29 -050052
53def build(args, config, basepath, workspace):
54 """Entry point for the devtool 'build' subcommand"""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050055 workspacepn = check_workspace_recipe(workspace, args.recipename, bbclassextend=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050057 build_tasks = _get_build_tasks(config)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050059 bbappend = workspace[workspacepn]['bbappend']
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 if args.disable_parallel_make:
61 logger.info("Disabling 'make' parallelism")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050062 _set_file_values(bbappend, {'PARALLEL_MAKE': ''})
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063 try:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050064 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 Williamsc124f4f2015-09-15 14:41:29 -050070 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 Williamsd8c66bc2016-06-20 12:57:21 -050074 if args.disable_parallel_make:
75 _set_file_values(bbappend, {'PARALLEL_MAKE': None})
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076
77 return 0
78
79def register_commands(subparsers, context):
80 """Register devtool subcommands from this plugin"""
81 parser_build = subparsers.add_parser('build', help='Build a recipe',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050082 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 -050083 group='working', order=50)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084 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)