From c8d75f3263f6d3119570d8cf1865b219ba57522a Mon Sep 17 00:00:00 2001 From: Andrei Raifura Date: Mon, 4 Aug 2025 11:52:40 -0700 Subject: [PATCH 1/4] Make Metadata.appintents/extract.actionsdata json output deterministic --- .../internal/resource_actions/app_intents.bzl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/apple/internal/resource_actions/app_intents.bzl b/apple/internal/resource_actions/app_intents.bzl index 07db72096e..b5df98bc57 100644 --- a/apple/internal/resource_actions/app_intents.bzl +++ b/apple/internal/resource_actions/app_intents.bzl @@ -112,6 +112,22 @@ set -euo pipefail exit_status=0 output=$($@ --sdk-root "$SDKROOT" --toolchain-dir "$DEVELOPER_DIR/Toolchains/XcodeDefault.xctoolchain" 2>&1) || exit_status=$? +# The Metadata.appintents/extract.actionsdata output is a json file with non-deterministic keys order. +# Here we sort the keys of the json file to ensure that the output is deterministic. +original_actionsdata_file={output_dir}/extract.actionsdata +temporary_actionsdata_file={output_dir}/extract_sorted.actionsdata + +# Set write permission to allow rewrite extract.actionsdata +chmod -R +w {output_dir} +# Write extract.actionsdata with sorted keys +/usr/bin/python3 -m json.tool --compact --sort-keys "$original_actionsdata_file" > "$temporary_actionsdata_file" +# Remove the original unsorted extract.actionsdata file +rm "$original_actionsdata_file" +# Rename the sorted file to the original name +mv "$temporary_actionsdata_file" "$original_actionsdata_file" +# Restore read-only permission +chmod -R -w {output_dir} + if [[ "$exit_status" -ne 0 ]]; then echo "$output" >&2 exit $exit_status @@ -122,7 +138,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", From 999962de6f763b6c37520195d8ef2ca1f5a16684 Mon Sep 17 00:00:00 2001 From: Andrei Raifura Date: Mon, 4 Aug 2025 13:04:57 -0700 Subject: [PATCH 2/4] Use python3 from Xcode's DEVELOPER_DIR --- apple/internal/resource_actions/app_intents.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple/internal/resource_actions/app_intents.bzl b/apple/internal/resource_actions/app_intents.bzl index b5df98bc57..c9e8ce6cc8 100644 --- a/apple/internal/resource_actions/app_intents.bzl +++ b/apple/internal/resource_actions/app_intents.bzl @@ -120,7 +120,7 @@ temporary_actionsdata_file={output_dir}/extract_sorted.actionsdata # Set write permission to allow rewrite extract.actionsdata chmod -R +w {output_dir} # Write extract.actionsdata with sorted keys -/usr/bin/python3 -m json.tool --compact --sort-keys "$original_actionsdata_file" > "$temporary_actionsdata_file" +"$DEVELOPER_DIR/usr/bin/python3" -m json.tool --compact --sort-keys "$original_actionsdata_file" > "$temporary_actionsdata_file" # Remove the original unsorted extract.actionsdata file rm "$original_actionsdata_file" # Rename the sorted file to the original name From 27a9d2b309c0fd579dd000d56f90aa68720ae13b Mon Sep 17 00:00:00 2001 From: Andrei Raifura Date: Mon, 11 Aug 2025 18:25:02 +0000 Subject: [PATCH 3/4] Sort keys of version.json produced by AppIntentsMetadataProcessor **Context** https://github.com/bazelbuild/rules_apple/issues/2760 Similar to https://github.sc-corp.net/Snapchat/rules_apple/pull/46, this sorts the keys of `version.json` file generated by the `AppIntentsMetadataProcessor` which also has non-deterministic key order. --- Automatic squash commit from https://github.sc-corp.net/Snapchat/rules_apple/pull/47 Cooled by araifura --- .../internal/resource_actions/app_intents.bzl | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/apple/internal/resource_actions/app_intents.bzl b/apple/internal/resource_actions/app_intents.bzl index c9e8ce6cc8..daaa91e232 100644 --- a/apple/internal/resource_actions/app_intents.bzl +++ b/apple/internal/resource_actions/app_intents.bzl @@ -109,24 +109,36 @@ 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 output is a json file with non-deterministic keys order. -# Here we sort the keys of the json file to ensure that the output is deterministic. -original_actionsdata_file={output_dir}/extract.actionsdata -temporary_actionsdata_file={output_dir}/extract_sorted.actionsdata - -# Set write permission to allow rewrite extract.actionsdata -chmod -R +w {output_dir} -# Write extract.actionsdata with sorted keys -"$DEVELOPER_DIR/usr/bin/python3" -m json.tool --compact --sort-keys "$original_actionsdata_file" > "$temporary_actionsdata_file" -# Remove the original unsorted extract.actionsdata file -rm "$original_actionsdata_file" -# Rename the sorted file to the original name -mv "$temporary_actionsdata_file" "$original_actionsdata_file" +# 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} +chmod -R -w "{output_dir}" if [[ "$exit_status" -ne 0 ]]; then echo "$output" >&2 From ee839a71f693a6260fdce2469751bae1f2d4fecb Mon Sep 17 00:00:00 2001 From: Andrei Raifura Date: Tue, 12 Aug 2025 13:31:25 -0700 Subject: [PATCH 4/4] escape curly braces --- apple/internal/resource_actions/app_intents.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apple/internal/resource_actions/app_intents.bzl b/apple/internal/resource_actions/app_intents.bzl index daaa91e232..c991417916 100644 --- a/apple/internal/resource_actions/app_intents.bzl +++ b/apple/internal/resource_actions/app_intents.bzl @@ -110,15 +110,15 @@ an issue with the Apple BUILD rules with repro steps. set -euo pipefail # sorts JSON file keys for deterministic output -sort_json_file() { +sort_json_file() {{ local original_file="$1" - local temp_file="${original_file}.sorted" + 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=$?