1

fix flock

This commit is contained in:
Motiejus Jakštys 2021-08-06 11:23:39 +03:00
parent 5f5b25d34b
commit 11f919ea6f
2 changed files with 22 additions and 9 deletions

View File

@ -53,4 +53,4 @@ load(
zig_register_toolchains = "register_toolchains",
)
zig_register_toolchains()
zig_register_toolchains(speed_first_safety_later="auto")

View File

@ -173,10 +173,9 @@ def register_toolchains(
ZIG_TOOL_PATH = "tools/{zig_tool}"
ZIG_TOOL_WRAPPER = """#!/bin/bash
set -eu
readonly _zig="{zig}"
set -e
if [[ -n "$TMPDIR" ]]; then
if [[ -z "$TMPDIR" ]]; then
_cache_prefix=$TMPDIR
else
_cache_prefix="$HOME/.cache"
@ -188,7 +187,22 @@ export ZIG_LOCAL_CACHE_DIR="$_cache_prefix/bazel-zig-cc"
export ZIG_GLOBAL_CACHE_DIR=$ZIG_LOCAL_CACHE_DIR
# https://github.com/ziglang/zig/issues/9431
exec {maybe_flock} "$_zig" "{zig_tool}" "$@"
_flock=
if [[ -n "{do_flock}" ]]; then
_flock=$(command -v flock || :)
if [[ -z "$_flock" && -x /usr/local/bin/flock ]]; then
_flock=/usr/local/bin/flock
else
>&2 echo "WARNING: flock not found, proceeding unsafely."
>&2 echo "If build fails, retry it."
fi
fi
if [[ -n "$_flock" ]]; then
exec "$_flock" "{zig}" "{zig}" "{zig_tool}" "$@"
else
exec "{zig}" "{zig_tool}" "$@"
fi
"""
_ZIG_TOOLS = [
@ -224,18 +238,17 @@ def _zig_repository_impl(repository_ctx):
if repository_ctx.attr.speed_first_safety_later == "auto":
do_flock = repository_ctx.os.name.lower().startswith("mac os")
elif repository_ctx.attr.speed_first_safety_later == "yes":
do_flock = True
else:
do_flock = False
else:
do_flock = True
maybe_flock = 'flock "${_zig}"' if do_flock else ""
for zig_tool in _ZIG_TOOLS:
repository_ctx.file(
ZIG_TOOL_PATH.format(zig_tool = zig_tool),
ZIG_TOOL_WRAPPER.format(
zig = str(repository_ctx.path("zig")),
zig_tool = zig_tool,
maybe_flock = maybe_flock,
do_flock = "1" if do_flock else "",
),
)