Skip to contentSkip to conversation

Revert "package.bbclass: Add '-b' option to file call in isELF"

PATCH New Andre McCurdy 1 participant 4 messages May 4, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 Revert "package.bbclass: Add '-b' option to file call in isELF"

This reverts commit 46ddc11a8be79515b4ab9f9f7568c3d624ac72fe.

The change is good in master but became subtly broken during the backport to rocko. Either the path passed to file should be quoted using double quotes (with any " chars in the path being escaped) or the path should be quoted using single quotes (and then any " chars in the path should NOT be escaped). Escaping " chars and using single quotes will cause problems for filenames containing " chars.

---
 meta/classes/package.bbclass | 2 +-
 meta/lib/oe/package.py       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
meta/classes/package.bbclass +1 -1
index cee64f3..2053d46 100644
@@ -901,7 +901,7 @@ python split_and_strip_files () {
     # 16 - kernel module
     def isELF(path):
         type = 0
-        ret, result = oe.utils.getstatusoutput("file -b '%s'" % path.replace("\"", "\\\""))
+        ret, result = oe.utils.getstatusoutput("file \"%s\"" % path.replace("\"", "\\\""))
 
         if ret:
             msg = "split_and_strip_files: 'file %s' failed" % path
meta/lib/oe/package.py +1 -1
index 599fca6..1e5c3aa 100644
@@ -73,7 +73,7 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
     def is_elf(path):
         exec_type = 0
         ret, result = oe.utils.getstatusoutput(
-            "file -b \"%s\"" % path.replace("\"", "\\\""))
+            "file \"%s\"" % path.replace("\"", "\\\""))
 
         if ret:
             bb.error("split_and_strip_files: 'file %s' failed" % path)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/4 package.bbclass: use single quotes for path passed to file in isELF()

Apparently there are recipes in the wild which generate files with filenames containing '$' characters - which cause errors during packaging.

Instead of adding another special case to escape '$' characters when constructing the command passed to oe.utils.getstatusoutput(), switch to using single quotes to quote the path - and therefore make isELF() consistent with the way filenames and paths are quoted by every other caller of oe.utils.getstatusoutput() in oe-core.

(cherry picked from commit 7877761534b0c2492da6289e9f2269d41b6ed464)
---
 meta/classes/package.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/classes/package.bbclass +1 -1
index 2053d46..e68299e 100644
@@ -901,7 +901,7 @@ python split_and_strip_files () {
     # 16 - kernel module
     def isELF(path):
         type = 0
-        ret, result = oe.utils.getstatusoutput("file \"%s\"" % path.replace("\"", "\\\""))
+        ret, result = oe.utils.getstatusoutput("file '%s'" % path)
 
         if ret:
             msg = "split_and_strip_files: 'file %s' failed" % path
Signature · 1 line
1.9.1
#2 lore raw

PATCH 3/4 package.bbclass: Add '-b' option to file call in isELF

In reply to Andre McCurdy

From: Mark Hatle <[email protected]>

The isELF function works by running:

result = file <pathname>
if 'ELF' in result

By default 'file' will prepend the result with the path name of the file that is being checked. This usually works fine, such as:

$ file /home/foo/openembedded-core/meta/classes/package.bbclass
/home/foo/openembedded-core/meta/classes/package.bbclass: Python script, ASCII text executable, with very long lines

However, if the path includes 'ELF', ELF will end up in the result, and then the check will return positive.

$ file /home/ELF/openembedded-core/meta/classes/package.bbclass
/home/ELF/openembedded-core/meta/classes/package.bbclass: Python script, ASCII text executable, with very long lines

This will then result in the isELF coming back true, and possibly causing the checks that use isELF, such as the 'is it already stripped' check, to do the incorrect thing.

Adding the '-b' option to file will result in the path being omitted in the result:

$ file /home/ELF/openembedded-core/meta/classes/package.bbclass
Python script, ASCII text executable, with very long lines
(cherry picked from commit 5a324e9b2cf6378f8eaa4e394f9cb36d4e2680ac)
---
 meta/classes/package.bbclass | 2 +-
 meta/lib/oe/package.py       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
meta/classes/package.bbclass +1 -1
index e68299e..2a5d8a5 100644
@@ -901,7 +901,7 @@ python split_and_strip_files () {
     # 16 - kernel module
     def isELF(path):
         type = 0
-        ret, result = oe.utils.getstatusoutput("file '%s'" % path)
+        ret, result = oe.utils.getstatusoutput("file -b '%s'" % path)
 
         if ret:
             msg = "split_and_strip_files: 'file %s' failed" % path
meta/lib/oe/package.py +1 -1
index 1e5c3aa..599fca6 100644
@@ -73,7 +73,7 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
     def is_elf(path):
         exec_type = 0
         ret, result = oe.utils.getstatusoutput(
-            "file \"%s\"" % path.replace("\"", "\\\""))
+            "file -b \"%s\"" % path.replace("\"", "\\\""))
 
         if ret:
             bb.error("split_and_strip_files: 'file %s' failed" % path)
Signature · 1 line
1.9.1
#3 lore raw

PATCH 4/4 package.py: use single quotes for path passed to file in is_elf()

In reply to Andre McCurdy

Align package.py is_elf() with recent changes in package.bbclass isELF():

http://git.openembedded.org/openembedded-core/commit/?id=7877761534b0c2492da6289e9f2269d41b6ed464

(cherry picked from commit ab056c7f6065f310be4dd256ceb45f85ff981f69)
---
 meta/lib/oe/package.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
meta/lib/oe/package.py +1 -2
index 599fca6..4f3e21a 100644
@@ -72,8 +72,7 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, qa_already_stripped=
     # 16 - kernel module
     def is_elf(path):
         exec_type = 0
-        ret, result = oe.utils.getstatusoutput(
-            "file -b \"%s\"" % path.replace("\"", "\\\""))
+        ret, result = oe.utils.getstatusoutput("file -b '%s'" % path)
 
         if ret:
             bb.error("split_and_strip_files: 'file %s' failed" % path)
Signature · 1 line
1.9.1