Skip to content

Don’t require xcode-select or DEVELOPER_DIR to run #3147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
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
21 changes: 15 additions & 6 deletions xcodeproj/internal/templates/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,33 @@ if [[ -s "$extra_flags_bazelrc" ]]; then
bazelrcs+=("--bazelrc=$extra_flags_bazelrc")
fi

developer_dir=$(xcode-select -p)

# We write to a `.bazelrc` file instead of passing flags directly in order to
# support all Bazel commands via the `common` pseudo-command
cat > "$pre_xcodeproj_bazelrc_dir/pre_xcodeproj.bazelrc" <<EOF
# Be explicit about our desired Xcode version
common:rules_xcodeproj --xcode_version=%xcode_version%

# Set \`DEVELOPER_DIR\` in case a bazel wrapper filters it
common:rules_xcodeproj --repo_env=DEVELOPER_DIR=$developer_dir

# Work around https://github.com/bazelbuild/bazel/issues/8902
# \`USE_CLANG_CL\` is only used on Windows, we set it here to cause Bazel to
# re-evaluate the cc_toolchain for a different Xcode version
common:rules_xcodeproj --repo_env=USE_CLANG_CL=%xcode_version%
common:rules_xcodeproj --repo_env=XCODE_VERSION=%xcode_version%
EOF

if command -v /usr/bin/xcode-select >/dev/null 2>&1; then
developer_dir=$(xcode-select -p)
else
developer_dir="${DEVELOPER_DIR:-}"
fi

if [[ -n "$developer_dir" ]]; then
cat >> "$pre_xcodeproj_bazelrc_dir/pre_xcodeproj.bazelrc" <<EOF

# Set \`DEVELOPER_DIR\` in case a bazel wrapper filters it
common:rules_xcodeproj --repo_env=DEVELOPER_DIR=$developer_dir
EOF
fi

readonly allowed_vars=(
"BUILD_WORKSPACE_DIRECTORY"
"HOME"
Expand All @@ -209,7 +218,7 @@ bazel_cmd=(
"$bazel_path"

# Restart Bazel server if `DEVELOPER_DIR` changes to clear `developerDirCache`
"--host_jvm_args=-Xdock:name=$developer_dir"
${developer_dir:+"--host_jvm_args=-Xdock:name=$developer_dir"}

"${bazelrcs[@]}"
)
Expand Down
Loading