Skip to contentSkip to conversation

sstate.bbclass: fix issue while handling long sstate filenames

PATCH Superseded Jaewon Lee 2 participants 2 messages Feb 6, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jaewon Lee

author
#0 lore raw

PATCH 1/1 sstate.bbclass: fix issue while handling long sstate filenames

When moving to python3, divison using '/' now returns float instead of an integer. In upstream commit b8025e972081b70960ffcbcbe43a7118041556a1 sstate filenames longer than the limit are changed to just include necessary info + 3 fields just for information. The space left over after the necessary info is divided into 3 for each of the fields. Casting the outcome of that division to int to solve the following error message:

avail = (254 - len(hash + "_" + taskname + extension) - len(components[0]) - len(components[1]) - len(components[5]) - len(components[6]) - 7) / 3

Quoted 1 line
       components[2] = components[2][:avail]
             components[3] = components[3][:avail]

TypeError: slice indices must be integers or None or have an __index__ method

---
 meta/classes/sstate.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/classes/sstate.bbclass +1 -1
index faa6470..53a6d06 100644
@@ -20,7 +20,7 @@ def generate_sstatefn(spec, hash, taskname, siginfo, d):
         components = spec.split(":")
         # Fields 0,5,6 are mandatory, 1 is most useful, 2,3,4 are just for information
         # 7 is for the separators
-        avail = (254 - len(hash + "_" + taskname + extension) - len(components[0]) - len(components[1]) - len(components[5]) - len(components[6]) - 7) / 3
+        avail = int((254 - len(hash + "_" + taskname + extension) - len(components[0]) - len(components[1]) - len(components[5]) - len(components[6]) - 7) / 3)
         components[2] = components[2][:avail]
         components[3] = components[3][:avail]
         components[4] = components[4][:avail]
Signature · 1 line
2.7.4
#1 lore raw
Quoted 27 lines · Jaewon Lee

When moving to python3, divison using '/' now returns float instead of an integer. In upstream commit b8025e972081b70960ffcbcbe43a7118041556a1 sstate filenames longer than the limit are changed to just include necessary info + 3 fields just for information. The space left over after the necessary info is divided into 3 for each of the fields. Casting the outcome of that division to int to solve the following error message:

avail = (254 - len(hash + "_" + taskname + extension) - len(components[0]) - len(components[1]) - len(components[5]) - len(components[6]) - 7) / 3
> components[2] = components[2][:avail]
components[3] = components[3][:avail]
TypeError: slice indices must be integers or None or have an __index__ method

---
  meta/classes/sstate.bbclass | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
meta/classes/sstate.bbclass +0 -0
index faa6470..53a6d06 100644

meta/classes/sstate.bbclass def generate_sstatefn(spec, hash, taskname, siginfo, d): · line 23

Quoted 5 lines
meta/classes/sstate.bbclass +1 -1
@@ -20,7 +20,7 @@ def generate_sstatefn(spec, hash, taskname, siginfo, d):
          components = spec.split(":")
          # Fields 0,5,6 are mandatory, 1 is most useful, 2,3,4 are just for information
          # 7 is for the separators
-        avail = (254 - len(hash + "_" + taskname + extension) - len(components[0]) - len(components[1]) - len(components[5]) - len(components[6]) - 7) / 3
+        avail = int((254 - len(hash + "_" + taskname + extension) - len(components[0]) - len(components[1]) - len(components[5]) - len(components[6]) - 7) / 3)

Python has a nifty // operator that resembles integer division from C:

Quoted 1 line
Quoted 1 line
Quoted 1 line

3 / 2

1.5

Quoted 1 line
Quoted 1 line
Quoted 1 line

3 // 2

1

// Martin

Quoted 4 lines
          components[2] = components[2][:avail]
          components[3] = components[3][:avail]
          components[4] = components[4][:avail]