diff --git a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-hello.xml b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-hello.xml
index f6d82b4f3f..8b7edbff54 100644
--- a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-hello.xml
+++ b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-hello.xml
@@ -399,7 +399,7 @@ ERROR: Unable to parse base: ParseError in configuration INHERITs: Could not inh
BBFILES += "${LAYERDIR}/*.bb"
BBFILE_COLLECTIONS += "mylayer"
- BBFILE_PATTERN_mylayer := "^${LAYERDIR}/"
+ BBFILE_PATTERN_mylayer := "^${LAYERDIR_RE}/"
For information on these variables, click the links
to go to the definitions in the glossary.
diff --git a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-ref-variables.xml b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-ref-variables.xml
index ae7e4cee8c..4d06ff950c 100644
--- a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-ref-variables.xml
+++ b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-ref-variables.xml
@@ -1636,6 +1636,17 @@
+ LAYERDIR_RE
+
+ When used inside the layer.conf configuration
+ file, this variable provides the path of the current layer,
+ escaped for use in a regular expression
+ (BBFILE_PATTERN).
+ This variable is not available outside of layer.conf
+ and references are expanded immediately when parsing of the file completes.
+
+
+
LAYERVERSIONOptionally specifies the version of a layer as a single number.
diff --git a/bitbake/lib/bb/cookerdata.py b/bitbake/lib/bb/cookerdata.py
index fba95afa54..1615db5b17 100644
--- a/bitbake/lib/bb/cookerdata.py
+++ b/bitbake/lib/bb/cookerdata.py
@@ -22,9 +22,11 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-import os, sys
-from functools import wraps
import logging
+import os
+import re
+import sys
+from functools import wraps
import bb
from bb import data
import bb.parse
@@ -296,9 +298,12 @@ class CookerDataBuilder(object):
if layer.endswith('/'):
layer = layer.rstrip('/')
data.setVar('LAYERDIR', layer)
+ data.setVar('LAYERDIR_RE', re.escape(layer))
data = parse_config_file(os.path.join(layer, "conf", "layer.conf"), data)
data.expandVarref('LAYERDIR')
+ data.expandVarref('LAYERDIR_RE')
+ data.delVar('LAYERDIR_RE')
data.delVar('LAYERDIR')
if not data.getVar("BBPATH", True):