Skip to contentSkip to conversation

meta: save relative paths to qemuboot.conf and testdata.json

PATCH New brian avery 1 participant 4 messages Apr 19, 2017

lore
Share & tools
lore
#0 lore raw

cover meta: save relative paths to qemuboot.conf and testdata.json

This patch set changes the behaviour to save relative paths instead of absolute paths into the qemuboot.conf and the testdata.json files. A sed test verified that this seems to work without complication. If certain variables, need to be excluded from this relative path fix, that can be done with subsequent patches.

This is to fix YOCTO #11375 https://bugzilla.yoctoproject.org/show_bug.cgi?id=11375

-brian

The following changes since commit 1423508b29fc557d8a1305f39c33de33e28d9003:

bitbake: bitbake: Update version to 1.34.0 for stable release (2017-04-19 10:42:12 +0100)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib bavery/poky/relpath_11375
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=bavery/poky/relpath_11375

brian avery (3):
meta: add search,replace strings to export2json rootfs-postcommands.bbclass: save relative paths qemuboot.bbclass: save relative paths in conf file

 meta/classes/qemuboot.bbclass            | 7 +++++++
 meta/classes/rootfs-postcommands.bbclass | 8 +++++---
 meta/lib/oe/data.py                      | 6 ++++--
 3 files changed, 16 insertions(+), 5 deletions(-)

--
1.9.1

#1 lore raw

PATCH 1/3 meta: add search, replace strings to export2json

We want to be able to save relative paths so that we can relocate the deploy dir images and kernels, yet still have qemu and testimage work correctly. This extends export2json with 2 named arguments so a search/replace operation can be done to remove the leading path.

[YOCTO #11375]

---
 meta/lib/oe/data.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
meta/lib/oe/data.py +4 -2
index 80bba2b..b8901e6 100644
@@ -17,7 +17,7 @@ def typed_value(key, d):
     except (TypeError, ValueError) as exc:
         bb.msg.fatal("Data", "%s: %s" % (key, str(exc)))
 
-def export2json(d, json_file, expand=True):
+def export2json(d, json_file, expand=True, searchString="",replaceString=""):
     data2export = {}
     keys2export = []
 
@@ -37,9 +37,11 @@ def export2json(d, json_file, expand=True):
 
     for key in keys2export:
         try:
-            data2export[key] = d.getVar(key, expand)
+            data2export[key] = d.getVar(key, expand).replace(searchString,replaceString)
         except bb.data_smart.ExpansionError:
             data2export[key] = ''
+        except AttributeError:
+            pass
 
     with open(json_file, "w") as f:
         json.dump(data2export, f, skipkeys=True, indent=4, sort_keys=True)
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/3 rootfs-postcommands.bbclass: save relative paths

In reply to brian avery

We pass the TOPDIR to do a search/replace in export2json so that we save relative paths in the testdata.json file rather than absolute paths. This is to allow the images and kernels to be relocated yet still allow testimage to work.

[YOCTO #11375]

---
 meta/classes/rootfs-postcommands.bbclass | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
meta/classes/rootfs-postcommands.bbclass +5 -3
index c42829d..498174a 100644
@@ -132,7 +132,7 @@ zap_empty_root_password () {
 	if [ -e ${IMAGE_ROOTFS}/etc/passwd ]; then
 		sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/passwd
 	fi
-} 
+}
 
 #
 # allow dropbear/openssh to accept root logins and logins from accounts with an empty password string
@@ -243,7 +243,7 @@ python write_image_manifest () {
         os.symlink(os.path.basename(manifest_name), manifest_link)
 }
 
-# Can be use to create /etc/timestamp during image construction to give a reasonably 
+# Can be use to create /etc/timestamp during image construction to give a reasonably
 # sane default time setting
 rootfs_update_timestamp () {
 	date -u +%4Y%2m%2d%2H%2M%2S >${IMAGE_ROOTFS}/etc/timestamp
@@ -286,6 +286,7 @@ rootfs_sysroot_relativelinks () {
 	sysroot-relativelinks.py ${SDK_OUTPUT}/${SDKTARGETSYSROOT}
 }
 
+
 # Generated test data json file
 python write_image_test_data() {
     from oe.data import export2json
@@ -294,7 +295,8 @@ python write_image_test_data() {
     testdata_link = "%s/%s.testdata.json" % (d.getVar('DEPLOY_DIR_IMAGE'), d.getVar('IMAGE_LINK_NAME'))
 
     bb.utils.mkdirhier(os.path.dirname(testdata))
-    export2json(d, testdata)
+    searchString = "%s/"%(d.getVar("TOPDIR")).replace("//","/")
+    export2json(d, testdata,searchString=searchString,replaceString="")
 
     if os.path.lexists(testdata_link):
        os.remove(testdata_link)
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/3 qemuboot.bbclass: save relative paths in conf file

In reply to brian avery

This saves relative paths in the qemuboot.conf file instead of absolute paths. This is to allow the images and kernels to be relocated and still have the testimage and runqemu work.

[YOCTO #11375]

---
 meta/classes/qemuboot.bbclass | 7 +++++++
 1 file changed, 7 insertions(+)
meta/classes/qemuboot.bbclass +7 -0
index cc5314e..86b3060 100644
@@ -84,6 +84,7 @@ python do_write_qemuboot_conf() {
 
     qemuboot = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR'), d.getVar('IMAGE_NAME'))
     qemuboot_link = "%s/%s.qemuboot.conf" % (d.getVar('IMGDEPLOYDIR'), d.getVar('IMAGE_LINK_NAME'))
+    topdir="%s/"%(d.getVar('TOPDIR')).replace("//","/")
     cf = configparser.ConfigParser()
     cf.add_section('config_bsp')
     for k in qemuboot_vars(d):
@@ -94,6 +95,9 @@ python do_write_qemuboot_conf() {
                                'qemu-helper-native/1.0-r1/recipe-sysroot-native/usr/bin/')
         else:
             val = d.getVar(k)
+        # we only want to write out relative paths so that we can relocate images
+        # and still run them
+        val=val.replace(topdir,"")
         cf.set('config_bsp', k, '%s' % val)
 
     # QB_DEFAULT_KERNEL's value of KERNEL_IMAGETYPE is the name of a symlink
@@ -101,6 +105,9 @@ python do_write_qemuboot_conf() {
     # Read the link and replace it with the full filename of the target.
     kernel_link = os.path.join(d.getVar('DEPLOY_DIR_IMAGE'), d.getVar('QB_DEFAULT_KERNEL'))
     kernel = os.path.realpath(kernel_link)
+    # we only want to write out relative paths so that we can relocate images
+    # and still run them
+    kernel=kernel.replace(topdir,"")
     cf.set('config_bsp', 'QB_DEFAULT_KERNEL', kernel)
 
     bb.utils.mkdirhier(os.path.dirname(qemuboot))
Signature · 1 line
1.9.1