blob: 335aff549148256bb0429562a2a9f4413d2282f2 [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
24from devtool import exec_build_env_command, DevtoolError
25
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"""
45 if not args.recipename in workspace:
46 raise DevtoolError("no recipe named %s in your workspace" %
47 args.recipename)
48
49 build_task = config.get('Build', 'build_task', 'populate_sysroot')
50
51 postfile_param = ""
52 postfile = ""
53 if args.disable_parallel_make:
54 logger.info("Disabling 'make' parallelism")
55 postfile = os.path.join(basepath, 'conf', 'disable_parallelism.conf')
56 _create_conf_file({'PARALLEL_MAKE':''}, postfile)
57 postfile_param = "-R %s" % postfile
58 try:
59 exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s %s' % (build_task, postfile_param, args.recipename), watch=True)
60 except bb.process.ExecutionError as e:
61 # We've already seen the output since watch=True, so just ensure we return something to the user
62 return e.exitcode
63 finally:
64 if postfile:
65 logger.debug('Removing postfile')
66 os.remove(postfile)
67
68 return 0
69
70def register_commands(subparsers, context):
71 """Register devtool subcommands from this plugin"""
72 parser_build = subparsers.add_parser('build', help='Build a recipe',
73 description='Builds the specified recipe using bitbake',
74 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
75 parser_build.add_argument('recipename', help='Recipe to build')
76 parser_build.add_argument('-s', '--disable-parallel-make', action="store_true", help='Disable make parallelism')
77 parser_build.set_defaults(func=build)