1# OpenEmbedded Development tool - menuconfig command plugin
2#
3# Copyright (C) 2018 Xilinx
4# Written by: Chandana Kalluri <ckalluri@xilinx.com>
5#
6# SPDX-License-Identifier: MIT
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License version 2 as
10# published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21"""Devtool menuconfig plugin"""
22
23import os
24import bb
25import logging
26import argparse
27import re
28import glob
29from devtool import setup_tinfoil, parse_recipe, DevtoolError, standard, exec_build_env_command
30from devtool import check_workspace_recipe
31logger = logging.getLogger('devtool')
32
33def menuconfig(args, config, basepath, workspace):
34    """Entry point for the devtool 'menuconfig' subcommand"""
35
36    rd = ""
37    kconfigpath = ""
38    pn_src = ""
39    localfilesdir = ""
40    workspace_dir = ""
41    tinfoil = setup_tinfoil(basepath=basepath)
42    try:
43        rd = parse_recipe(config, tinfoil, args.component, appends=True, filter_workspace=False)
44        if not rd:
45            return 1
46
47        check_workspace_recipe(workspace, args.component)
48        pn = rd.getVar('PN')
49
50        if not rd.getVarFlag('do_menuconfig','task'):
51            raise DevtoolError("This recipe does not support menuconfig option")
52
53        workspace_dir = os.path.join(config.workspace_path,'sources')
54        kconfigpath = rd.getVar('B')
55        pn_src = os.path.join(workspace_dir,pn)
56
57        # add check to see if oe_local_files exists or not
58        localfilesdir = os.path.join(pn_src,'oe-local-files')
59        if not os.path.exists(localfilesdir):
60            bb.utils.mkdirhier(localfilesdir)
61            # Add gitignore to ensure source tree is clean
62            gitignorefile = os.path.join(localfilesdir,'.gitignore')
63            with open(gitignorefile, 'w') as f:
64                f.write('# Ignore local files, by default. Remove this file if you want to commit the directory to Git\n')
65                f.write('*\n')
66
67    finally:
68        tinfoil.shutdown()
69
70    logger.info('Launching menuconfig')
71    exec_build_env_command(config.init_path, basepath, 'bitbake -c menuconfig %s' % pn, watch=True)
72    fragment = os.path.join(localfilesdir, 'devtool-fragment.cfg')
73    res = standard._create_kconfig_diff(pn_src,rd,fragment)
74
75    return 0
76
77def register_commands(subparsers, context):
78    """register devtool subcommands from this plugin"""
79    parser_menuconfig = subparsers.add_parser('menuconfig',help='Alter build-time configuration for a recipe', description='Launches the make menuconfig command (for recipes where do_menuconfig is available), allowing users to make changes to the build-time configuration. Creates a config fragment corresponding to changes made.', group='advanced')
80    parser_menuconfig.add_argument('component', help='compenent to alter config')
81    parser_menuconfig.set_defaults(func=menuconfig,fixed_setup=context.fixed_setup)
82