From ca4b9f2111b861ead38d36ddea82505938134783 Mon Sep 17 00:00:00 2001 From: Evan Klitzke Date: Wed, 18 Jun 2025 23:20:45 -0700 Subject: [PATCH] Make compile_commands.json order deterministic Order entries in the output json file by filename, to make output deterministic. An example of why this is useful: changes in Python, bazel, or `rules_cc` can all change the exact output order in `compile_commands.json`. When my compile commands change as a result of an upstream change in bazel or `rules_cc`, I would like to see what has changed. By making output order deterministic it makes it much simpler to diff the old and new compiler commands json files. --- refresh.template.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/refresh.template.py b/refresh.template.py index 194f365e..7a5cb61e 100644 --- a/refresh.template.py +++ b/refresh.template.py @@ -1414,6 +1414,9 @@ def main(): There should be actionable warnings, above, that led to this.""") sys.exit(1) + # Sort output by filenaem to make output deterministic. + compile_command_entries.sort(lambda entry: entry['file']) + # Chain output into compile_commands.json with open('compile_commands.json', 'w') as output_file: json.dump(