fix flock
This commit is contained in:
parent
5f5b25d34b
commit
11f919ea6f
@ -53,4 +53,4 @@ load(
|
|||||||
zig_register_toolchains = "register_toolchains",
|
zig_register_toolchains = "register_toolchains",
|
||||||
)
|
)
|
||||||
|
|
||||||
zig_register_toolchains()
|
zig_register_toolchains(speed_first_safety_later="auto")
|
||||||
|
@ -173,10 +173,9 @@ def register_toolchains(
|
|||||||
|
|
||||||
ZIG_TOOL_PATH = "tools/{zig_tool}"
|
ZIG_TOOL_PATH = "tools/{zig_tool}"
|
||||||
ZIG_TOOL_WRAPPER = """#!/bin/bash
|
ZIG_TOOL_WRAPPER = """#!/bin/bash
|
||||||
set -eu
|
set -e
|
||||||
readonly _zig="{zig}"
|
|
||||||
|
|
||||||
if [[ -n "$TMPDIR" ]]; then
|
if [[ -z "$TMPDIR" ]]; then
|
||||||
_cache_prefix=$TMPDIR
|
_cache_prefix=$TMPDIR
|
||||||
else
|
else
|
||||||
_cache_prefix="$HOME/.cache"
|
_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
|
export ZIG_GLOBAL_CACHE_DIR=$ZIG_LOCAL_CACHE_DIR
|
||||||
|
|
||||||
# https://github.com/ziglang/zig/issues/9431
|
# 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 = [
|
_ZIG_TOOLS = [
|
||||||
@ -224,18 +238,17 @@ def _zig_repository_impl(repository_ctx):
|
|||||||
if repository_ctx.attr.speed_first_safety_later == "auto":
|
if repository_ctx.attr.speed_first_safety_later == "auto":
|
||||||
do_flock = repository_ctx.os.name.lower().startswith("mac os")
|
do_flock = repository_ctx.os.name.lower().startswith("mac os")
|
||||||
elif repository_ctx.attr.speed_first_safety_later == "yes":
|
elif repository_ctx.attr.speed_first_safety_later == "yes":
|
||||||
do_flock = True
|
|
||||||
else:
|
|
||||||
do_flock = False
|
do_flock = False
|
||||||
|
else:
|
||||||
|
do_flock = True
|
||||||
|
|
||||||
maybe_flock = 'flock "${_zig}"' if do_flock else ""
|
|
||||||
for zig_tool in _ZIG_TOOLS:
|
for zig_tool in _ZIG_TOOLS:
|
||||||
repository_ctx.file(
|
repository_ctx.file(
|
||||||
ZIG_TOOL_PATH.format(zig_tool = zig_tool),
|
ZIG_TOOL_PATH.format(zig_tool = zig_tool),
|
||||||
ZIG_TOOL_WRAPPER.format(
|
ZIG_TOOL_WRAPPER.format(
|
||||||
zig = str(repository_ctx.path("zig")),
|
zig = str(repository_ctx.path("zig")),
|
||||||
zig_tool = zig_tool,
|
zig_tool = zig_tool,
|
||||||
maybe_flock = maybe_flock,
|
do_flock = "1" if do_flock else "",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user