[PATCH] build: Use Python tarfile instead of pax

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Aug 18 11:16:55 UTC 2020


This patch is for the new build system.
---
 spec/build/testsuites/libtests/dl01.yml   |  2 +-
 spec/build/testsuites/libtests/dl02.yml   |  2 +-
 spec/build/testsuites/libtests/dl04.yml   |  2 +-
 spec/build/testsuites/libtests/dl05.yml   |  2 +-
 spec/build/testsuites/libtests/dl06.yml   |  4 ++--
 spec/build/testsuites/libtests/dl07.yml   |  2 +-
 spec/build/testsuites/libtests/dl08.yml   |  2 +-
 spec/build/testsuites/libtests/dl09.yml   |  2 +-
 spec/build/testsuites/libtests/dl10.yml   |  2 +-
 spec/build/testsuites/libtests/grp.yml    |  2 --
 spec/build/testsuites/libtests/optpax.yml | 14 ------------
 wscript                                   | 27 ++++++++++++-----------
 12 files changed, 24 insertions(+), 39 deletions(-)
 delete mode 100644 spec/build/testsuites/libtests/optpax.yml

diff --git a/spec/build/testsuites/libtests/dl01.yml b/spec/build/testsuites/libtests/dl01.yml
index 42e482bcc7..49ff5a0eb1 100644
--- a/spec/build/testsuites/libtests/dl01.yml
+++ b/spec/build/testsuites/libtests/dl01.yml
@@ -9,7 +9,7 @@ do-build: |
   objs = []
   objs.append(self.cc(bld, bic, path + "dl01-o1.c"))
   tar = path + "dl01.tar"
-  self.pax(bld, objs, [path], tar)
+  self.tar(bld, objs, [path], tar)
   tar_c, tar_h = self.bin2c(bld, tar)
   objs = []
   objs.append(self.cc(bld, bic, tar_c))
diff --git a/spec/build/testsuites/libtests/dl02.yml b/spec/build/testsuites/libtests/dl02.yml
index 83bc4d159c..e6b1d0fe11 100644
--- a/spec/build/testsuites/libtests/dl02.yml
+++ b/spec/build/testsuites/libtests/dl02.yml
@@ -10,7 +10,7 @@ do-build: |
   objs.append(self.cc(bld, bic, path + "dl02-o1.c"))
   objs.append(self.cc(bld, bic, path + "dl02-o2.c"))
   tar = path + "dl02.tar"
-  self.pax(bld, objs, [path], tar)
+  self.tar(bld, objs, [path], tar)
   tar_c, tar_h = self.bin2c(bld, tar)
   objs = []
   objs.append(self.cc(bld, bic, tar_c))
diff --git a/spec/build/testsuites/libtests/dl04.yml b/spec/build/testsuites/libtests/dl04.yml
index 8957f9eb40..061c655675 100644
--- a/spec/build/testsuites/libtests/dl04.yml
+++ b/spec/build/testsuites/libtests/dl04.yml
@@ -10,7 +10,7 @@ do-build: |
   objs = []
   objs.append(self.cxx(bld, bic, path + "dl04-o4.cc"))
   tar = path + "dl04.tar"
-  self.pax(bld, objs, [path], tar)
+  self.tar(bld, objs, [path], tar)
   tar_c, tar_h = self.bin2c(bld, tar)
   objs = []
   objs.append(self.cc(bld, bic, tar_c))
diff --git a/spec/build/testsuites/libtests/dl05.yml b/spec/build/testsuites/libtests/dl05.yml
index 3e049dce29..67370ccbc1 100644
--- a/spec/build/testsuites/libtests/dl05.yml
+++ b/spec/build/testsuites/libtests/dl05.yml
@@ -10,7 +10,7 @@ do-build: |
   objs = []
   objs.append(self.cxx(bld, bic, path + "dl05-o5.cc"))
   tar = path + "dl05.tar"
-  self.pax(bld, objs, [path], tar)
+  self.tar(bld, objs, [path], tar)
   tar_c, tar_h = self.bin2c(bld, tar)
   objs = []
   objs.append(self.cc(bld, bic, tar_c))
diff --git a/spec/build/testsuites/libtests/dl06.yml b/spec/build/testsuites/libtests/dl06.yml
index cd19712b42..2f5d4ab08d 100644
--- a/spec/build/testsuites/libtests/dl06.yml
+++ b/spec/build/testsuites/libtests/dl06.yml
@@ -7,7 +7,7 @@ cppflags: []
 do-build: |
   path = "testsuites/libtests/dl06/"
   pre_tar = path + "dl06-pre.tar"
-  self.pax(bld, path + "dl06_pre_file", [path], pre_tar)
+  self.tar(bld, path + "dl06_pre_file", [path], pre_tar)
   pre_tar_c, pre_tar_h = self.bin2c(bld, pre_tar, name="dl06_tar")
   objs = []
   objs.append(self.cc(bld, bic, pre_tar_c))
@@ -22,7 +22,7 @@ do-build: |
   dl06_rap = path + "dl06.rap"
   self.rtems_rap(bld, dl06_pre, objs, ["m"], dl06_rap)
   tar = path + "dl06.tar"
-  self.pax(bld, dl06_rap, [path], tar)
+  self.tar(bld, dl06_rap, [path], tar)
   tar_c, tar_h = self.bin2c(bld, tar)
   objs.append(self.cc(bld, bic, tar_c))
   objs.append(self.cc(bld, bic, path + "init.c", deps=[tar_h], cppflags=bld.env.TEST_DL06_CPPFLAGS))
