2015-09-16 17:03:32 +00:00
# Recipe creation tool - newappend plugin
#
# This sub-command creates a bbappend for the specified target and prints the
# path to the bbappend.
#
# Example: recipetool newappend meta-mylayer busybox
#
# Copyright (C) 2015 Christopher Larson <kergoth@gmail.com>
#
# 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.
import argparse
import errno
import logging
import os
import re
2016-02-09 23:12:06 +00:00
import subprocess
2015-09-16 17:03:32 +00:00
import sys
2016-02-19 09:38:50 +00:00
import scriptutils
2015-09-16 17:03:32 +00:00
logger = logging . getLogger ( ' recipetool ' )
tinfoil = None
def tinfoil_init ( instance ) :
global tinfoil
tinfoil = instance
def layer ( layerpath ) :
if not os . path . exists ( os . path . join ( layerpath , ' conf ' , ' layer.conf ' ) ) :
raise argparse . ArgumentTypeError ( ' {0!r} must be a path to a valid layer ' . format ( layerpath ) )
return layerpath
def newappend ( args ) :
import oe . recipeutils
2016-12-13 07:09:36 +00:00
recipe_path = tinfoil . get_recipe_file ( args . target )
2015-09-16 17:03:32 +00:00
rd = tinfoil . config_data . createCopy ( )
rd . setVar ( ' FILE ' , recipe_path )
append_path , path_ok = oe . recipeutils . get_bbappend_path ( rd , args . destlayer , args . wildcard_version )
if not append_path :
logger . error ( ' Unable to determine layer directory containing %s ' , recipe_path )
return 1
if not path_ok :
2016-04-21 15:45:41 +00:00
logger . warn ( ' Unable to determine correct subdirectory path for bbappend file - check that what %s adds to BBFILES also matches .bbappend files. Using %s for now, but until you fix this the bbappend will not be applied. ' , os . path . join ( args . destlayer , ' conf ' , ' layer.conf ' ) , os . path . dirname ( append_path ) )
2015-09-16 17:03:32 +00:00
2016-12-14 21:13:05 +00:00
layerdirs = [ os . path . abspath ( layerdir ) for layerdir in rd . getVar ( ' BBLAYERS ' ) . split ( ) ]
2015-09-16 17:03:32 +00:00
if not os . path . abspath ( args . destlayer ) in layerdirs :
logger . warn ( ' Specified layer is not currently enabled in bblayers.conf, you will need to add it before this bbappend will be active ' )
if not os . path . exists ( append_path ) :
bb . utils . mkdirhier ( os . path . dirname ( append_path ) )
try :
2016-02-09 23:12:06 +00:00
open ( append_path , ' a ' ) . close ( )
2015-09-16 17:03:32 +00:00
except ( OSError , IOError ) as exc :
logger . critical ( str ( exc ) )
return 1
2016-02-09 23:12:06 +00:00
if args . edit :
2016-02-19 09:38:50 +00:00
return scriptutils . run_editor ( [ append_path , recipe_path ] )
2016-02-09 23:12:06 +00:00
else :
print ( append_path )
2015-09-16 17:03:32 +00:00
2015-11-22 19:55:45 +00:00
def register_commands ( subparsers ) :
2015-09-16 17:03:32 +00:00
parser = subparsers . add_parser ( ' newappend ' ,
help = ' Create a bbappend for the specified target in the specified layer ' )
2016-02-09 23:12:06 +00:00
parser . add_argument ( ' -e ' , ' --edit ' , help = ' Edit the new append. This obeys $VISUAL if set, otherwise $EDITOR, otherwise vi. ' , action = ' store_true ' )
2015-09-16 17:03:32 +00:00
parser . add_argument ( ' -w ' , ' --wildcard-version ' , help = ' Use wildcard to make the bbappend apply to any recipe version ' , action = ' store_true ' )
parser . add_argument ( ' destlayer ' , help = ' Base directory of the destination layer to write the bbappend to ' , type = layer )
parser . add_argument ( ' target ' , help = ' Target recipe/provide to append ' )
parser . set_defaults ( func = newappend , parserecipes = True )