bazelbuild / rules_apple

Bazel rules to build apps for Apple platforms.
Apache License 2.0
512 stars 269 forks source link

Conflicting outputs when building with --define=apple.experimental.tree_artifact_outputs=1 #1933

Open chiragramani opened 1 year ago

chiragramani commented 1 year ago

When two application targets decared in the same BUILD file are built together with --define=apple.experimental.tree_artifact_outputs=1, each having the same bundle name, the Bazel build fails.

There are no build failures when building via --define=apple.experimental.tree_artifact_outputs=0.

Repro:

bazel build :HelloWorld :HelloWorld-Beta --define=apple.experimental.tree_artifact_outputs=1

repro.zip

Error Log:

ERROR: file 'HelloWorld.app' is generated by these conflicting actions:
Label: //:HelloWorld, //:HelloWorld-Beta
RuleClass: ios_application rule
JavaActionClass: class com.google.devtools.build.lib.analysis.actions.StarlarkAction
Configuration: 0b98b517ca42c5fd26fcd2bcd166b34b84a6c22d2344086c2b3e749c2e8193bd
Mnemonic: BundleTreeApp
Action key: aeea3ae6c1de92c04bf14fc9789d875fa978bde7697a00b35637df7193cd88d7, 8c54878f5e170eaf4fdacf9ae53e8b606ba3b206523bef761a4e48771b412ac4
Progress message: Bundling, processing and signing HelloWorld, Bundling, processing and signing HelloWorld-Beta
Action describeKey: Bundling, processing and signing HelloWorld
  Environment variable: XCODE_VERSION_OVERRIDE=14.1.0.14B47b
  Environment variable: APPLE_SDK_VERSION_OVERRIDE=16.1
  Environment variable: APPLE_SDK_PLATFORM=iPhoneSimulator
  Argument: bazel-out/darwin_arm64-opt-exec-2B5CBBC6-ST-521287fc850f/bin/external/build_bazel_rules_apple/tools/bundletool/bundletool_experimental
  Argument: bazel-out/applebin_ios-ios_sim_arm64-fastbuild-ST-bc46a42dbfe8/bin/HelloWorld-intermediates/bundletool_control.json
, Bundling, processing and signing HelloWorld-Beta
  Environment variable: XCODE_VERSION_OVERRIDE=14.1.0.14B47b
  Environment variable: APPLE_SDK_VERSION_OVERRIDE=16.1
  Environment variable: APPLE_SDK_PLATFORM=iPhoneSimulator
  Argument: bazel-out/darwin_arm64-opt-exec-2B5CBBC6-ST-521287fc850f/bin/external/build_bazel_rules_apple/tools/bundletool/bundletool_experimental
  Argument: bazel-out/applebin_ios-ios_sim_arm64-fastbuild-ST-bc46a42dbfe8/bin/HelloWorld-Beta-intermediates/bundletool_control.json

PrimaryInput: File:[/private/var/tmp/_bazel_chirag.ramani/5646a08425b0ad6703d2a0a3bcdd60c2/external/build_bazel_rules_apple[source]]tools/bundletool/bundletool_experimental.py
PrimaryOutput: File:[[<execution_root>]bazel-out/applebin_ios-ios_sim_arm64-fastbuild-ST-bc46a42dbfe8/bin]HelloWorld.app
Owner information: ConfiguredTargetKey{label=//:HelloWorld, config=BuildConfigurationKey[0b98b517ca42c5fd26fcd2bcd166b34b84a6c22d2344086c2b3e749c2e8193bd]}, ConfiguredTargetKey{label=//:HelloWorld-Beta, config=BuildConfigurationKey[0b98b517ca42c5fd26fcd2bcd166b34b84a6c22d2344086c2b3e749c2e8193bd]}
MandatoryInputs: Attempted action contains artifacts not in previous action (first 5): 
    HelloWorld-intermediates/HelloWorld
    HelloWorld-intermediates/storyboards/HelloWorld
    HelloWorld-intermediates/Info.plist
    HelloWorld-intermediates/PkgInfo
    HelloWorld-intermediates/bundletool_control.json
Previous action contains artifacts not in attempted action (first 5): 
    HelloWorld-Beta-intermediates/HelloWorld
    HelloWorld-Beta-intermediates/storyboards/HelloWorld-Beta
    HelloWorld-Beta-intermediates/Info.plist
    HelloWorld-Beta-intermediates/PkgInfo
    HelloWorld-Beta-intermediates/bundletool_control.json
Outputs: are equal
ERROR: com.google.devtools.build.lib.actions.MutableActionGraph$ActionConflictException: for HelloWorld.app, previous action: action 'Bundling, processing and signing HelloWorld-Beta', attempted action: action 'Bundling, processing and signing HelloWorld'
chiragramani commented 1 year ago

Looks like this code path is being executed, https://github.com/bazelbuild/rules_apple/blob/master/apple/internal/outputs.bzl#L51, where the action declaration makes use of the bundle name and hence the conflict. (since the bundle names are the same). The same conflicts are also seen when requesting dSYMs. https://github.com/bazelbuild/rules_apple/blob/master/apple/internal/partials/debug_symbols.bzl#L198