[OE-core] [PATCH 1/2] srctree.bbclass: Download sourcecode and make it searchable

Tobias Hagelborn tobias.hagelborn at axis.com
Fri Mar 24 07:07:16 UTC 2017


This class is used to create a symlink to the source in ${S} in a
separate directory structure. ${SECTION} is used, if available, for
naming the path.

Intended for 'devtool srctree <recipe>' to set up a tree with the
source for all specified recipes and their dependencies to be able
to do a more convenient local search in source code.

Example:

nfs-utils (console/network) maps to ->
   console/
     network/
       nfs-utils

Signed-off-by: Tobias Hagelborn <tobiasha at axis.com>
---
 meta/classes/srctree.bbclass | 92 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)
 create mode 100644 meta/classes/srctree.bbclass

diff --git a/meta/classes/srctree.bbclass b/meta/classes/srctree.bbclass
new file mode 100644
index 0000000..53df3c6
--- /dev/null
+++ b/meta/classes/srctree.bbclass
@@ -0,0 +1,92 @@
+# Create symlinks to source (${S}) in a separate directory structure.
+#
+# Copyright (C) 2016-2017 Axis Communications AB
+# Author: Tobias Hagelborn <tobias.hagelborn at axis.com>
+#
+# Released under the MIT license (see COPYING.MIT for the terms)
+#
+# This class is used to create a symlink to the source in ${S} in a
+# separate directory structure. ${SECTION} is used, if available, for
+# naming the path.
+#
+# Intended for 'devtool srctree <recipe>' to set up a tree with the
+# source for all specified recipes and their dependencies to be able
+# to do a more convenient local search in source code.
+#
+# Example:
+#
+# nfs-utils (console/network) maps to ->
+#   console/
+#     network/
+#       nfs-utils
+
+# Use the following to extend the srctree class with custom functions
+SRCTREE_EXTENSION ?= ""
+
+inherit ${SRCTREE_EXTENSION}
+
+# Default PN sub-path function
+def srctree_get_path(d):
+    section = d.getVar("SECTION", True)
+    if section:
+        return section.split()[0]
+    else:
+        d.getVar("BPN", True)
+
+# Configurable browsable source tree root
+SRCTREE_DIR ?= "${TOPDIR}/src"
+
+# Path within ${SRCTREE_DIR} for the current PN. Can be overridden in
+# a custom class via ${SRCTREE_EXTENSION} or set to a fixed value.
+# Example: SRCTREE_PN_PATH = "${PN}"
+SRCTREE_PN_PATH ?= "${@srctree_get_path(d)}"
+SYM_S = "${SRCTREE_DIR}/${SRCTREE_PN_PATH}"
+
+create_srctree_readme() {
+	readme="${SRCTREE_DIR}/README"
+
+	[ -e "$readme" ] || cat >"$readme" <<EOF
+This directory contains a directory tree for source code browsing.
+
+IMPORTANT:
+
+ * The source tree is intended for CODE BROWSING ONLY.
+ * The tree contains symbolic links directly to the source as used by BitBake.
+ * Any CHANGES made to the source code MAY BE REMOVED by BitBake AT ANY TIME.
+ * BitBake will NOT automatically rebuild packages due to code changes made
+   directly in the source tree (which you should not do in the first place).
+ * The source tree will NOT reflect changes made to recipes or, e.g., by
+   running "devtool modify -x <recipe>" until "devtool srctree" is re-executed.
+EOF
+}
+
+do_srctree[nostamp] = "1"
+do_srctree[dirs] = "${SRCTREE_DIR}"
+addtask srctree after do_patch
+do_srctree() {
+	if [ "${S}" = "${WORKDIR}" ]; then
+		[ "${SRCTREE_VERBOSE}" != 1 ] ||
+			bbwarn "Not setting up a link for '${SRCTREE_PN_PATH}' (since $""{S} = $""{WORKDIR})"
+		return
+	fi
+
+	# Ignore all cases where S is not properly set up for any reason
+	if [ ! -d "${S}" ]; then
+		[ "${SRCTREE_VERBOSE}" != 1 ] ||
+			bbwarn "No source available for ${PN}";
+		return
+	fi
+
+	mkdir -p $(dirname "${SYM_S}")
+	ln -sfn ${S} ${SYM_S}
+
+	create_srctree_readme
+}
+
+addtask srctree_all after do_srctree
+do_srctree_all[recrdeptask] = "do_srctree_all do_srctree"
+do_srctree_all[recideptask] = "do_${BB_DEFAULT_TASK}"
+do_srctree_all[doc] = "Setup source tree recursivly"
+do_srctree_all() {
+	:
+}
-- 
2.1.4




More information about the Openembedded-core mailing list