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