blob: ba9593f1ad05bf68115fe77c60c2551edd9c1fe6 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001# 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
24from devtool import exec_build_env_command, check_workspace_recipe, DevtoolError
25
26logger = logging.getLogger('devtool')
27
28
29def _set_file_values(fn, values):
30 remaining = list(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
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]
52
53def build(args, config, basepath, workspace):
54 """Entry point for the devtool 'build' subcommand"""
55 workspacepn = check_workspace_recipe(workspace, args.recipename, bbclassextend=True)
56
57 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)
62
63 bbappend = workspace[workspacepn]['bbappend']
64 if args.disable_parallel_make:
65 logger.info("Disabling 'make' parallelism")
66 _set_file_values(bbappend, {'PARALLEL_MAKE': ''})
67 try:
68 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)
74 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:
78 if args.disable_parallel_make:
79 _set_file_values(bbappend, {'PARALLEL_MAKE': None})
80
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',
86 description='Builds the specified recipe using bitbake (up to and including %s)' % ', '.join(_get_build_tasks(context.config)),
87 group='working', order=50)
88 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')
90 parser_build.add_argument('-c', '--clean', action='store_true', help='clean up recipe building results')
91 parser_build.set_defaults(func=build)