Skip to content

Commit 9d784a7

Browse files
authored
Merge pull request #87 from lucidsoftware/various-things
Various fixes and improvements
2 parents 3ab54ce + 869ce68 commit 9d784a7

File tree

15 files changed

+88
-109
lines changed

15 files changed

+88
-109
lines changed

.bazelrc_shared

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ common:tests --@rules_scala_annex//rules/scala:scala-toolchain=test_zinc_2_13
2828

2929
# These are backwards incompatible options; we should check to see if their values have been flipped
3030
# when upgrading to new major Bazel version.
31+
common --incompatible_modify_execution_info_additive
3132
common --incompatible_auto_exec_groups
3233
common --incompatible_autoload_externally=sh_binary # sh_binary is used by rules_jvm_external
3334
common --incompatible_config_setting_private_default_visibility

rules/common/private/utils.bzl

+7-22
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,9 @@ def safe_name(value):
173173
def _short_path(file):
174174
return file.short_path
175175

176-
# This propagates specific tags as execution requirements to be passed to an action
177-
# 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
178-
PROPAGATABLE_TAGS = ["no-remote", "no-cache", "no-sandbox", "no-remote-exec", "no-remote-cache"]
179-
180-
def resolve_execution_reqs(ctx, base_exec_reqs):
181-
exec_reqs = {}
182-
for tag in ctx.attr.tags:
183-
if tag in PROPAGATABLE_TAGS:
184-
exec_reqs.update({tag: "1"})
185-
exec_reqs.update(base_exec_reqs)
186-
return exec_reqs
187-
188176
def _format_resources_item(item):
189177
key, value = item
190-
return "{}:{}".format(value.path, key)
178+
return "\"{}\":\"{}\"".format(value.path, key)
191179

