@@ -109,24 +109,36 @@ an issue with the Apple BUILD rules with repro steps.
109109 command = '''\
110110 set -euo pipefail
111111
112+ # sorts JSON file keys for deterministic output
113+ sort_json_file() {
114+ local original_file="$1"
115+ local temp_file="${original_file}.sorted"
116+
117+ # Sort the JSON file keys
118+ "$DEVELOPER_DIR/usr/bin/python3" -m json.tool --compact --sort-keys "$original_file" > "$temp_file"
119+ # Replace original with sorted version
120+ mv "$temp_file" "$original_file"
121+ }
122+
112123exit_status=0
113124output=$($@ --sdk-root "$SDKROOT" --toolchain-dir "$DEVELOPER_DIR/Toolchains/XcodeDefault.xctoolchain" 2>&1) || exit_status=$?
114125
115- # The Metadata.appintents/extract.actionsdata output is a json file with non-deterministic keys order.
116- # Here we sort the keys of the json file to ensure that the output is deterministic.
117- original_actionsdata_file={output_dir}/extract.actionsdata
118- temporary_actionsdata_file={output_dir}/extract_sorted.actionsdata
119-
120- # Set write permission to allow rewrite extract.actionsdata
121- chmod -R +w {output_dir}
122- # Write extract.actionsdata with sorted keys
123- "$DEVELOPER_DIR/usr/bin/python3" -m json.tool --compact --sort-keys "$original_actionsdata_file" > "$temporary_actionsdata_file"
124- # Remove the original unsorted extract.actionsdata file
125- rm "$original_actionsdata_file"
126- # Rename the sorted file to the original name
127- mv "$temporary_actionsdata_file" "$original_actionsdata_file"
126+ # The Metadata.appintents/extract.actionsdata and version.json outputs are json
127+ # files with non-deterministic keys order.
128+ # Here we sort their keys to ensure that the output is deterministic.
129+ # This should be removed once the issue is fixed (FB19585633).
130+ actionsdata_file="{output_dir}/extract.actionsdata"
131+ version_file="{output_dir}/version.json"
132+
133+ # Set write permission to allow rewriting files
134+ chmod -R +w "{output_dir}"
135+
136+ # Sort both JSON files to ensure deterministic output
137+ sort_json_file "$version_file"
138+ sort_json_file "$actionsdata_file"
139+
128140# Restore read-only permission
129- chmod -R -w {output_dir}
141+ chmod -R -w " {output_dir}"
130142
131143if [[ "$exit_status" -ne 0 ]]; then
132144 echo "$output" >&2
0 commit comments