Skip to content
This repository has been archived by the owner on Mar 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #56 from laszlocsomor/fix-command
Browse files Browse the repository at this point in the history
multirun(), command(): export RUNFILES_* envvars
  • Loading branch information
ash2k committed Apr 12, 2019
2 parents c7e0fd9 + 5a6cec1 commit e31d79d
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions multirun/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,36 @@ load("@bazel_skylib//lib:shell.bzl", "shell")

_CONTENT_PREFIX = """#!/usr/bin/env bash
# --- begin runfiles.bash initialization ---
# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash).
set -euo pipefail
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
if [[ -f "$0.runfiles_manifest" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
elif [[ -f "$0.runfiles/MANIFEST" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
export RUNFILES_DIR="$0.runfiles"
fi
fi
if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
else
echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
exit 1
fi
# --- end runfiles.bash initialization ---
# Export RUNFILES_* envvars (and a couple more) for subprocesses.
runfiles_export_envvars
"""

def _multirun_impl(ctx):
runfiles = ctx.runfiles()
runfiles = ctx.runfiles().merge(ctx.attr._bash_runfiles[DefaultInfo].default_runfiles)
content = [_CONTENT_PREFIX]

for command in ctx.attr.commands:
Expand Down Expand Up @@ -45,6 +69,9 @@ _multirun = rule(
doc = "Targets to run in specified order",
cfg = "target",
),
"_bash_runfiles": attr.label(
default = Label("@bazel_tools//tools/bash/runfiles"),
),
},
executable = True,
)
Expand All @@ -59,7 +86,8 @@ def multirun(**kwargs):
)

def _command_impl(ctx):
runfiles = ctx.runfiles()
runfiles = ctx.runfiles().merge(ctx.attr._bash_runfiles[DefaultInfo].default_runfiles)

defaultInfo = ctx.attr.command[DefaultInfo]

default_runfiles = defaultInfo.default_runfiles
Expand Down Expand Up @@ -118,6 +146,9 @@ _command = rule(
doc = "Target to run",
cfg = "target",
),
"_bash_runfiles": attr.label(
default = Label("@bazel_tools//tools/bash/runfiles"),
),
},
executable = True,
)
Expand Down

0 comments on commit e31d79d

Please sign in to comment.