2015-09-08 10:39:10 +00:00
|
|
|
# Development tool - build command plugin
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014-2015 Intel Corporation
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
"""Devtool build plugin"""
|
|
|
|
|
2015-09-08 10:39:11 +00:00
|
|
|
import os
|
|
|
|
import bb
|
2015-09-08 10:39:10 +00:00
|
|
|
import logging
|
|
|
|
import argparse
|
2015-09-08 10:39:11 +00:00
|
|
|
import tempfile
|
|
|
|
from devtool import exec_build_env_command, DevtoolError
|
2015-09-08 10:39:10 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger('devtool')
|
|
|
|
|
|
|
|
def plugin_init(pluginlist):
|
|
|
|
"""Plugin initialization"""
|
|
|
|
pass
|
|
|
|
|
2015-09-08 10:39:11 +00:00
|
|
|
def _create_conf_file(values, conf_file=None):
|
|
|
|
if not conf_file:
|
|
|
|
fd, conf_file = tempfile.mkstemp(suffix='.conf')
|
|
|
|
elif not os.path.exists(os.path.dirname(conf_file)):
|
|
|
|
logger.debug("Creating folder %s" % os.path.dirname(conf_file))
|
|
|
|
bb.utils.mkdirhier(os.path.dirname(conf_file))
|
|
|
|
with open(conf_file, 'w') as f:
|
|
|
|
for key, value in values.iteritems():
|
|
|
|
f.write('%s = "%s"\n' % (key, value))
|
|
|
|
return conf_file
|
|
|
|
|
2015-09-08 10:39:10 +00:00
|
|
|
def build(args, config, basepath, workspace):
|
|
|
|
"""Entry point for the devtool 'build' subcommand"""
|
|
|
|
if not args.recipename in workspace:
|
|
|
|
raise DevtoolError("no recipe named %s in your workspace" %
|
|
|
|
args.recipename)
|
2015-09-08 10:39:11 +00:00
|
|
|
|
2015-09-08 10:39:10 +00:00
|
|
|
build_task = config.get('Build', 'build_task', 'populate_sysroot')
|
2015-09-08 10:39:11 +00:00
|
|
|
|
|
|
|
postfile_param = ""
|
|
|
|
postfile = ""
|
|
|
|
if args.disable_parallel_make:
|
|
|
|
logger.info("Disabling 'make' parallelism")
|
|
|
|
postfile = os.path.join(basepath, 'conf', 'disable_parallelism.conf')
|
|
|
|
_create_conf_file({'PARALLEL_MAKE':''}, postfile)
|
|
|
|
postfile_param = "-R %s" % postfile
|
2015-09-08 10:39:10 +00:00
|
|
|
try:
|
2015-09-08 10:39:11 +00:00
|
|
|
exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s %s' % (build_task, postfile_param, args.recipename), watch=True)
|
2015-09-08 10:39:10 +00:00
|
|
|
except bb.process.ExecutionError as e:
|
|
|
|
# We've already seen the output since watch=True, so just ensure we return something to the user
|
|
|
|
return e.exitcode
|
2015-09-08 10:39:11 +00:00
|
|
|
finally:
|
|
|
|
if postfile:
|
|
|
|
logger.debug('Removing postfile')
|
|
|
|
os.remove(postfile)
|
2015-09-08 10:39:10 +00:00
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def register_commands(subparsers, context):
|
|
|
|
"""Register devtool subcommands from this plugin"""
|
|
|
|
parser_build = subparsers.add_parser('build', help='Build a recipe',
|
|
|
|
description='Builds the specified recipe using bitbake',
|
|
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
|
|
|
parser_build.add_argument('recipename', help='Recipe to build')
|
2015-09-08 10:39:11 +00:00
|
|
|
parser_build.add_argument('-s', '--disable-parallel-make', action="store_true", help='Disable make parallelism')
|
2015-09-08 10:39:10 +00:00
|
|
|
parser_build.set_defaults(func=build)
|