Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion apple/internal/resource_actions/app_intents.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,37 @@ an issue with the Apple BUILD rules with repro steps.
command = '''\
set -euo pipefail

# sorts JSON file keys for deterministic output
sort_json_file() {{
local original_file="$1"
local temp_file="${{original_file}}.sorted"

# Sort the JSON file keys
"$DEVELOPER_DIR/usr/bin/python3" -m json.tool --compact --sort-keys "$original_file" > "$temp_file"
# Replace original with sorted version
mv "$temp_file" "$original_file"
}}

exit_status=0
output=$($@ --sdk-root "$SDKROOT" --toolchain-dir "$DEVELOPER_DIR/Toolchains/XcodeDefault.xctoolchain" 2>&1) || exit_status=$?

# The Metadata.appintents/extract.actionsdata and version.json outputs are json
# files with non-deterministic keys order.
# Here we sort their keys to ensure that the output is deterministic.
# This should be removed once the issue is fixed (FB19585633).
actionsdata_file="{output_dir}/extract.actionsdata"
version_file="{output_dir}/version.json"

# Set write permission to allow rewriting files
chmod -R +w "{output_dir}"

# Sort both JSON files to ensure deterministic output
sort_json_file "$version_file"
sort_json_file "$actionsdata_file"

# Restore read-only permission
chmod -R -w "{output_dir}"

if [[ "$exit_status" -ne 0 ]]; then
echo "$output" >&2
exit $exit_status
Expand All @@ -122,7 +150,7 @@ elif [[ "$output" == *"skipping writing output"* ]]; then
echo "$output" >&2
exit 1
fi
''',
'''.format(output_dir = output.path),
inputs = depset([bundle_binary], transitive = transitive_inputs),
outputs = [output],
mnemonic = "AppIntentsMetadataProcessor",
Expand Down