192180
def action_singlejar(
193181
ctx,
@@ -215,21 +203,18 @@ def action_singlejar(
215203
args.add("--output", output)
216204
if main_class != None:
217205
args.add("--main_class", main_class)
218-
args.set_param_file_format("multiline")
219-
args.use_param_file("@%s", use_always = True)
206+
args.set_param_file_format("multiline")
207+
args.use_param_file("@%s", use_always = True)
220208

221209
all_inputs = depset(resources.values(), transitive = [inputs])
222210

223211
ctx.actions.run(
224212
arguments = [args],
225213
executable = ctx.executable._singlejar,
226-
execution_requirements = resolve_execution_reqs(
227-
ctx,
228-
{
229-
"supports-workers": "0",
230-
"supports-path-mapping": "1",
231-
},
232-
),
214+
execution_requirements = {
215+
"supports-workers": "0",
216+
"supports-path-mapping": "1",
217+
},
233218
inputs = all_inputs,
234219
mnemonic = _SINGLE_JAR_MNEMONIC,
235220
outputs = [output],

rules/private/phases/phase_bootstrap_compile.bzl

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
load("@rules_java//java/common:java_common.bzl", "java_common")
22
load(
33
"//rules/common:private/utils.bzl",
4-
_resolve_execution_reqs = "resolve_execution_reqs",
54
_strip_margin = "strip_margin",
65
)
76

@@ -121,12 +120,9 @@ def phase_bootstrap_compile(ctx, g):
121120
ctx.actions.run_shell(
122121
arguments = [args],
123122
command = command,
124-
execution_requirements = _resolve_execution_reqs(
125-
ctx,
126-
{
127-
"supports-path-mapping": "1",
128-
},
129-
),
123+
execution_requirements = {
124+
"supports-path-mapping": "1",
125+
},
130126
inputs = inputs,
131127
mnemonic = "BootstrapScalacompile",
132128
outputs = [g.classpaths.jar, tmp],

rules/private/phases/phase_coverage_jacoco.bzl

+7-14
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ load(
33
_CodeCoverageConfiguration = "CodeCoverageConfiguration",
44
_JacocoInfo = "JacocoInfo",
55
)
6-
load(
7-
"@rules_scala_annex//rules/common:private/utils.bzl",
8-
_resolve_execution_reqs = "resolve_execution_reqs",
9-
)
106
load(
117
"@rules_scala_annex//rules/private:coverage_replacements_provider.bzl",
128
_coverage_replacements_provider = "coverage_replacements_provider",
@@ -34,16 +30,13 @@ def phase_coverage_jacoco(ctx, g):
3430
ctx.actions.run(
3531
arguments = [args],
3632
executable = toolchain.code_coverage_configuration.instrumentation_worker.files_to_run,
37-
execution_requirements = _resolve_execution_reqs(
38-
ctx,
39-
{
40-
"supports-multiplex-workers": "1",
41-
"supports-workers": "1",
42-
"supports-multiplex-sandboxing": "1",
43-
"supports-worker-cancellation": "1",
44-
"supports-path-mapping": "1",
45-
},
46-
),
33+
execution_requirements = {
34+
"supports-multiplex-workers": "1",
35+
"supports-workers": "1",
36+
"supports-multiplex-sandboxing": "1",
37+
"supports-worker-cancellation": "1",
38+
"supports-path-mapping": "1",
39+
},
4740
inputs = [in_out_pair[0] for in_out_pair in in_out_pairs],
4841
mnemonic = "JacocoInstrumenter",
4942
outputs = [in_out_pair[1] for in_out_pair in in_out_pairs],

rules/private/phases/phase_zinc_compile.bzl

+1-8
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ load(
88
_ZincDepInfo = "ZincDepInfo",
99
_ZincInfo = "ZincInfo",
1010
)
11-
load(
12-
"@rules_scala_annex//rules/common:private/utils.bzl",
13-
_resolve_execution_reqs = "resolve_execution_reqs",
14-
)
1511

1612
#
1713
# PHASE: compile
@@ -106,10 +102,7 @@ def phase_zinc_compile(ctx, g):
106102
ctx.actions.run(
107103
arguments = [args],
108104
executable = worker.files_to_run,
109-
execution_requirements = _resolve_execution_reqs(
110-
ctx,
111-
execution_requirements_tags,
112-
),
105+
execution_requirements = execution_requirements_tags,
113106
inputs = inputs,
114107
mnemonic = "ScalaCompile",
115108
outputs = outputs,

rules/private/phases/phase_zinc_depscheck.bzl

+7-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ load(
66
)
77
load(
88
"@rules_scala_annex//rules/common:private/utils.bzl",
9-
_resolve_execution_reqs = "resolve_execution_reqs",
109
_short_path = "short_path",
1110
)
1211

@@ -44,16 +43,13 @@ def phase_zinc_depscheck(ctx, g):
4443
ctx.actions.run(
4544
arguments = [deps_args],
4645
executable = deps_configuration.worker.files_to_run,
47-
execution_requirements = _resolve_execution_reqs(
48-
ctx,
49-
{
50-
"supports-multiplex-workers": "1",
51-
"supports-workers": "1",
52-
"supports-multiplex-sandboxing": "1",
53-
"supports-worker-cancellation": "1",
54-
"supports-path-mapping": "1",
55-
},
56-
),
46+
execution_requirements = {
47+
"supports-multiplex-workers": "1",
48+
"supports-workers": "1",
49+
"supports-multiplex-sandboxing": "1",
50+
"supports-worker-cancellation": "1",
51+
"supports-path-mapping": "1",
52+
},
5753
inputs = [g.compile.used],
5854
mnemonic = "ScalaCheckDeps",
5955
outputs = [deps_check],

rules/register_toolchain.bzl

+15-2
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,29 @@ register_zinc_toolchain = _make_register_toolchain(_zinc_configuration)
215215
def _scala_incoming_transition_impl(settings, attr):
216216
result = dict(settings)
217217

218-
if attr.scala_toolchain_name != "":
218+
if attr.scala_toolchain_name != "" and attr.scala_toolchain_name != settings[scala_toolchain_setting]:
219219
# We set `original_scala_toolchain_setting` so we can reset the toolchain to its
220220
# original value in `scala_outgoing_transition`. That way, we can ensure every target is
221221
# built under a single toolchain, thus preventing duplicate builds.
222222
#
223+
# We do not do this work when the toolchain name is set, but is no different than what is
224+
# already set. By having that check we avoid the failure mode where the original toolchain
225+
# name gets set equal to the current toolchain name and destroys whatever the actual original
226+
# toolchain name was. For example
227+
# State 1: State 2: State 3:
228+
# Setting: A => Setting: B => Setting: B => Game over
229+
# Original: Unset Original: A Original: B
230+
#
231+
# Note that the check described above should ideally not be required due to outgoing
232+
# transitions but it is, so something is going wrong. As a result, the check is probably
233+
# temporary, but who knows.
234+
#
223235
# This is inspired by what the rules_go folks are doing.
224236
result[original_scala_toolchain_setting] = settings[scala_toolchain_setting]
225237
result[scala_toolchain_setting] = attr.scala_toolchain_name
226238

227-
if hasattr(attr, "scalafmt_toolchain_name") and attr.scalafmt_toolchain_name != "":
239+
if (hasattr(attr, "scalafmt_toolchain_name") and attr.scalafmt_toolchain_name != "" and
240+
attr.scalafmt_toolchain_name != settings[scalafmt_toolchain_setting]):
228241
result[original_scalafmt_toolchain_setting] = settings[scalafmt_toolchain_setting]
229242
result[scalafmt_toolchain_setting] = attr.scalafmt_toolchain_name
230243

rules/scala.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ _compile_private_attributes = {
5757
),
5858
"_singlejar": attr.label(
5959
cfg = "exec",
60-
default = "@bazel_tools//tools/jdk:singlejar",
60+
default = "@rules_java//toolchains:singlejar",
6161
executable = True,
6262
),
6363

rules/scala/private/doc.bzl

+7-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ load(
88
load(
99
"//rules/common:private/utils.bzl",
1010
_collect = "collect",
11-
_resolve_execution_reqs = "resolve_execution_reqs",
1211
_separate_src_jars_srcs_and_other = "separate_src_jars_srcs_and_other",
1312
)
1413

@@ -55,16 +54,13 @@ def scaladoc_implementation(ctx):
5554
ctx.actions.run(
5655
arguments = [args],
5756
executable = ctx.attr._runner.files_to_run,
58-
execution_requirements = _resolve_execution_reqs(
59-
ctx,
60-
{
61-
"supports-multiplex-workers": "1",
62-
"supports-workers": "1",
63-
"supports-multiplex-sandboxing": "1",
64-
"supports-worker-cancellation": "1",
65-
"supports-path-mapping": "1",
66-
},
67-
),
57+
execution_requirements = {
58+
"supports-multiplex-workers": "1",
59+
"supports-workers": "1",
60+
"supports-multiplex-sandboxing": "1",
61+
"supports-worker-cancellation": "1",
62+
"supports-path-mapping": "1",
63+
},
6864
inputs = depset(
6965
src_jars + srcs + [toolchain.zinc_configuration.compiler_bridge],
7066
transitive = [classpath, compiler_classpath],

rules/scala_proto/private/core.bzl

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
load("@protobuf//bazel/common:proto_info.bzl", "ProtoInfo")
22
load(
33
"//rules/common:private/utils.bzl",
4-
_resolve_execution_reqs = "resolve_execution_reqs",
54
_safe_name = "safe_name",
65
)
76

@@ -44,16 +43,13 @@ def scala_proto_library_implementation(ctx):
4443
ctx.actions.run(
4544
arguments = [args],
4645
executable = compiler.compiler.files_to_run,
47-
execution_requirements = _resolve_execution_reqs(
48-
ctx,
49-
{
50-
"supports-multiplex-workers": supports_workers,
51-
"supports-workers": supports_workers,
52-
"supports-multiplex-sandboxing": supports_workers,
53-
"supports-worker-cancellation": supports_workers,
54-
"supports-path-mapping": supports_workers,
55-
},
56-
),
46+
execution_requirements = {
47+
"supports-multiplex-workers": supports_workers,
48+
"supports-workers": supports_workers,
49+
"supports-multiplex-sandboxing": supports_workers,
50+
"supports-worker-cancellation": supports_workers,
51+
"supports-path-mapping": supports_workers,
52+
},
5753
inputs = depset(direct = [], transitive = [transitive_sources]),
5854
mnemonic = "ScalaProtoCompile",
5955
outputs = [gendir],
@@ -71,9 +67,9 @@ def scala_proto_library_implementation(ctx):
7167
ctx.actions.run_shell(
7268
arguments = [shell_args],
7369
command = """$1 c $4 META-INF/= $(find -L $2 -type f | while read v; do echo ${v#"${2%$3}"}=$v; done)""",
74-
execution_requirements = _resolve_execution_reqs(ctx, {
70+
execution_requirements = {
7571
"supports-path-mapping": "1",
76-
}),
72+
},
7773
inputs = [gendir],
7874
mnemonic = "SrcJar",
7975
outputs = [srcjar],

rules/scalafmt/private/test.bzl

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
load(
22
"@rules_scala_annex//rules/common:private/utils.bzl",
3-
_resolve_execution_reqs = "resolve_execution_reqs",
43
_short_path = "short_path",
54
)
65

@@ -49,16 +48,13 @@ def build_format(ctx):
4948
ctx.actions.run(
5049
arguments = ["--jvm_flag=-Dfile.encoding=UTF-8", args],
5150
executable = ctx.executable._fmt,
52-
execution_requirements = _resolve_execution_reqs(
53-
ctx,
54-
{
55-
"supports-multiplex-workers": "1",
56-
"supports-workers": "1",
57-
"supports-multiplex-sandboxing": "1",
58-
"supports-worker-cancellation": "1",
59-
"supports-path-mapping": "1",
60-
},
61-
),
51+
execution_requirements = {
52+
"supports-multiplex-workers": "1",
53+
"supports-workers": "1",
54+
"supports-multiplex-sandboxing": "1",
55+
"supports-worker-cancellation": "1",
56+
"supports-path-mapping": "1",
57+
},
6258
inputs = [config, src],
6359
mnemonic = "ScalaFmt",
6460
outputs = [file],
@@ -81,9 +77,9 @@ def format_runner(ctx, manifest, files):
8177
ctx.actions.run_shell(
8278
arguments = [args],
8379
command = "cat $1 | sed -e s#%workspace%#$2# -e s#%manifest%#$3# > $4",
84-
execution_requirements = _resolve_execution_reqs(ctx, {
80+
execution_requirements = {
8581
"supports-path-mapping": "1",
86-
}),
82+
},
8783
inputs = [ctx.file._runner, manifest] + files,
8884
mnemonic = "CreateScalaFmtRunner",
8985
outputs = [ctx.outputs.scalafmt_runner],
@@ -100,9 +96,9 @@ def format_tester(ctx, manifest, files):
10096
ctx.actions.run_shell(
10197
arguments = [args],
10298
command = "cat $1 | sed -e s#%workspace%#$2# -e s#%manifest%#$3# > $4",
103-
execution_requirements = _resolve_execution_reqs(ctx, {
99+
execution_requirements = {
104100
"supports-path-mapping": "1",
105-
}),
101+
},
106102
inputs = [ctx.file._testrunner, manifest] + files,
107103
mnemonic = "CreateScalaFmtTester",
108104
outputs = [ctx.outputs.scalafmt_testrunner],
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("@rules_scala_annex//rules:scala.bzl", "scala_library")
2+
3+
scala_library(
4+
name = "special_characters",
5+
resources = glob(["**/*.txt"]),
6+
scala_toolchain_name = "test_zinc_2_13",
7+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
example
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash -e
2+
. "$(dirname "$0")"/../../common.sh
3+
4+
bazel build :special_characters

tests/tagging/BUILD

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
load("@rules_scala_annex//rules:scala.bzl", "scala_binary", "scala_library", "scala_test")
2-
load(
3-
"@rules_scala_annex//rules/common:private/utils.bzl",
4-
_PROPAGATABLE_TAGS = "PROPAGATABLE_TAGS",
5-
)
62

73
scala_binary(
84
name = "binary-all-propagatable",
95
srcs = ["A.scala"],
106
scala_toolchain_name = "test_zinc_2_13",
11-
tags = ["manual"] + _PROPAGATABLE_TAGS,
7+
tags = ["manual"] + [
8+
"no-cache",
9+
"no-remote",
10+
"no-remote-cache",
11+
"no-remote-exec",
12+
"no-sandbox",
13+
],
1214
)
1315

1416
scala_library(

0 commit comments

Comments
 (0)