Skip to content

Commit 0ccf4fb

Browse files
committed
Maintain examples order
1 parent 2ee84e6 commit 0ccf4fb

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

scripts/genExamples.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
os.environ["CFLAGS"] = "-Werror=cpp"
175175
os.environ["CXXFLAGS"] = "-Werror=cpp"
176176

177-
ordered_targets = []
177+
updated_examples = set()
178178

179179
for board in boards:
180180
for platform in platforms[board]:
@@ -329,8 +329,6 @@ def test_build(target, v):
329329
shutil.rmtree(f"{dir}-build")
330330
return ret
331331

332-
ordered_targets.extend(target_locs.keys())
333-
334332
with multiprocessing.Pool(processes=os.cpu_count()) as pool:
335333
ret = pool.starmap(
336334
test_build,
@@ -367,11 +365,32 @@ def test_build(target, v):
367365
"supportRiscV": "riscv" in platform,
368366
}
369367
# Write out after each platform
368+
with open(
369+
f"{os.path.dirname(os.path.realpath(__file__))}/../data/{CURRENT_DATA_VERSION}/examples.json",
370+
"r",
371+
) as f:
372+
current_examples = json.load(f)
373+
374+
current_examples.update(examples)
375+
updated_examples.update(examples.keys())
376+
370377
with open(
371378
f"{os.path.dirname(os.path.realpath(__file__))}/../data/{CURRENT_DATA_VERSION}/examples.json",
372379
"w",
373380
) as f:
374-
sorted_examples = dict(
375-
sorted(examples.items(), key=lambda x: ordered_targets.index(x[0]))
376-
)
377-
json.dump(sorted_examples, f, indent=4)
381+
json.dump(current_examples, f, indent=4)
382+
383+
# Finalise list, removing any examples no longer supported
384+
with open(
385+
f"{os.path.dirname(os.path.realpath(__file__))}/../data/{CURRENT_DATA_VERSION}/examples.json",
386+
"r",
387+
) as f:
388+
current_examples = dict(json.load(f))
389+
390+
current_examples = {k: v for k, v in current_examples.items() if k in updated_examples}
391+
392+
with open(
393+
f"{os.path.dirname(os.path.realpath(__file__))}/../data/{CURRENT_DATA_VERSION}/examples.json",
394+
"w",
395+
) as f:
396+
json.dump(current_examples, f, indent=4)

0 commit comments

Comments
 (0)