2011-03-03 14:15:47 +00:00
|
|
|
#!/usr/bin/env python
|
2011-02-07 17:50:27 +00:00
|
|
|
|
2011-03-02 17:59:38 +00:00
|
|
|
# This script has subcommands which operate against your bitbake layers, either
|
|
|
|
# displaying useful information, or acting against them.
|
2011-08-12 10:40:18 +00:00
|
|
|
# See the help output for details on available commands.
|
2011-03-02 17:59:38 +00:00
|
|
|
|
2011-02-07 17:50:27 +00:00
|
|
|
import cmd
|
|
|
|
import logging
|
2011-07-25 18:29:53 +00:00
|
|
|
import os
|
2011-02-07 17:50:27 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
bindir = os.path.dirname(__file__)
|
|
|
|
topdir = os.path.dirname(bindir)
|
|
|
|
sys.path[0:0] = [os.path.join(topdir, 'lib')]
|
|
|
|
|
|
|
|
import bb.cache
|
|
|
|
import bb.cooker
|
|
|
|
import bb.providers
|
2011-06-29 18:37:40 +00:00
|
|
|
import bb.utils
|
2011-02-07 17:50:27 +00:00
|
|
|
from bb.cooker import state
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger('BitBake')
|
|
|
|
|
|
|
|
|
|
|
|
def main(args):
|
2011-08-12 11:09:44 +00:00
|
|
|
# Set up logging
|
|
|
|
console = logging.StreamHandler(sys.stdout)
|
|
|
|
format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
|
|
|
|
bb.msg.addDefaultlogFilter(console)
|
|
|
|
console.setFormatter(format)
|
|
|
|
logger.addHandler(console)
|
|
|
|
|
2011-08-13 00:58:11 +00:00
|
|
|
initialenv = os.environ.copy()
|
2011-02-07 17:58:40 +00:00
|
|
|
bb.utils.clean_environment()
|
2011-02-07 17:50:27 +00:00
|
|
|
|
2011-08-13 00:58:11 +00:00
|
|
|
cmds = Commands(initialenv)
|
2011-02-07 17:50:27 +00:00
|
|
|
if args:
|
|
|
|
cmds.onecmd(' '.join(args))
|
|
|
|
else:
|
2011-08-12 10:40:18 +00:00
|
|
|
cmds.do_help('')
|
2011-02-07 17:50:27 +00:00
|
|
|
return cmds.returncode
|
|
|
|
|
|
|
|
|
|
|
|
class Commands(cmd.Cmd):
|
2011-08-13 00:58:11 +00:00
|
|
|
def __init__(self, initialenv):
|
2011-02-07 17:50:27 +00:00
|
|
|
cmd.Cmd.__init__(self)
|
|
|
|
self.returncode = 0
|
|
|
|
self.config = Config(parse_only=True)
|
|
|
|
self.cooker = bb.cooker.BBCooker(self.config,
|
2011-07-25 18:29:53 +00:00
|
|
|
self.register_idle_function,
|
|
|
|
initialenv)
|
2011-02-07 17:50:27 +00:00
|
|
|
self.config_data = self.cooker.configuration.data
|
|
|
|
bb.providers.logger.setLevel(logging.ERROR)
|
2011-07-22 16:03:55 +00:00
|
|
|
self.cooker_data = None
|
2011-02-07 17:50:27 +00:00
|
|
|
|
2011-06-08 16:25:41 +00:00
|
|
|
def register_idle_function(self, function, data):
|
|
|
|
pass
|
|
|
|
|
2011-02-07 17:50:27 +00:00
|
|
|
def prepare_cooker(self):
|
|
|
|
sys.stderr.write("Parsing recipes..")
|
2011-07-02 15:15:30 +00:00
|
|
|
logger.setLevel(logging.WARNING)
|
2011-02-07 17:50:27 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
while self.cooker.state in (state.initial, state.parsing):
|
|
|
|
self.cooker.updateCache()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
self.cooker.shutdown()
|
|
|
|
self.cooker.updateCache()
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
sys.stderr.write("done.\n")
|
|
|
|
|
|
|
|
self.cooker_data = self.cooker.status
|
|
|
|
self.cooker_data.appends = self.cooker.appendlist
|
|
|
|
|
2011-07-22 16:03:55 +00:00
|
|
|
def check_prepare_cooker(self):
|
|
|
|
if not self.cooker_data:
|
|
|
|
self.prepare_cooker()
|
|
|
|
|
2011-08-12 10:35:25 +00:00
|
|
|
def default(self, line):
|
|
|
|
"""Handle unrecognised commands"""
|
|
|
|
sys.stderr.write("Unrecognised command or option\n")
|
|
|
|
self.do_help('')
|
|
|
|
|
|
|
|
def do_help(self, topic):
|
|
|
|
"""display general help or help on a specified command"""
|
|
|
|
if topic:
|
|
|
|
sys.stdout.write('%s: ' % topic)
|
|
|
|
cmd.Cmd.do_help(self,topic)
|
|
|
|
else:
|
|
|
|
sys.stdout.write("usage: bitbake-layers <command> [arguments]\n\n")
|
|
|
|
sys.stdout.write("Available commands:\n")
|
|
|
|
procnames = self.get_names()
|
|
|
|
for procname in procnames:
|
|
|
|
if procname[:3] == 'do_':
|
|
|
|
sys.stdout.write(" %s\n" % procname[3:])
|
|
|
|
doc = getattr(self, procname).__doc__
|
|
|
|
if doc:
|
|
|
|
sys.stdout.write(" %s\n" % doc.splitlines()[0])
|
|
|
|
|
2011-02-07 17:50:27 +00:00
|
|
|
def do_show_layers(self, args):
|
2011-08-12 10:35:25 +00:00
|
|
|
"""show current configured layers"""
|
2011-07-22 16:03:55 +00:00
|
|
|
self.check_prepare_cooker()
|
2011-08-12 14:38:22 +00:00
|
|
|
logger.plain('')
|
|
|
|
logger.plain("%s %s %s" % ("layer".ljust(20), "path".ljust(40), "priority"))
|
|
|
|
logger.plain('=' * 74)
|
|
|
|
layerdirs = str(self.config_data.getVar('BBLAYERS', True)).split()
|
|
|
|
for layerdir in layerdirs:
|
|
|
|
layername = '?'
|
|
|
|
layerpri = 0
|
|
|
|
for layer, _, regex, pri in self.cooker.status.bbfile_config_priorities:
|
|
|
|
if regex.match(os.path.join(layerdir, 'test')):
|
|
|
|
layername = layer
|
|
|
|
layerpri = pri
|
|
|
|
break
|
|
|
|
|
|
|
|
logger.plain("%s %s %d" % (layername.ljust(20), layerdir.ljust(40), layerpri))
|
2011-02-07 17:50:27 +00:00
|
|
|
|
2011-06-29 18:37:38 +00:00
|
|
|
def do_show_overlayed(self, args):
|
2011-08-12 10:35:25 +00:00
|
|
|
"""list overlayed recipes (where there is a recipe in another layer that has a higher layer priority)
|
2011-07-22 17:17:39 +00:00
|
|
|
|
2011-08-12 10:35:25 +00:00
|
|
|
usage: show_overlayed
|
2011-07-22 17:17:39 +00:00
|
|
|
|
|
|
|
Highest priority recipes are listed with the recipes they overlay as subitems.
|
|
|
|
"""
|
2011-07-22 16:03:55 +00:00
|
|
|
self.check_prepare_cooker()
|
2011-06-29 18:37:38 +00:00
|
|
|
if self.cooker.overlayed:
|
2011-08-12 11:09:44 +00:00
|
|
|
logger.plain('Overlayed recipes:')
|
2011-06-29 18:37:38 +00:00
|
|
|
for f in self.cooker.overlayed.iterkeys():
|
2011-08-12 11:09:44 +00:00
|
|
|
logger.plain('%s' % f)
|
2011-06-29 18:37:38 +00:00
|
|
|
for of in self.cooker.overlayed[f]:
|
2011-08-12 11:09:44 +00:00
|
|
|
logger.plain(' %s' % of)
|
2011-06-29 18:37:38 +00:00
|
|
|
else:
|
2011-08-12 11:09:44 +00:00
|
|
|
logger.plain('No overlayed recipes found')
|
2011-06-29 18:37:38 +00:00
|
|
|
|
2011-06-29 18:37:40 +00:00
|
|
|
def do_flatten(self, args):
|
2011-08-12 10:35:25 +00:00
|
|
|
"""flattens layer configuration into a separate output directory.
|
2011-07-22 17:17:39 +00:00
|
|
|
|
2011-08-12 10:35:25 +00:00
|
|
|
usage: flatten <outputdir>
|
2011-07-22 17:17:39 +00:00
|
|
|
|
|
|
|
Takes the current layer configuration and builds a "flattened" directory
|
|
|
|
containing the contents of all layers, with any overlayed recipes removed
|
|
|
|
and bbappends appended to the corresponding recipes. Note that some manual
|
|
|
|
cleanup may still be necessary afterwards, in particular:
|
|
|
|
|
|
|
|
* where non-recipe files (such as patches) are overwritten (the flatten
|
|
|
|
command will show a warning for these)
|
|
|
|
* where anything beyond the normal layer setup has been added to
|
|
|
|
layer.conf (only the lowest priority layer's layer.conf is used)
|
|
|
|
* overridden/appended items from bbappends will need to be tidied up
|
|
|
|
"""
|
2011-06-29 18:37:40 +00:00
|
|
|
arglist = args.split()
|
|
|
|
if len(arglist) != 1:
|
2011-07-22 17:17:39 +00:00
|
|
|
logger.error('Please specify an output directory')
|
|
|
|
self.do_help('flatten')
|
2011-06-29 18:37:40 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
if os.path.exists(arglist[0]) and os.listdir(arglist[0]):
|
|
|
|
logger.error('Directory %s exists and is non-empty, please clear it out first' % arglist[0])
|
|
|
|
return
|
|
|
|
|
2011-07-22 16:03:55 +00:00
|
|
|
self.check_prepare_cooker()
|
2011-06-29 18:37:40 +00:00
|
|
|
layers = (self.config_data.getVar('BBLAYERS', True) or "").split()
|
|
|
|
for layer in layers:
|
|
|
|
overlayed = []
|
|
|
|
for f in self.cooker.overlayed.iterkeys():
|
|
|
|
for of in self.cooker.overlayed[f]:
|
|
|
|
if of.startswith(layer):
|
|
|
|
overlayed.append(of)
|
|
|
|
|
2011-08-12 11:09:44 +00:00
|
|
|
logger.plain('Copying files from %s...' % layer )
|
2011-06-29 18:37:40 +00:00
|
|
|
for root, dirs, files in os.walk(layer):
|
|
|
|
for f1 in files:
|
|
|
|
f1full = os.sep.join([root, f1])
|
|
|
|
if f1full in overlayed:
|
2011-08-12 11:09:44 +00:00
|
|
|
logger.plain(' Skipping overlayed file %s' % f1full )
|
2011-06-29 18:37:40 +00:00
|
|
|
else:
|
|
|
|
ext = os.path.splitext(f1)[1]
|
|
|
|
if ext != '.bbappend':
|
|
|
|
fdest = f1full[len(layer):]
|
|
|
|
fdest = os.path.normpath(os.sep.join([arglist[0],fdest]))
|
|
|
|
bb.utils.mkdirhier(os.path.dirname(fdest))
|
|
|
|
if os.path.exists(fdest):
|
|
|
|
if f1 == 'layer.conf' and root.endswith('/conf'):
|
2011-08-12 11:09:44 +00:00
|
|
|
logger.plain(' Skipping layer config file %s' % f1full )
|
2011-06-29 18:37:40 +00:00
|
|
|
continue
|
|
|
|
else:
|
|
|
|
logger.warn('Overwriting file %s', fdest)
|
|
|
|
bb.utils.copyfile(f1full, fdest)
|
|
|
|
if ext == '.bb':
|
|
|
|
if f1 in self.cooker_data.appends:
|
|
|
|
appends = self.cooker_data.appends[f1]
|
|
|
|
if appends:
|
2011-08-12 11:09:44 +00:00
|
|
|
logger.plain(' Applying appends to %s' % fdest )
|
2011-06-29 18:37:40 +00:00
|
|
|
for appendname in appends:
|
|
|
|
self.apply_append(appendname, fdest)
|
|
|
|
|
|
|
|
def get_append_layer(self, appendname):
|
|
|
|
for layer, _, regex, _ in self.cooker.status.bbfile_config_priorities:
|
|
|
|
if regex.match(appendname):
|
|
|
|
return layer
|
|
|
|
return "?"
|
|
|
|
|
|
|
|
def apply_append(self, appendname, recipename):
|
|
|
|
appendfile = open(appendname, 'r')
|
|
|
|
recipefile = open(recipename, 'a')
|
|
|
|
recipefile.write('\n')
|
|
|
|
recipefile.write('##### bbappended from %s #####\n' % self.get_append_layer(appendname))
|
|
|
|
recipefile.writelines(appendfile.readlines())
|
|
|
|
|
2011-02-07 17:50:27 +00:00
|
|
|
def do_show_appends(self, args):
|
2011-08-12 10:35:25 +00:00
|
|
|
"""list bbappend files and recipe files they apply to
|
2011-07-22 17:17:39 +00:00
|
|
|
|
2011-08-12 10:35:25 +00:00
|
|
|
usage: show_appends
|
2011-07-22 17:17:39 +00:00
|
|
|
|
|
|
|
Recipes are listed with the bbappends that apply to them as subitems.
|
|
|
|
"""
|
2011-07-22 16:03:55 +00:00
|
|
|
self.check_prepare_cooker()
|
2011-02-07 17:50:27 +00:00
|
|
|
if not self.cooker_data.appends:
|
2011-08-12 11:09:44 +00:00
|
|
|
logger.plain('No append files found')
|
2011-02-07 17:50:27 +00:00
|
|
|
return
|
|
|
|
|
2011-08-12 11:09:44 +00:00
|
|
|
logger.plain('State of append files:')
|
2011-02-07 17:50:27 +00:00
|
|
|
|
2011-06-29 18:37:41 +00:00
|
|
|
pnlist = list(self.cooker_data.pkg_pn.keys())
|
2011-07-05 13:25:05 +00:00
|
|
|
pnlist.sort()
|
2011-06-29 18:37:41 +00:00
|
|
|
for pn in pnlist:
|
2011-02-07 17:50:27 +00:00
|
|
|
self.show_appends_for_pn(pn)
|
|
|
|
|
2011-06-01 16:48:32 +00:00
|
|
|
self.show_appends_for_skipped()
|
|
|
|
|
2011-02-07 17:50:27 +00:00
|
|
|
def show_appends_for_pn(self, pn):
|
|
|
|
filenames = self.cooker_data.pkg_pn[pn]
|
|
|
|
|
|
|
|
best = bb.providers.findBestProvider(pn,
|
|
|
|
self.cooker.configuration.data,
|
|
|
|
self.cooker_data,
|
|
|
|
self.cooker_data.pkg_pn)
|
|
|
|
best_filename = os.path.basename(best[3])
|
|
|
|
|
2011-06-01 16:48:32 +00:00
|
|
|
self.show_appends_output(filenames, best_filename)
|
|
|
|
|
|
|
|
def show_appends_for_skipped(self):
|
|
|
|
filenames = [os.path.basename(f)
|
|
|
|
for f in self.cooker.skiplist.iterkeys()]
|
|
|
|
self.show_appends_output(filenames, None, " (skipped)")
|
|
|
|
|
|
|
|
def show_appends_output(self, filenames, best_filename, name_suffix = ''):
|
2011-02-07 17:50:27 +00:00
|
|
|
appended, missing = self.get_appends_for_files(filenames)
|
|
|
|
if appended:
|
|
|
|
for basename, appends in appended:
|
2011-08-12 11:09:44 +00:00
|
|
|
logger.plain('%s%s:', basename, name_suffix)
|
2011-02-07 17:50:27 +00:00
|
|
|
for append in appends:
|
2011-08-12 11:09:44 +00:00
|
|
|
logger.plain(' %s', append)
|
2011-02-07 17:50:27 +00:00
|
|
|
|
2011-06-01 16:48:32 +00:00
|
|
|
if best_filename:
|
|
|
|
if best_filename in missing:
|
|
|
|
logger.warn('%s: missing append for preferred version',
|
|
|
|
best_filename)
|
|
|
|
self.returncode |= 1
|
|
|
|
|
2011-02-07 17:50:27 +00:00
|
|
|
|
|
|
|
def get_appends_for_files(self, filenames):
|
2011-06-29 18:37:41 +00:00
|
|
|
appended, notappended = [], []
|
2011-02-07 17:50:27 +00:00
|
|
|
for filename in filenames:
|
|
|
|
_, cls = bb.cache.Cache.virtualfn2realfn(filename)
|
|
|
|
if cls:
|
|
|
|
continue
|
|
|
|
|
|
|
|
basename = os.path.basename(filename)
|
|
|
|
appends = self.cooker_data.appends.get(basename)
|
|
|
|
if appends:
|
2011-06-29 18:37:41 +00:00
|
|
|
appended.append((basename, list(appends)))
|
2011-02-07 17:50:27 +00:00
|
|
|
else:
|
2011-06-29 18:37:41 +00:00
|
|
|
notappended.append(basename)
|
2011-02-07 17:50:27 +00:00
|
|
|
return appended, notappended
|
|
|
|
|
|
|
|
|
|
|
|
class Config(object):
|
|
|
|
def __init__(self, **options):
|
|
|
|
self.pkgs_to_build = []
|
|
|
|
self.debug_domains = []
|
|
|
|
self.extra_assume_provided = []
|
2011-07-05 13:25:06 +00:00
|
|
|
self.prefile = []
|
|
|
|
self.postfile = []
|
2011-02-07 17:50:27 +00:00
|
|
|
self.debug = 0
|
|
|
|
self.__dict__.update(options)
|
|
|
|
|
|
|
|
def __getattr__(self, attribute):
|
|
|
|
try:
|
|
|
|
return super(Config, self).__getattribute__(attribute)
|
|
|
|
except AttributeError:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv[1:]) or 0)
|