blob: 935ffab46c5ec86d7b3f7b062cc7dea8e3d642ea [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
Brad Bishopc68388fc2019-08-26 01:33:31 -040014from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, DevtoolError
15from devtool import parse_recipe
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016
17logger = logging.getLogger('devtool')
18
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050020def _set_file_values(fn, values):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060021 remaining = list(values.keys())
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050022
23 def varfunc(varname, origvalue, op, newlines):
24 newvalue = values.get(varname, origvalue)
25 remaining.remove(varname)
26 return (newvalue, '=', 0, True)
27
28 with open(fn, 'r') as f:
29 (updated, newlines) = bb.utils.edit_metadata(f, values, varfunc)
30
31 for item in remaining:
32 updated = True
33 newlines.append('%s = "%s"' % (item, values[item]))
34
35 if updated:
36 with open(fn, 'w') as f:
37 f.writelines(newlines)
38 return updated
39
40def _get_build_tasks(config):
41 tasks = config.get('Build', 'build_task', 'populate_sysroot,packagedata').split(',')
42 return ['do_%s' % task.strip() for task in tasks]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043
44def build(args, config, basepath, workspace):
45 """Entry point for the devtool 'build' subcommand"""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050046 workspacepn = check_workspace_recipe(workspace, args.recipename, bbclassextend=True)
Brad Bishopc68388fc2019-08-26 01:33:31 -040047 tinfoil = setup_tinfoil(config_only=False, basepath=basepath)
48 try:
49 rd = parse_recipe(config, tinfoil, args.recipename, appends=True, filter_workspace=False)
50 if not rd:
51 return 1
52 deploytask = 'do_deploy' in rd.getVar('__BBTASKS')
53 finally:
54 tinfoil.shutdown()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080056 if args.clean:
57 # use clean instead of cleansstate to avoid messing things up in eSDK
58 build_tasks = ['do_clean']
59 else:
60 build_tasks = _get_build_tasks(config)
Brad Bishopc68388fc2019-08-26 01:33:31 -040061 if deploytask:
62 build_tasks.append('do_deploy')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050064 bbappend = workspace[workspacepn]['bbappend']
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065 if args.disable_parallel_make:
66 logger.info("Disabling 'make' parallelism")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050067 _set_file_values(bbappend, {'PARALLEL_MAKE': ''})
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068 try:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050069 bbargs = []
70 for task in build_tasks:
71 if args.recipename.endswith('-native') and 'package' in task:
72 continue
73 bbargs.append('%s:%s' % (args.recipename, task))
74 exec_build_env_command(config.init_path, basepath, 'bitbake %s' % ' '.join(bbargs), watch=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075 except bb.process.ExecutionError as e:
76 # We've already seen the output since watch=True, so just ensure we return something to the user
77 return e.exitcode
78 finally:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050079 if args.disable_parallel_make:
80 _set_file_values(bbappend, {'PARALLEL_MAKE': None})
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081
82 return 0
83
84def register_commands(subparsers, context):
85 """Register devtool subcommands from this plugin"""
86 parser_build = subparsers.add_parser('build', help='Build a recipe',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050087 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 -050088 group='working', order=50)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089 parser_build.add_argument('recipename', help='Recipe to build')
90 parser_build.add_argument('-s', '--disable-parallel-make', action="store_true", help='Disable make parallelism')
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080091 parser_build.add_argument('-c', '--clean', action='store_true', help='clean up recipe building results')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050092 parser_build.set_defaults(func=build)