Skip to content
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

Fix issues not navigating to source files in BwB mode #893

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/bash;
shellScript = "set -euo pipefail\n\n# In Xcode 14 the \"Index\" directory was renamed to \"Index.noindex\".\n# `$INDEX_DATA_STORE_DIR` is set to `$OBJROOT/INDEX_DIR/DataStore`, so we can\n# use it to determine the name of the directory regardless of Xcode version.\nreadonly index_dir=\"${INDEX_DATA_STORE_DIR%/*}\"\nreadonly index_dir_name=\"${index_dir##*/}\"\n\n# Xcode doesn't adjust `$OBJROOT` in scheme action scripts when building for\n# previews. So we need to look in the non-preview build directory for this file.\nreadonly non_preview_objroot=\"${OBJROOT/\\/Intermediates.noindex\\/Previews\\/*//Intermediates.noindex}\"\nreadonly base_objroot=\"${non_preview_objroot/\\/$index_dir_name\\/Build\\/Intermediates.noindex//Build/Intermediates.noindex}\"\nreadonly scheme_target_ids_file=\"$non_preview_objroot/scheme_target_ids\"\n\nif [ \"$ACTION\" == \"indexbuild\" ]; then\n readonly output_group_prefix=i\nelse\n readonly output_group_prefix=b\nfi\n\n# We need to read from `$output_groups_file` as soon as possible, as concurrent\n# writes to it can happen during indexing, which breaks the off-by-one-by-design\n# nature of it\nIFS=$'\\n' read -r -d '' -a output_groups < \\\n <( \"$CALCULATE_OUTPUT_GROUPS_SCRIPT\" \\\n \"$non_preview_objroot\" \\\n \"$base_objroot\" \\\n \"$scheme_target_ids_file\" \\\n $output_group_prefix \\\n && printf '\\0' )\n\nif [ -z \"${output_groups:-}\" ]; then\n if [ \"$ACTION\" == \"indexbuild\" ]; then\n echo \"error: Can't yet determine Index Build output group. Next build should succeed. If not, please file a bug report here: https://github.com/buildbuddy-io/rules_xcodeproj/issues/new?template=bug.md.\" >&2\n exit 1\n else\n echo \"error: BazelDependencies invoked without any output groups set. Please file a bug report here: https://github.com/buildbuddy-io/rules_xcodeproj/issues/new?template=bug.md.\" >&2\n exit 1\n fi\nfi\noutput_groups_flag=\"--output_groups=$(IFS=, ; echo \"${output_groups[*]}\")\"\n\nif [ \"$ACTION\" == \"indexbuild\" ]; then\n # We use a different output base for Index Build to prevent normal builds and\n # indexing waiting on bazel locks from the other\n output_base=\"$OBJROOT/bazel_output_base\"\nelif [ \"${ENABLE_PREVIEWS:-}\" == \"YES\" ]; then\n # We use a different output base for SwiftUI Previews since they have\n # different swiftcopts, preventing output trashing\n output_base=\"$OBJROOT/bazel_output_base\"\nfi\n\nif [[ \"${COLOR_DIAGNOSTICS:-NO}\" == \"YES\" ]]; then\n color=yes\nelse\n color=no\nfi\n\noutput_path=$(env -i \\\n DEVELOPER_DIR=\"$DEVELOPER_DIR\" \\\n HOME=\"$HOME\" \\\n PATH=\"/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin\" \\\n USER=\"$USER\" \\\n \"$BAZEL_PATH\" \\\n ${output_base:+--output_base \"$output_base\"} \\\n info \\\n --color=\"$color\" \\\n --experimental_convenience_symlinks=ignore \\\n --symlink_prefix=/ \\\n --bes_backend= \\\n --bes_results_url= \\\n output_path)\nexec_root=\"${output_path%/*}\"\n\nif [[ \"$ACTION\" != \"indexbuild\" && \"${ENABLE_PREVIEWS:-}\" != \"YES\" ]]; then\n \"$BAZEL_INTEGRATION_DIR/create_lldbinit.sh\" \"$exec_root\" > \"$BAZEL_LLDB_INIT\"\nfi\n\n# Use current path for bazel-out\n# This fixes Index Build to use its version of generated files\nif [[ \"${BAZEL_OUT:0:1}\" == '/' ]]; then\n absolute_bazel_out=\"$BAZEL_OUT\"\nelse\n absolute_bazel_out=\"$SRCROOT/$BAZEL_OUT\"\nfi\ncat > \"$OBJROOT/bazel-out-overlay.yaml\" <<EOF\n{\"case-sensitive\": \"false\", \"fallthrough\": true, \"roots\": [{\"external-contents\": \"$output_path\",\"name\": \"$absolute_bazel_out\",\"type\": \"directory-remap\"}],\"version\": 0}\nEOF\n\ncd \"$SRCROOT\"\n\nif [ \"$ACTION\" == \"indexbuild\" ]; then\n index_flags=(\n --bes_backend=\n --bes_results_url=\n )\nelif [ \"${ENABLE_PREVIEWS:-}\" == \"YES\" ]; then\n swiftui_previews_flags=(\n --swiftcopt=-Xfrontend\n --swiftcopt=-enable-implicit-dynamic\n --swiftcopt=-Xfrontend\n --swiftcopt=-enable-private-imports\n --swiftcopt=-Xfrontend\n --swiftcopt=-enable-dynamic-replacement-chaining\n )\nfi\n\ndate +%s > \"$INTERNAL_DIR/toplevel_cache_buster\"\n\nbuild_marker=\"$OBJROOT/bazel_build_start\"\ntouch \"$build_marker\"\n\nlog=$(mktemp)\nenv -i \\\n DEVELOPER_DIR=\"$DEVELOPER_DIR\" \\\n HOME=\"$HOME\" \\\n PATH=\"/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin\" \\\n USER=\"$USER\" \\\n \"$BAZEL_PATH\" \\\n ${output_base:+--output_base \"$output_base\"} \\\n build \\\n --color=\"$color\" \\\n --experimental_convenience_symlinks=ignore \\\n --symlink_prefix=/ \\\n ${index_flags:+${index_flags[*]}} \\\n ${swiftui_previews_flags:+${swiftui_previews_flags[*]}} \\\n \"$output_groups_flag\" \\\n //test/fixtures:fixture_bwb \\\n 2>&1 | tee -i \"$log\"\n\nfor output_group in \"${output_groups[@]}\"; do\n filelist=\"fixture_bwb-${output_group//\\//_}\"\n filelist=\"${filelist/#/$output_path/darwin_x86_64-fastbuild-ST-1b9bd654f600/bin/test/fixtures/}\"\n filelist=\"${filelist/%/.filelist}\"\n if [[ \"$filelist\" -ot \"$build_marker\" ]]; then\n echo \"error: Bazel didn't generate the correct files (it should have generated outputs for output group \\\"$output_group\\\", but the timestamp for \\\"$filelist\\\" was from before the build). Please regenerate the project to fix this.\" >&2\n echo \"error: If your bazel version is less than 5.2, you may need to \\`bazel clean\\` and/or \\`bazel shutdown\\` to work around a bug in project generation.\" >&2\n echo \"error: If you are still getting this error after all of that, please file a bug report here: https://github.com/buildbuddy-io/rules_xcodeproj/issues/new?template=bug.md.\" >&2\n exit 1\n fi\ndone\n";
shellScript = "set -euo pipefail\n\n# In Xcode 14 the \"Index\" directory was renamed to \"Index.noindex\".\n# `$INDEX_DATA_STORE_DIR` is set to `$OBJROOT/INDEX_DIR/DataStore`, so we can\n# use it to determine the name of the directory regardless of Xcode version.\nreadonly index_dir=\"${INDEX_DATA_STORE_DIR%/*}\"\nreadonly index_dir_name=\"${index_dir##*/}\"\n\n# Xcode doesn't adjust `$OBJROOT` in scheme action scripts when building for\n# previews. So we need to look in the non-preview build directory for this file.\nreadonly non_preview_objroot=\"${OBJROOT/\\/Intermediates.noindex\\/Previews\\/*//Intermediates.noindex}\"\nreadonly base_objroot=\"${non_preview_objroot/\\/$index_dir_name\\/Build\\/Intermediates.noindex//Build/Intermediates.noindex}\"\nreadonly scheme_target_ids_file=\"$non_preview_objroot/scheme_target_ids\"\n\nif [ \"$ACTION\" == \"indexbuild\" ]; then\n readonly output_group_prefix=i\nelse\n readonly output_group_prefix=b\nfi\n\n# We need to read from `$output_groups_file` as soon as possible, as concurrent\n# writes to it can happen during indexing, which breaks the off-by-one-by-design\n# nature of it\nIFS=$'\\n' read -r -d '' -a output_groups < \\\n <( \"$CALCULATE_OUTPUT_GROUPS_SCRIPT\" \\\n \"$non_preview_objroot\" \\\n \"$base_objroot\" \\\n \"$scheme_target_ids_file\" \\\n $output_group_prefix \\\n && printf '\\0' )\n\nif [ -z \"${output_groups:-}\" ]; then\n if [ \"$ACTION\" == \"indexbuild\" ]; then\n echo \"error: Can't yet determine Index Build output group. Next build should succeed. If not, please file a bug report here: https://github.com/buildbuddy-io/rules_xcodeproj/issues/new?template=bug.md.\" >&2\n exit 1\n else\n echo \"error: BazelDependencies invoked without any output groups set. Please file a bug report here: https://github.com/buildbuddy-io/rules_xcodeproj/issues/new?template=bug.md.\" >&2\n exit 1\n fi\nfi\noutput_groups_flag=\"--output_groups=$(IFS=, ; echo \"${output_groups[*]}\")\"\n\nif [ \"$ACTION\" == \"indexbuild\" ]; then\n # We use a different output base for Index Build to prevent normal builds and\n # indexing waiting on bazel locks from the other\n output_base=\"$OBJROOT/bazel_output_base\"\nelif [ \"${ENABLE_PREVIEWS:-}\" == \"YES\" ]; then\n # We use a different output base for SwiftUI Previews since they have\n # different swiftcopts, preventing output trashing\n output_base=\"$OBJROOT/bazel_output_base\"\nfi\n\nif [[ \"${COLOR_DIAGNOSTICS:-NO}\" == \"YES\" ]]; then\n color=yes\nelse\n color=no\nfi\n\noutput_path=$(env -i \\\n DEVELOPER_DIR=\"$DEVELOPER_DIR\" \\\n HOME=\"$HOME\" \\\n PATH=\"/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin\" \\\n USER=\"$USER\" \\\n \"$BAZEL_PATH\" \\\n ${output_base:+--output_base \"$output_base\"} \\\n info \\\n --color=\"$color\" \\\n --experimental_convenience_symlinks=ignore \\\n --symlink_prefix=/ \\\n --bes_backend= \\\n --bes_results_url= \\\n output_path)\nexec_root=\"${output_path%/*}\"\n\nif [[ \"$ACTION\" != \"indexbuild\" && \"${ENABLE_PREVIEWS:-}\" != \"YES\" ]]; then\n \"$BAZEL_INTEGRATION_DIR/create_lldbinit.sh\" \"$exec_root\" > \"$BAZEL_LLDB_INIT\"\nfi\n\n# Use current path for bazel-out\n# This fixes Index Build to use its version of generated files\nif [[ \"${BAZEL_OUT:0:1}\" == '/' ]]; then\n absolute_bazel_out=\"$BAZEL_OUT\"\nelse\n absolute_bazel_out=\"$SRCROOT/$BAZEL_OUT\"\nfi\ncat > \"$OBJROOT/bazel-out-overlay.yaml\" <<EOF\n{\"case-sensitive\": \"false\", \"fallthrough\": true, \"roots\": [{\"external-contents\": \"$output_path\",\"name\": \"$absolute_bazel_out\",\"type\": \"directory-remap\"}],\"version\": 0}\nEOF\n\ncd \"$SRCROOT\"\n\nif [ \"$ACTION\" == \"indexbuild\" ]; then\n index_flags=(\n --bes_backend=\n --bes_results_url=\n )\nelif [ \"${ENABLE_PREVIEWS:-}\" == \"YES\" ]; then\n swiftui_previews_flags=(\n --swiftcopt=-Xfrontend\n --swiftcopt=-enable-implicit-dynamic\n --swiftcopt=-Xfrontend\n --swiftcopt=-enable-private-imports\n --swiftcopt=-Xfrontend\n --swiftcopt=-enable-dynamic-replacement-chaining\n )\nfi\n\ndate +%s > \"$INTERNAL_DIR/toplevel_cache_buster\"\n\nbuild_marker=\"$OBJROOT/bazel_build_start\"\ntouch \"$build_marker\"\n\nlog=$(mktemp)\n\"$BAZEL_INTEGRATION_DIR/process_bazel_build_log.py\" env -i \\\n DEVELOPER_DIR=\"$DEVELOPER_DIR\" \\\n HOME=\"$HOME\" \\\n PATH=\"/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin\" \\\n USER=\"$USER\" \\\n \"$BAZEL_PATH\" \\\n ${output_base:+--output_base \"$output_base\"} \\\n build \\\n --color=\"yes\" \\\n --experimental_convenience_symlinks=ignore \\\n --symlink_prefix=/ \\\n ${index_flags:+${index_flags[*]}} \\\n ${swiftui_previews_flags:+${swiftui_previews_flags[*]}} \\\n \"$output_groups_flag\" \\\n //test/fixtures:fixture_bwb \\\n 2>&1 | tee -i \"$log\"\n\nfor output_group in \"${output_groups[@]}\"; do\n filelist=\"fixture_bwb-${output_group//\\//_}\"\n filelist=\"${filelist/#/$output_path/darwin_x86_64-fastbuild-ST-1b9bd654f600/bin/test/fixtures/}\"\n filelist=\"${filelist/%/.filelist}\"\n if [[ \"$filelist\" -ot \"$build_marker\" ]]; then\n echo \"error: Bazel didn't generate the correct files (it should have generated outputs for output group \\\"$output_group\\\", but the timestamp for \\\"$filelist\\\" was from before the build). Please regenerate the project to fix this.\" >&2\n echo \"error: If your bazel version is less than 5.2, you may need to \\`bazel clean\\` and/or \\`bazel shutdown\\` to work around a bug in project generation.\" >&2\n echo \"error: If you are still getting this error after all of that, please file a bug report here: https://github.com/buildbuddy-io/rules_xcodeproj/issues/new?template=bug.md.\" >&2\n exit 1\n fi\ndone\n";
showEnvVarsInLog = 0;
};
E4007F3470769810A6EC2EEF /* Create link.params */ = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/python3

