Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
propagate specific target tags to run and run_shell actions as execut…
Browse files Browse the repository at this point in the history
…ion_requirements
  • Loading branch information
SrodriguezO committed Jun 14, 2019
1 parent 3e22acd commit 97709b8
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 8 deletions.
14 changes: 13 additions & 1 deletion rules/common/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ def safe_name(value):
def _short_path(file):
return file.short_path

# This propagates specific tags as execution requirements to be passed to an action
# A fix to bazelbuild/bazel that will make this no longer necessary is underway; we can remove this once that's released and we've obtained it
PROPAGATABLE_TAGS = ["no-remote", "no-cache", "no-sandbox", "no-remote-exec", "no-remote-cache"]

def resolve_execution_reqs(ctx, base_exec_reqs):
exec_reqs = {}
for tag in ctx.attr.tags:
if tag in PROPAGATABLE_TAGS:
exec_reqs.update({tag: "1"})
exec_reqs.update(base_exec_reqs)
return exec_reqs

def action_singlejar(
ctx,
inputs,
Expand Down Expand Up @@ -151,7 +163,7 @@ def action_singlejar(
ctx.actions.run(
arguments = [args],
executable = ctx.executable._singlejar,
execution_requirements = {"supports-workers": "1"},
execution_requirements = resolve_execution_reqs(ctx, {"supports-workers": "1"}),
mnemonic = _SINGLE_JAR_MNEMONIC,
inputs = all_inputs,
outputs = [output],
Expand Down
5 changes: 5 additions & 0 deletions rules/private/phases/phase_bootstrap_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ load(
"//rules/common:private/utils.bzl",
_strip_margin = "strip_margin",
)
load(
"//rules/common:private/utils.bzl",
_resolve_execution_reqs = "resolve_execution_reqs",
)

#
# PHASE: bootstrap compile
Expand Down Expand Up @@ -51,4 +55,5 @@ def phase_bootstrap_compile(ctx, g):
output_jar = g.classpaths.jar.path,
),
),
execution_requirements = _resolve_execution_reqs(ctx, {}),
)
6 changes: 5 additions & 1 deletion rules/private/phases/phase_coverage_jacoco.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ load(
"@rules_scala_annex//rules/private:coverage_replacements_provider.bzl",
_coverage_replacements_provider = "coverage_replacements_provider",
)
load(
"@rules_scala_annex//rules/common:private/utils.bzl",
_resolve_execution_reqs = "resolve_execution_reqs",
)

def phase_coverage_jacoco(ctx, g):
if not ctx.configuration.coverage_enabled:
Expand Down Expand Up @@ -40,7 +44,7 @@ def phase_coverage_jacoco(ctx, g):
outputs = [in_out_pair[1] for in_out_pair in in_out_pairs],
executable = code_coverage_configuration.instrumentation_worker.files_to_run.executable,
input_manifests = worker_input_manifests,
execution_requirements = {"supports-workers": "1"},
execution_requirements = _resolve_execution_reqs(ctx, {"supports-workers": "1"}),
arguments = [args],
)

Expand Down
6 changes: 5 additions & 1 deletion rules/private/phases/phase_zinc_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ load(
_ZincConfiguration = "ZincConfiguration",
_ZincInfo = "ZincInfo",
)
load(
"@rules_scala_annex//rules/common:private/utils.bzl",
_resolve_execution_reqs = "resolve_execution_reqs",
)

#
# PHASE: compile
Expand Down Expand Up @@ -80,7 +84,7 @@ def phase_zinc_compile(ctx, g):
outputs = outputs,
executable = worker.files_to_run.executable,
input_manifests = input_manifests,
execution_requirements = {"no-sandbox": "1", "supports-workers": "1"},
execution_requirements = _resolve_execution_reqs(ctx, {"no-sandbox": "1", "supports-workers": "1"}),
arguments = [args],
)

Expand Down
6 changes: 5 additions & 1 deletion rules/private/phases/phase_zinc_depscheck.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ load(
_DepsConfiguration = "DepsConfiguration",
_LabeledJars = "LabeledJars",
)
load(
"@rules_scala_annex//rules/common:private/utils.bzl",
_resolve_execution_reqs = "resolve_execution_reqs",
)

#
# PHASE: depscheck
Expand Down Expand Up @@ -39,7 +43,7 @@ def phase_zinc_depscheck(ctx, g):
outputs = [deps_check],
executable = deps_configuration.worker.files_to_run.executable,
input_manifests = worker_input_manifests,
execution_requirements = {"supports-workers": "1"},
execution_requirements = _resolve_execution_reqs(ctx, {"supports-workers": "1"}),
arguments = [deps_args],
)
deps_checks[name] = deps_check
Expand Down
11 changes: 9 additions & 2 deletions rules/scala/private/doc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ load(
_ScalaConfiguration = "ScalaConfiguration",
_ZincConfiguration = "ZincConfiguration",
)
load("//rules/common:private/utils.bzl", _collect = "collect")
load(
"//rules/common:private/utils.bzl",
_collect = "collect",
)
load(
"//rules/common:private/utils.bzl",
_resolve_execution_reqs = "resolve_execution_reqs",
)