diff --git a/spec/build/testsuites/libtests/dl07.yml b/spec/build/testsuites/libtests/dl07.yml
index 3641086b62..2fedef4795 100644
--- a/spec/build/testsuites/libtests/dl07.yml
+++ b/spec/build/testsuites/libtests/dl07.yml
@@ -13,7 +13,7 @@ do-build: |
   objs.append(self.cc(bld, bic, path + "dl07-o4.c"))
   objs.append(self.cc(bld, bic, path + "dl07-o5.c"))
   tar = path + "dl07.tar"
-  self.pax(bld, objs, [path], tar)
+  self.tar(bld, objs, [path], tar)
   tar_c, tar_h = self.bin2c(bld, tar)
   objs = []
   objs.append(self.cc(bld, bic, tar_c))
diff --git a/spec/build/testsuites/libtests/dl08.yml b/spec/build/testsuites/libtests/dl08.yml
index 43a74e3065..94f16fe196 100644
--- a/spec/build/testsuites/libtests/dl08.yml
+++ b/spec/build/testsuites/libtests/dl08.yml
@@ -18,7 +18,7 @@ do-build: |
   objs.append(self.ar(bld, lib_objs, path + "libdl08_2.a"))
   objs.append(self.cc(bld, bic, path + "dl08-o1.c"))
   tar = path + "dl08.tar"
-  self.pax(bld, [path + "etc/libdl.conf"] + objs, [path], tar)
+  self.tar(bld, [path + "etc/libdl.conf"] + objs, [path], tar)
   tar_c, tar_h = self.bin2c(bld, tar)
   objs = []
   objs.append(self.cc(bld, bic, tar_c))
diff --git a/spec/build/testsuites/libtests/dl09.yml b/spec/build/testsuites/libtests/dl09.yml
index 8f9557edc6..7f9da4c3b9 100644
--- a/spec/build/testsuites/libtests/dl09.yml
+++ b/spec/build/testsuites/libtests/dl09.yml
@@ -13,7 +13,7 @@ do-build: |
   objs.append(self.cc(bld, bic, path + "dl09-o4.c"))
   objs.append(self.cc(bld, bic, path + "dl09-o5.c"))
   tar = path + "dl09.tar"
-  self.pax(bld, objs, [path], tar)
+  self.tar(bld, objs, [path], tar)
   tar_c, tar_h = self.bin2c(bld, tar)
   objs = []
   objs.append(self.cc(bld, bic, tar_c))
diff --git a/spec/build/testsuites/libtests/dl10.yml b/spec/build/testsuites/libtests/dl10.yml
index ba09a6f444..b3e4bc0ded 100644
--- a/spec/build/testsuites/libtests/dl10.yml
+++ b/spec/build/testsuites/libtests/dl10.yml
@@ -18,7 +18,7 @@ do-build: |
   objs.append(self.ar(bld, lib_objs, path + "libdl10_2.a"))
   objs.append(self.cc(bld, bic, path + "dl10-o1.c"))
   tar = path + "dl10.tar"
-  self.pax(bld, [path + "etc/libdl.conf"] + objs, [path], tar)
+  self.tar(bld, [path + "etc/libdl.conf"] + objs, [path], tar)
   tar_c, tar_h = self.bin2c(bld, tar)
   objs = []
   objs.append(self.cc(bld, bic, tar_c))
diff --git a/spec/build/testsuites/libtests/grp.yml b/spec/build/testsuites/libtests/grp.yml
index aff46c9f8f..2b1f2727cf 100644
--- a/spec/build/testsuites/libtests/grp.yml
+++ b/spec/build/testsuites/libtests/grp.yml
@@ -16,8 +16,6 @@ links:
   uid: optbin2c
 - role: build-dependency
   uid: optgzip
-- role: build-dependency
-  uid: optpax
 - role: build-dependency
   uid: optrtemsld
 - role: build-dependency
diff --git a/spec/build/testsuites/libtests/optpax.yml b/spec/build/testsuites/libtests/optpax.yml
deleted file mode 100644
index 097b60291b..0000000000
--- a/spec/build/testsuites/libtests/optpax.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
-actions:
-- set-value: pax
-- find-program: null
-- env-assign: PAX
-build-type: option
-copyrights:
-- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
-default: null
-default-by-variant: []
-description: ''
-enabled-by: true
-links: []
-type: build
diff --git a/wscript b/wscript
index 5463b1c788..2e42918ebb 100755
--- a/wscript
+++ b/wscript
@@ -405,22 +405,23 @@ class Item(object):
         bld(rule="${XZ} < ${SRC} > ${TGT}", source=source, target=target)
         return target
 
-    def pax(self, bld, source, remove, target):
+    def tar(self, bld, source, remove, target):
         def run(task):
+            import tarfile
+
+            tar = tarfile.TarFile(
+                task.outputs[0].abspath(), "w", format=tarfile.USTAR_FORMAT
+            )
             srcpath = bld.path.abspath() + "/"
             bldpath = bld.bldnode.abspath() + "/"
-            cmd = [bld.env.PAX[0], "-w", "-f", task.outputs[0].abspath()]
-            for r in remove:
-                cmd.extend(
-                    [
-                        "-s",
-                        "," + srcpath + r + ",,",
-                        "-s",
-                        "," + bldpath + r + ",,",
-                    ]
-                )
-            cmd.extend([i.abspath() for i in task.inputs])
-            return task.exec_command(cmd)
+            for src in task.inputs:
+                src = src.abspath()
+                dst = src
+                for r in remove:
+                    dst = src.replace(srcpath + r, "").replace(bldpath + r, "")
+                tar.add(src, dst)
+            tar.close()
+            return 0
 
         bld(rule=run, source=source, target=target)
         return target
-- 
2.26.2



More information about the devel mailing list