import os
import re
import subprocess
import sys
from typing import List


def _main(command: List[str]) -> None:
srcroot = os.getenv("SRCROOT")
if not srcroot:
sys.exit("SRCROOT environment variable must be set")

bazel_out_directory = os.getenv("BAZEL_OUT")
if not bazel_out_directory:
sys.exit("BAZEL_OUT environment variable must be set")
bazel_out_prefix = bazel_out_directory[:-(len("/bazel-out")+1)]
if not bazel_out_prefix.startswith("/"):
bazel_out_prefix = f"{srcroot}/{bazel_out_prefix}"

external_directory = os.getenv("BAZEL_EXTERNAL")
if not external_directory:
sys.exit("BAZEL_EXTERNAL environment variable must be set")
external_prefix = bazel_out_directory[:-(len("/external")+1)]
if not external_prefix.startswith("/"):
external_prefix = f"{srcroot}/{external_prefix}"

should_strip_color = os.getenv("COLOR_DIAGNOSTICS", default="YES") != "YES"

strip_color = re.compile(r"\x1b\[[0-9;]{1,}[A-Za-z]")
relative_diagnostic = re.compile(
r"^(?P<path>[^/].+?):\d+(:\d+)?: (error|warning):"
)

def _replacement(match: re.Match) -> str:
path = match.group("path")
if path.startswith("bazel-out/"):
prefix = bazel_out_prefix
elif path.startswith("external/"):
prefix = external_prefix
else:
prefix = srcroot
return f"{prefix}/{match.group(0)}"

process = subprocess.Popen(
command, bufsize=1, stderr=subprocess.PIPE, universal_newlines=True
)
assert process.stderr

while process.poll() is None:
input_line = process.stderr.readline().rstrip()

if should_strip_color:
input_line = strip_color.sub("", input_line)

if not input_line:
continue

output_line = relative_diagnostic.sub(_replacement, input_line)
print(output_line, flush=True)

sys.exit(process.returncode)


if __name__ == "__main__":
_main(sys.argv[1:])
Loading