Skip to content

Commit 5fb116d

Browse files
committed
Make fuchsia-test-runner.py compatible with new JSON output from llvm-readelf
[A recent commit in LLVM](llvm/llvm-project@ab930ee) modified the JSON output of LLVM. The LLVM change renamed "Notes" to "NoteSections" and inserted a new "Notes" key nested under each "NoteSection". This change shores up exceptions around reading the JSON output of llvm-readelf and reads from "NoteSections" instead of the non-existent "Notes".
1 parent f79fae3 commit 5fb116d

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

src/ci/docker/scripts/fuchsia-test-runner.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,36 @@ def build_id(self, binary):
193193
stderr=subprocess.STDOUT,
194194
)
195195
if process.returncode:
196-
self.env_logger.error(
197-
f"llvm-readelf failed for binary {binary} with output {process.stdout}"
196+
e = f"llvm-readelf failed for binary {binary} with output {process.stdout}"
197+
self.env_logger.error(e)
198+
raise Exception(e)
199+
200+
elf_output = json.loads(process.stdout)
201+
if len(elf_output) != 1:
202+
raise Exception(
203+
f"JSON returned by llvm-readelf for binary {binary} is not a list with a single entry"
198204
)
199-
raise Exception(f"Unreadable build-id for binary {binary}")
200-
data = json.loads(process.stdout)
201-
if len(data) != 1:
202-
raise Exception(f"Unreadable output from llvm-readelf for binary {binary}")
203-
notes = data[0]["Notes"]
204-
for note in notes:
205-
note_section = note["NoteSection"]
206-
if note_section["Name"] == ".note.gnu.build-id":
207-
return note_section["Note"]["Build ID"]
205+
206+
try:
207+
note_sections = elf_output[0]["NoteSections"]
208+
except KeyError as e:
209+
e.add_note(
210+
f'Failed to read "NoteSections" from llvm-readelf for binary {binary}'
211+
)
212+
e.add_note(f"elf_output: {elf_output}")
213+
raise
214+
215+
for entry in note_sections:
216+
try:
217+
note_section = entry["NoteSection"]
218+
if note_section["Name"] == ".note.gnu.build-id":
219+
return note_section["Notes"][0]["Build ID"]
220+
except KeyError as e:
221+
e.add_note(
222+
f'Failed to read ".note.gnu.build-id" from NoteSections entry in llvm-readelf for binary {binary}'
223+
)
224+
e.add_note(f"NoteSections: {note_sections}")
225+
raise
208226
raise Exception(f"Build ID not found for binary {binary}")
209227

210228
def generate_buildid_dir(

0 commit comments

Comments
 (0)