blob: ba9593f1ad05bf68115fe77c60c2551edd9c1fe6 [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
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080057 if args.clean:
58 # use clean instead of cleansstate to avoid messing things up in eSDK
59 build_tasks = ['do_clean']
60 else:
61 build_tasks = _get_build_tasks(config)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050063 bbappend = workspace[workspacepn]['bbappend']
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064 if args.disable_parallel_make:
65 logger.info("Disabling 'make' parallelism")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050066 _set_file_values(bbappend, {'PARALLEL_MAKE': ''})
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 try:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050068 bbargs = []
69 for task in build_tasks:
70 if args.recipename.endswith('-native') and 'package' in task:
71 continue
72 bbargs.append('%s:%s' % (args.recipename, task))
73 exec_build_env_command(config.init_path, basepath, 'bitbake %s' % ' '.join(bbargs), watch=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074 except bb.process.ExecutionError as e:
75 # We've already seen the output since watch=True, so just ensure we return something to the user
76 return e.exitcode
77 finally:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050078 if args.disable_parallel_make:
79 _set_file_values(bbappend, {'PARALLEL_MAKE': None})
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080
81 return 0
82
83def register_commands(subparsers, context):
84 """Register devtool subcommands from this plugin"""
85 parser_build = subparsers.add_parser('build', help='Build a recipe',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050086 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 -050087 group='working', order=50)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088 parser_build.add_argument('recipename', help='Recipe to build')
89 parser_build.add_argument('-s', '--disable-parallel-make', action="store_true", help='Disable make parallelism')
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080090 parser_build.add_argument('-c', '--clean', action='store_true', help='clean up recipe building results')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 parser_build.set_defaults(func=build)