scaladoc_private_attributes = {
"_runner": attr.label(
Expand Down Expand Up @@ -53,7 +60,7 @@ def scaladoc_implementation(ctx):
ctx.actions.run(
arguments = [args],
executable = ctx.attr._runner.files_to_run.executable,
execution_requirements = {"supports-workers": "1"},
execution_requirements = _resolve_execution_reqs(ctx, {"supports-workers": "1"}),
input_manifests = input_manifests,
inputs = depset(
src_jars + srcs + [zinc_configuration.compiler_bridge],
Expand Down
7 changes: 6 additions & 1 deletion rules/scala_proto/private/core.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ load(
"//rules/common:private/utils.bzl",
_safe_name = "safe_name",
)
load(
"//rules/common:private/utils.bzl",
_resolve_execution_reqs = "resolve_execution_reqs",
)

scala_proto_library_private_attributes = {}

Expand Down Expand Up @@ -41,7 +45,7 @@ def scala_proto_library_implementation(ctx):
outputs = [gendir],
executable = compiler.compiler.files_to_run.executable,
tools = compiler_inputs,
execution_requirements = {"supports-workers": supports_workers},
execution_requirements = _resolve_execution_reqs(ctx, {"supports-workers": supports_workers}),
arguments = [args],
)

Expand All @@ -52,4 +56,5 @@ def scala_proto_library_implementation(ctx):
command = """$1 c $4 META-INF/= $(find -L $2 -type f | while read v; do echo ${v#"${2%$3}"}=$v; done)""",
progress_message = "Bundling compiled Scala into srcjar",
tools = [ctx.executable._zipper],
execution_requirements = _resolve_execution_reqs(ctx, {}),
)
9 changes: 8 additions & 1 deletion rules/scalafmt/private/test.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
load(
"@rules_scala_annex//rules/common:private/utils.bzl",
_resolve_execution_reqs = "resolve_execution_reqs",
)

scala_format_attributes = {
"config": attr.label(
allow_single_file = [".conf"],
Expand Down Expand Up @@ -47,7 +52,7 @@ def build_format(ctx):
input_manifests = runner_manifests,
inputs = [ctx.file.config, src],
tools = runner_inputs,
execution_requirements = {"supports-workers": "1"},
execution_requirements = _resolve_execution_reqs(ctx, {"supports-workers": "1"}),
mnemonic = "ScalaFmt",
)
manifest_content.append("{} {}".format(src.short_path, file.short_path))
Expand All @@ -68,6 +73,7 @@ def format_runner(ctx, manifest, files):
manifest.short_path,
ctx.outputs.scalafmt_runner.path,
],
execution_requirements = _resolve_execution_reqs(ctx, {}),
)

def format_tester(ctx, manifest, files):
Expand All @@ -81,6 +87,7 @@ def format_tester(ctx, manifest, files):
manifest.short_path,
ctx.outputs.scalafmt_testrunner.path,
],
execution_requirements = _resolve_execution_reqs(ctx, {}),
)

def scala_format_test_implementation(ctx):
Expand Down
Empty file added tests/tagging/A.scala
Empty file.
32 changes: 32 additions & 0 deletions tests/tagging/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load("@rules_scala_annex//rules:scala.bzl", "scala_binary", "scala_library", "scala_test")
load(
"@rules_scala_annex//rules/common:private/utils.bzl",
_PROPAGATABLE_TAGS = "PROPAGATABLE_TAGS",
)

scala_binary(
name = "binary-all-propagatable",
srcs = ["A.scala"],
scala = "//scala:2_11",
tags = ["manual"] + _PROPAGATABLE_TAGS,
)

scala_library(
name = "library-no-propagatable",
srcs = ["A.scala"],
scala = "//scala:2_11",
tags = [
"manual",
"requires-network",
],
)

scala_test(
name = "test-no-remote-only",
srcs = ["A.scala"],
scala = "//scala:2_11",
tags = [
"manual",
"no-remote",
],
)
25 changes: 25 additions & 0 deletions tests/tagging/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash -e
. "$(dirname "$0")"/../common.sh

IFS=$'\n'

function check_execution_info {
target=$1
all_exec_info=$((bazel aquery $target) | egrep "ExecutionInfo")
for exec_info in $all_exec_info; do
for arg in $@; do
if [[ $arg == $1 || "$exec_info" =~ "$arg" ]]; then
continue
else
echo "Failed. $arg not found in tags"
exit 1
fi
done
done
}
check_execution_info "library-no-propagatable"
check_execution_info "binary-all-propagatable" "no-remote" "no-cache" "no-sandbox" "no-remote-exec" "no-remote-cache"
check_execution_info "test-no-remote-only" "no-remote"
echo "SUCCESS"

0 comments on commit 97709b8

Please sign in to comment.