MobileNativeFoundation / rules_xcodeproj

Bazel rules for generating Xcode projects.
MIT License
528 stars 86 forks source link

Bug: Handle `ios_application.bundle_name`s with spaces #1719

Closed mattrobmattrob closed 1 year ago

mattrobmattrob commented 1 year ago

Describe the bug

This is potentially odd/contrived but the difference between vanilla bazel.build and rules_xcodeproj.xcodeproj.build was confusing. Perhaps the outcome is to just fire a warning when this is encountered during generation or similar.

To reproduce, make this change to the integration tests:

diff --git a/examples/integration/iOSApp/Source/BUILD b/examples/integration/iOSApp/Source/BUILD
index 1e800e56..86f99420 100644
--- a/examples/integration/iOSApp/Source/BUILD
+++ b/examples/integration/iOSApp/Source/BUILD
@@ -32,7 +32,7 @@ ios_application(
     app_clips = ["//AppClip"],
     app_icons = glob(["Assets.xcassets/AppIcon.appiconset/**"]),
     bundle_id = IOS_BUNDLE_ID,
-    bundle_name = "iOSApp",
+    bundle_name = "iOS App",
     entitlements = "ios app.entitlements",
     executable_name = "iOSApp_ExecutableName",
     extensions = ["//WidgetExtension"],

Reproduction steps

$ bazel run //:xcodeproj-sim_arm64 -- "build //iOSApp"
INFO: Analyzed target //:xcodeproj-sim_arm64 (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:xcodeproj-sim_arm64 up-to-date:
  /Users/mattrobinson/Developer/github/buildbuddy-io/rules_xcodeproj/examples/integration/bazel-output-base/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/xcodeproj-sim_arm64-runner.sh
INFO: Elapsed time: 0.213s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: /Users/mattrobinson/Developer/github/buildbuddy-io/rules_xcodeproj/examples/integration/bazel-output-base/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/xcodeproj-sim_arm64-runner.sh 'build //iOSApp'

INFO: Analyzed target //iOSApp:iOSApp (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /Users/mattrobinson/Developer/github/buildbuddy-io/rules_xcodeproj/examples/integration/iOSApp/Source/BUILD:29:16: Creating runfiles tree bazel-out/applebin_ios-ios_sim_arm64-dbg-ST-7785c4ff3d6f/bin/iOSApp/Source/iOSApp.runfiles failed: build-runfiles failed: error executing command 
  (cd /Users/mattrobinson/Developer/github/buildbuddy-io/rules_xcodeproj/examples/integration/bazel-output-base/rules_xcodeproj/build_output_base/execroot/__main__ && \
  exec env - \
    PATH=/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin \
  /var/tmp/_bazel_mattrobinson/install/730b09b9d9f2bfd30b4c0a074ba23835/build-runfiles --allow_relative bazel-out/applebin_ios-ios_sim_arm64-dbg-ST-7785c4ff3d6f/bin/iOSApp/Source/iOSApp.runfiles_manifest bazel-out/applebin_ios-ios_sim_arm64-dbg-ST-7785c4ff3d6f/bin/iOSApp/Source/iOSApp.runfiles): Process exited with status 1: Process exited with status 1
/var/tmp/_bazel_mattrobinson/install/730b09b9d9f2bfd30b4c0a074ba23835/build-runfiles (args bazel-out/applebin_ios-ios_sim_arm64-dbg-ST-7785c4ff3d6f/bin/iOSApp/Source/iOSApp.runfiles_manifest bazel-out/applebin_ios-ios_sim_arm64-dbg-ST-7785c4ff3d6f/bin/iOSApp/Source/iOSApp.runfiles): link or target filename contains space on line 1: '__main__/iOSApp/Source/iOS App.app /Users/mattrobinson/Developer/github/buildbuddy-io/rules_xcodeproj/examples/integration/bazel-output-base/rules_xcodeproj/build_output_base/execroot/__main__/bazel-out/applebin_ios-ios_sim_arm64-dbg-ST-7785c4ff3d6f/bin/iOSApp/Source/iOS App.app'

INFO: Elapsed time: 0.283s, Critical Path: 0.04s
INFO: 4 processes: 4 internal.
FAILED: Build did NOT complete successfully

Expected behavior

Same as normal bazel build command:

$ bazel build //iOSApp
INFO: Analyzed target //iOSApp:iOSApp (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //iOSApp/Source:iOSApp up-to-date:
  /Users/mattrobinson/Developer/github/buildbuddy-io/rules_xcodeproj/examples/integration/bazel-output-base/execroot/__main__/bazel-out/applebin_ios-ios_sim_arm64-fastbuild-ST-7785c4ff3d6f/bin/iOSApp/Source/iOSApp.ipa
INFO: Elapsed time: 0.222s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action

Versions

Repro'd in repo on 323c33d72bf87b64f2bc9c805cd602a5a248f6e2.

mattrobmattrob commented 1 year ago

And perhaps a different but similar outcome in Xcode itself:

diff --git a/examples/integration/BUILD b/examples/integration/BUILD
index f59fad0c..97e36670 100644
--- a/examples/integration/BUILD
+++ b/examples/integration/BUILD
@@ -1,5 +1,6 @@
 load(
     "@com_github_buildbuddy_io_rules_xcodeproj//xcodeproj:defs.bzl",
+    "top_level_target",
     "xcodeproj",
 )
 load(
@@ -15,6 +16,17 @@ load(

 exports_files(["README.md"])

+xcodeproj(
+    name = "xcodeproj",
+    project_name = "App",
+    # scheme_autogeneration_mode = "all",
+    top_level_targets = [
+        top_level_target("//iOSApp", target_environments = ["simulator"]),
+    ],
+)
+
 # Example of xcodeproj cache warming
 #
 # 1. Register a single macOS execution platform in `WORKSPACE`:
Then build: Xcode Log
Screenshot 2023-01-31 at 9 59 45 PM Build iOSApp_2023-01-31T21-58-02.txt
brentleyjones commented 1 year ago

So a couple comments:

  1. You probably shouldn't be calling build //some:target with the command-line API. While it will put you in the correct "environment", you still won't have the same transitions applied. That's why --generator_output_groups exists. Though, I also do this from time to time just to test something, knowing I won't get cache hits.
  2. Runfiles not being able to contain spaces is a know Bazel limitation (bug). I haven't seen this partiticular one though, so I'm going to look into it and see why we are generating runfiles for a target (we only need them for xcodeproj itself).
brentleyjones commented 1 year ago

The issue isn't with the command-line API, it's from --define=apple.experimental.tree_artifact_outputs=1. This will fail as well:

bazel build //iOSApp/Source:iOSApp --define=apple.experimental.tree_artifact_outputs=1
INFO: Build options --@com_github_buildbuddy_io_rules_xcodeproj//xcodeproj:extra_common_flags, --@com_github_buildbuddy_io_rules_xcodeproj//xcodeproj:extra_generator_flags, --@com_github_buildbuddy_io_rules_xcodeproj//xcodeproj:extra_indexbuild_flags, and 2 more have changed, discarding analysis cache.
INFO: Analyzed target //iOSApp/Source:iOSApp (79 packages loaded, 2467 targets configured).
INFO: Found 1 target...
ERROR: /Users/brentley/Developer/rules_xcodeproj/examples/integration/iOSApp/Source/BUILD:29:16: Creating runfiles tree bazel-out/applebin_ios-ios_sim_arm64-fastbuild-ST-7785c4ff3d6f/bin/iOSApp/Source/iOSApp.runfiles failed: build-runfiles failed: error executing command 
  (cd /Users/brentley/Developer/rules_xcodeproj/examples/integration/bazel-output-base/execroot/__main__ && \
  exec env - \
    PATH=/Users/brentley/Developer/rules_xcodeproj/examples/integration/tools:/opt/homebrew/opt/mysql-client/bin:/Users/brentley/.dotfiles/bin:/opt/homebrew/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/brentley/google-cloud-sdk/bin \
  /var/tmp/_bazel_brentley/install/730b09b9d9f2bfd30b4c0a074ba23835/build-runfiles --allow_relative bazel-out/applebin_ios-ios_sim_arm64-fastbuild-ST-7785c4ff3d6f/bin/iOSApp/Source/iOSApp.runfiles_manifest bazel-out/applebin_ios-ios_sim_arm64-fastbuild-ST-7785c4ff3d6f/bin/iOSApp/Source/iOSApp.runfiles): Process exited with status 1: Process exited with status 1
/var/tmp/_bazel_brentley/install/730b09b9d9f2bfd30b4c0a074ba23835/build-runfiles (args bazel-out/applebin_ios-ios_sim_arm64-fastbuild-ST-7785c4ff3d6f/bin/iOSApp/Source/iOSApp.runfiles_manifest bazel-out/applebin_ios-ios_sim_arm64-fastbuild-ST-7785c4ff3d6f/bin/iOSApp/Source/iOSApp.runfiles): link or target filename contains space on line 1: '__main__/iOSApp/Source/iOS App.app /Users/brentley/Developer/rules_xcodeproj/examples/integration/bazel-output-base/execroot/__main__/bazel-out/applebin_ios-ios_sim_arm64-fastbuild-ST-7785c4ff3d6f/bin/iOSApp/Source/iOS App.app'

Target //iOSApp/Source:iOSApp failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 7.672s, Critical Path: 0.03s
INFO: 26 processes: 26 internal.
FAILED: Build did NOT complete successfully
brentleyjones commented 1 year ago

So this is an issue with rules_apple, not rules_xcodeproj.

mattrobmattrob commented 1 year ago

Perfect. Thanks for looking, @brentleyjones!