Skip to content

Commit 9eab705

Browse files
araifura-scadincebic
authored andcommitted
Make Metadata.appintents/extract.actionsdata json output deterministic
1 parent b2d7603 commit 9eab705

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

apple/internal/resource_actions/app_intents.bzl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,22 @@ set -euo pipefail
112112
exit_status=0
113113
output=$($@ --sdk-root "$SDKROOT" --toolchain-dir "$DEVELOPER_DIR/Toolchains/XcodeDefault.xctoolchain" 2>&1) || exit_status=$?
114114
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+
/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"
128+
# Restore read-only permission
129+
chmod -R -w {output_dir}
130+
115131
if [[ "$exit_status" -ne 0 ]]; then
116132
echo "$output" >&2
117133
exit $exit_status
@@ -122,7 +138,7 @@ elif [[ "$output" == *"skipping writing output"* ]]; then
122138
echo "$output" >&2
123139
exit 1
124140
fi
125-
''',
141+
'''.format(output_dir = output.path),
126142
inputs = depset([bundle_binary], transitive = transitive_inputs),
127143
outputs = [output],
128144
mnemonic = "AppIntentsMetadataProcessor",

0 commit comments

Comments
 (0)