Skip to content

Commit c4dc549

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 c4dc549

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

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

+27-11
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,34 @@ 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+
raise
213+
214+
for entry in note_sections:
215+
try:
216+
note_section = entry["NoteSection"]
217+
if note_section["Name"] == ".note.gnu.build-id":
218+
return note_section["Note"]["Build ID"]
219+
except KeyError as e:
220+
e.add_note(
221+
f'Failed to read ".note.gnu.build-id" from NoteSections entry in llvm-readelf for binary {binary}'
222+
)
223+
raise
208224
raise Exception(f"Build ID not found for binary {binary}")
209225

210226
def generate_buildid_dir(

0 commit comments

Comments
 (0)