aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/bb-print-layer-data
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/bb-print-layer-data')
-rwxr-xr-xscripts/bb-print-layer-data129
1 files changed, 0 insertions, 129 deletions
diff --git a/scripts/bb-print-layer-data b/scripts/bb-print-layer-data
deleted file mode 100755
index afbefe93..00000000
--- a/scripts/bb-print-layer-data
+++ /dev/null
@@ -1,129 +0,0 @@
-#!/usr/bin/env python3
-#
-# ---------------------------------------------------------------------------------------------------------------------
-# SPDX-License-Identifier: MIT
-# ---------------------------------------------------------------------------------------------------------------------
-#
-# Given a layer or layer.conf path, print the layer metadata
-
-import contextlib
-import os
-import signal
-import sys
-from operator import itemgetter
-
-
-class Terminate(BaseException):
- pass
-
-
-def sigterm_exception(signum, stackframe):
- raise Terminate()
-
-
-def setup_command_import(command, relpath='../lib'):
- """Set up sys.path based on the location of a binary in the PATH """
- PATH = os.getenv('PATH').split(':')
- cmd_paths = [os.path.join(path, relpath)
- for path in PATH if os.path.exists(os.path.join(path, command))]
- if not cmd_paths:
- raise ImportError("Unable to locate bb, please ensure PATH is set correctly.")
-
- sys.path[0:0] = cmd_paths
-
-
-@contextlib.contextmanager
-def status(message, outfile=sys.stderr):
- """Show the user what we're doing, and whether we succeed"""
- outfile.write('{0}..'.format(message))
- outfile.flush()
- try:
- yield
- except KeyboardInterrupt:
- outfile.write('.interrupted\n')
- raise
- except Terminate:
- outfile.write('.terminated\n')
- raise
- except BaseException:
- outfile.write('.failed\n')
- raise
- outfile.write('.done\n')
-
-
-class LayerError(Exception):
- pass
-
-
-def get_layer_data(layer_path, lconf=None, data=None):
- if lconf is None:
- lconf = os.path.join(layer_path, 'conf', 'layer.conf')
-
- if data is None:
- ldata = bb.data.init()
- bb.parse.init_parser(ldata)
- else:
- ldata = data.createCopy()
-
- ldata.setVar('LAYERDIR', layer_path)
- try:
- ldata = bb.parse.handle(lconf, ldata, include=True)
- except BaseException as exc:
- raise LayerError(exc)
- ldata.expandVarref('LAYERDIR')
-
- collections = (ldata.getVar('BBFILE_COLLECTIONS', True) or '').split()
- if not collections:
- name = os.path.basename(layer_path)
- collections = [name]
-
- for name in collections:
- priority = ldata.getVar('BBFILE_PRIORITY_%s' % name, True)
- pattern = ldata.getVar('BBFILE_PATTERN_%s' % name, True)
- depends = ldata.getVar('LAYERDEPENDS_%s' % name, True)
- yield name, priority, layer_path, pattern, depends
-
-
-def print_layer_data(cmdline_opts):
- if len(cmdline_opts) < 1:
- return "Usage: bb-print-layer-data LCONF|LAYERDIR [LCONF|LAYERDIR..]\n"
-
- setup_command_import('bitbake')
- try:
- import bb
- except ImportError as exc:
- sys.exit("Unable to import 'bb' python package: %s" % exc)
-
- import bb.parse
- import bb.data
-
- data = bb.data.init()
- bb.parse.init_parser(data)
-
- collections = set()
-
- for layer_path in cmdline_opts:
- if os.path.isdir(layer_path):
- lconf = os.path.join(layer_path, 'conf', 'layer.conf')
- else:
- lconf = layer_path
- layer_path = os.path.dirname(os.path.dirname(lconf))
-
- with status("Parsing {0}".format(lconf)):
- collections |= set(get_layer_data(layer_path, lconf, data))
-
- priority_key = lambda i: int(i[1]) if i[1] is not None else None
- for name, priority, layer_path, pattern, depends in sorted(collections, key=priority_key):
- print("{0}: {1}|{2}|{3}|{4}".format(name, priority or '', layer_path, pattern or '', depends or ''))
-
-
-if __name__ == '__main__':
- signal.signal(signal.SIGTERM, sigterm_exception)
- try:
- sys.exit(print_layer_data(sys.argv[1:]) or 0)
- except KeyboardInterrupt:
- signal.signal(signal.SIGINT, signal.SIG_DFL)
- os.kill(os.getpid(), signal.SIGINT)
- except Terminate:
- signal.signal(signal.SIGTERM, signal.SIG_DFL)
- os.kill(os.getpid(), signal.SIGTERM)