aboutsummaryrefslogtreecommitdiffstats
path: root/meta/classes/populate_sdk_base.bbclass
diff options
context:
space:
mode:
authorHaris Okanovic <haris.okanovic@ni.com>2015-11-17 14:21:12 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-12-01 21:07:19 +0000
commit2658200fa2b3df08880ee937a3de5cb2866f8a50 (patch)
treebfb84d0ca0a7ad6aa6594c17acd6b755dc917e27 /meta/classes/populate_sdk_base.bbclass
parent9e30e849eda3b0a0c54d3f7ed0102760fdaef06c (diff)
downloadopenembedded-core-contrib-2658200fa2b3df08880ee937a3de5cb2866f8a50.tar.gz
populate_sdk_base: Add sysroot symlink check
Add optional check to do_populate_sdk() that verifies SDK sysroots don't contain dangling or escaping symlinks before attempting to tar an archive. Such links may fail a `tar -h` operation (-h => follow symlinks) or archive the build system's files. Set CHECK_SDK_SYSROOTS = "1" to enable this check. Use case: The -h option may be set via SDKTAROPTS in some configurations to create symlink-less SDK archives for Windows file systems. Signed-off-by: Haris Okanovic <haris.okanovic@ni.com> Signed-off-by: Ross Burton <ross.burton@intel.com>
Diffstat (limited to 'meta/classes/populate_sdk_base.bbclass')
-rw-r--r--meta/classes/populate_sdk_base.bbclass53
1 files changed, 52 insertions, 1 deletions
diff --git a/meta/classes/populate_sdk_base.bbclass b/meta/classes/populate_sdk_base.bbclass
index 35e129b068..23dc1156bd 100644
--- a/meta/classes/populate_sdk_base.bbclass
+++ b/meta/classes/populate_sdk_base.bbclass
@@ -80,7 +80,7 @@ python write_host_sdk_manifest () {
POPULATE_SDK_POST_TARGET_COMMAND_append = " write_target_sdk_manifest ; "
POPULATE_SDK_POST_HOST_COMMAND_append = " write_host_sdk_manifest; "
-SDK_POSTPROCESS_COMMAND = " create_sdk_files; tar_sdk; ${SDK_PACKAGING_FUNC}; "
+SDK_POSTPROCESS_COMMAND = " create_sdk_files; check_sdk_sysroots; tar_sdk; ${SDK_PACKAGING_FUNC}; "
# Some archs override this, we need the nativesdk version
# turns out this is hard to get from the datastore due to TRANSLATED_TARGET_ARCH
@@ -120,6 +120,57 @@ fakeroot create_sdk_files() {
sed -i -e "s:##DEFAULT_INSTALL_DIR##:$escaped_sdkpath:" ${SDK_OUTPUT}/${SDKPATH}/relocate_sdk.py
}
+python check_sdk_sysroots() {
+ # Fails build if there are broken or dangling symlinks in SDK sysroots
+
+ if d.getVar('CHECK_SDK_SYSROOTS', True) != '1':
+ # disabled, bail out
+ return
+
+ def norm_path(path):
+ return os.path.abspath(path)
+
+ # Get scan root
+ SCAN_ROOT = norm_path("${SDK_OUTPUT}/${SDKPATH}/sysroots/")
+
+ bb.note('Checking SDK sysroots at ' + SCAN_ROOT)
+
+ def check_symlink(linkPath):
+ if not os.path.islink(linkPath):
+ return
+
+ linkDirPath = os.path.dirname(linkPath)
+
+ targetPath = os.readlink(linkPath)
+ if not os.path.isabs(targetPath):
+ targetPath = os.path.join(linkDirPath, targetPath)
+ targetPath = norm_path(targetPath)
+
+ if SCAN_ROOT != os.path.commonprefix( [SCAN_ROOT, targetPath] ):
+ bb.error("Escaping symlink {0!s} --> {1!s}".format(linkPath, targetPath))
+ return
+
+ if not os.path.exists(targetPath):
+ bb.error("Broken symlink {0!s} --> {1!s}".format(linkPath, targetPath))
+ return
+
+ if os.path.isdir(targetPath):
+ dir_walk(targetPath)
+
+ def walk_error_handler(e):
+ bb.error(str(e))
+
+ def dir_walk(rootDir):
+ for dirPath,subDirEntries,fileEntries in os.walk(rootDir, followlinks=False, onerror=walk_error_handler):
+ entries = subDirEntries + fileEntries
+ for e in entries:
+ ePath = os.path.join(dirPath, e)
+ check_symlink(ePath)
+
+ # start
+ dir_walk(SCAN_ROOT)
+}
+
SDKTAROPTS = "--owner=root --group=root"
fakeroot tar_sdk() {