Skip to content

Commit 8d477fc

Browse files
Copy files into local_config_apple_cc instead of symlinking (#355)
There is a bug in Bazel where the repository symlinks can resolve (nondeterministically in a race condition way) to old contents of files. This leads to errors like: ``` ERROR: error loading package '@@apple_support~~apple_cc_configure_extension~local_config_apple_cc//': Encountered error while reading extension file 'cc_toolchain_config.bzl': Unexpected short read from file '/Users/brentley.jones/Developer/rules_xcodeproj/bazel-output-base/external/apple_support~~apple_cc_configure_extension~local_config_apple_cc/cc_toolchain_config.bzl' (expected 100570, got 95733 bytes) ``` or ``` ERROR: /Users/brentley.jones/Developer/rules_xcodeproj/bazel-output-base/external/apple_support~~apple_cc_configure_extension~local_config_apple_cc/cc_toolchain_config.bzl:2667:23: syntax error at 'newline': expected ] ``` Signed-off-by: Brentley Jones <github@brentleyjones.com>
1 parent 1e48772 commit 8d477fc

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

crosstool/osx_cc_configure.bzl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ def _compile_cc_file(repository_ctx, src_name, out_name):
145145
"https://github.com/bazelbuild/apple_support/issues with the following:\n" +
146146
error_msg)
147147

148+
def _copy_file(repository_ctx, src, dest):
149+
repository_ctx.file(dest, content = repository_ctx.read(src))
150+
148151
def configure_osx_toolchain(repository_ctx):
149152
"""Configure C++ toolchain on macOS.
150153
@@ -199,10 +202,10 @@ def configure_osx_toolchain(repository_ctx):
199202
"%{env}": "",
200203
},
201204
)
202-
repository_ctx.symlink(xcrunwrapper, "xcrunwrapper.sh")
203-
repository_ctx.symlink(libtool, "libtool")
204-
repository_ctx.symlink(make_hashed_objlist, "make_hashed_objlist.py")
205-
repository_ctx.symlink(cc_toolchain_config, "cc_toolchain_config.bzl")
205+
_copy_file(repository_ctx, xcrunwrapper, "xcrunwrapper.sh")
206+
_copy_file(repository_ctx, libtool, "libtool")
207+
_copy_file(repository_ctx, make_hashed_objlist, "make_hashed_objlist.py")
208+
_copy_file(repository_ctx, cc_toolchain_config, "cc_toolchain_config.bzl")
206209
_compile_cc_file(repository_ctx, libtool_check_unique_src_path, "libtool_check_unique")
207210
_compile_cc_file(repository_ctx, wrapped_clang_src_path, "wrapped_clang")
208211
repository_ctx.symlink("wrapped_clang", "wrapped_clang_pp")

crosstool/setup.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ def _apple_cc_autoconf_toolchains_impl(repository_ctx):
2020
_DISABLE_ENV_VAR if should_disable else _OLD_DISABLE_ENV_VAR,
2121
))
2222
elif repository_ctx.os.name.startswith("mac os"):
23-
repository_ctx.symlink(
24-
repository_ctx.path(Label("@build_bazel_apple_support//crosstool:BUILD.toolchains")),
23+
repository_ctx.file(
2524
"BUILD",
25+
content = repository_ctx.read(
26+
Label("@build_bazel_apple_support//crosstool:BUILD.toolchains"),
27+
),
2628
)
2729
else:
2830
repository_ctx.file("BUILD", "# Apple CC toolchain autoconfiguration was disabled because you're not running on macOS")

0 commit comments

Comments
 (0)