Title: [293143] trunk/Tools
- Revision
- 293143
- Author
- ysuz...@apple.com
- Date
- 2022-04-20 21:08:17 -0700 (Wed, 20 Apr 2022)
Log Message
Generate well-formed JSON for compile_commands.json
https://bugs.webkit.org/show_bug.cgi?id=239584
Reviewed by Mark Lam.
Currently, compile_commands.json always has one trailing comma in the main array. While clangd does not care this,
it is ill-formed JSON, and some other tools consuming compile_commands.json can fail.
This patch makes it so that generated compile_commands.json has well-formed JSON.
* Tools/Scripts/generate-compile-commands:
Canonical link: https://commits.webkit.org/249841@main
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (293142 => 293143)
--- trunk/Tools/ChangeLog 2022-04-21 03:56:58 UTC (rev 293142)
+++ trunk/Tools/ChangeLog 2022-04-21 04:08:17 UTC (rev 293143)
@@ -1,3 +1,16 @@
+2022-04-20 Yusuke Suzuki <ysuz...@apple.com>
+
+ Generate well-formed JSON for compile_commands.json
+ https://bugs.webkit.org/show_bug.cgi?id=239584
+
+ Reviewed by Mark Lam.
+
+ Currently, compile_commands.json always has one trailing comma in the main array. While clangd does not care this,
+ it is ill-formed JSON, and some other tools consuming compile_commands.json can fail.
+ This patch makes it so that generated compile_commands.json has well-formed JSON.
+
+ * Scripts/generate-compile-commands:
+
2022-04-20 Wenson Hsieh <wenson_hs...@apple.com>
Avoid falling back to snapshots for transparent images when triggering batch text recognition
Modified: trunk/Tools/Scripts/generate-compile-commands (293142 => 293143)
--- trunk/Tools/Scripts/generate-compile-commands 2022-04-21 03:56:58 UTC (rev 293142)
+++ trunk/Tools/Scripts/generate-compile-commands 2022-04-21 04:08:17 UTC (rev 293143)
@@ -84,10 +84,12 @@
if third_party_regex.search(json_contents):
continue
+ # -2 gets rid of the comma at the end of the file.
+ json_contents = json_contents[:-2]
+
# Try to load JSON File
- try:
- # -2 gets rid of the comma at the end of the file.
- json.loads(json_contents[:-2])
+ try:
+ json.loads(json_contents)
except Exception:
print("Invalid JSON File: " + j_file_name)
continue
@@ -106,14 +108,16 @@
# Write the new compile_commands.json file
new_compile_commands_file = open("compile_commands.json", 'w')
-new_compile_commands_file.write("[\n")
+new_compile_commands_file.write("[")
-# We should probably remove the trailing comma in the last entry, but
-# clangd does not seem to mind.
-for key in files.keys():
+for index, key in enumerate(files.keys()):
+ if index != 0:
+ new_compile_commands_file.write(",\n")
+ else:
+ new_compile_commands_file.write("\n")
new_compile_commands_file.write(key)
-new_compile_commands_file.write("]\n")
+new_compile_commands_file.write("\n]\n")
new_compile_commands_file.close()
print("Generated Compile Commands!")
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes