blob: 9b58858a62ebbe9b996200916c5b40c1af652597 [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
28def plugin_init(pluginlist):
29 """Plugin initialization"""
30 pass
31
32def _create_conf_file(values, conf_file=None):
33 if not conf_file:
34 fd, conf_file = tempfile.mkstemp(suffix='.conf')
35 elif not os.path.exists(os.path.dirname(conf_file)):
36 logger.debug("Creating folder %s" % os.path.dirname(conf_file))
37 bb.utils.mkdirhier(os.path.dirname(conf_file))
38 with open(conf_file, 'w') as f:
39 for key, value in values.iteritems():
40 f.write('%s = "%s"\n' % (key, value))
41 return conf_file
42
43def build(args, config, basepath, workspace):
44 """Entry point for the devtool 'build' subcommand"""
Patrick Williamsf1e5d692016-03-30 15:21:19 -050045 check_workspace_recipe(workspace, args.recipename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046
47 build_task = config.get('Build', 'build_task', 'populate_sysroot')
48
49 postfile_param = ""
50 postfile = ""
51 if args.disable_parallel_make:
52 logger.info("Disabling 'make' parallelism")
53 postfile = os.path.join(basepath, 'conf', 'disable_parallelism.conf')
54 _create_conf_file({'PARALLEL_MAKE':''}, postfile)
55 postfile_param = "-R %s" % postfile
56 try:
57 exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s %s' % (build_task, postfile_param, args.recipename), watch=True)
58 except bb.process.ExecutionError as e:
59 # We've already seen the output since watch=True, so just ensure we return something to the user
60 return e.exitcode
61 finally:
62 if postfile:
63 logger.debug('Removing postfile')
64 os.remove(postfile)
65
66 return 0
67
68def register_commands(subparsers, context):
69 """Register devtool subcommands from this plugin"""
70 parser_build = subparsers.add_parser('build', help='Build a recipe',
71 description='Builds the specified recipe using bitbake',
72 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
73 parser_build.add_argument('recipename', help='Recipe to build')
74 parser_build.add_argument('-s', '--disable-parallel-make', action="store_true", help='Disable make parallelism')
75 parser_build.set_defaults(func=build)