Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 86ec86f

Browse files
committed
Clean up rules
1 parent 069b394 commit 86ec86f

File tree

5 files changed

+25
-42
lines changed

5 files changed

+25
-42
lines changed

rules/common/private/utils.bzl

+2-10
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,15 @@ def write_launcher(
3737
"""
3838

3939
classpath_args = ctx.actions.args()
40-
if hasattr(classpath_args, "add_all"): # Bazel 0.13.0+
41-
classpath_args.add_joined(runtime_classpath, format_each = "${RUNPATH}%s", join_with = ":", map_each = _short_path)
42-
else:
43-
classpath_args.add(runtime_classpath, format = "${RUNPATH}%s", join_with = ":", map_fn = _short_paths)
40+
classpath_args.add_joined(runtime_classpath, format_each = "${RUNPATH}%s", join_with = ":", map_each = _short_path)
4441
classpath_args.set_param_file_format("multiline")
4542
classpath_file = ctx.actions.declare_file("{}/classpath.params".format(ctx.label.name))
4643
ctx.actions.write(classpath_file, classpath_args)
4744

4845
classpath = "\"$(eval echo \"$(cat ${{RUNPATH}}{})\")\"".format(classpath_file.short_path)
4946

50-
#jvm_flags = " ".join([ctx.expand_location(f, ctx.attr.data) for f in jvm_flags])
5147
jvm_flags = " ".join(jvm_flags)
52-
template = ctx.attr._java_stub_template.files.to_list()[0]
53-
48+
template = ctx.file._java_stub_template
5449
runfiles_enabled = False
5550

5651
ctx.actions.expand_template(
@@ -78,6 +73,3 @@ def safe_name(value):
7873

7974
def _short_path(file):
8075
return file.short_path
81-
82-
def _short_paths(files):
83-
return [file.short_path for file in files]

rules/scala/private/core.bzl

+19-27
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
load(
22
"@rules_scala_annex//rules:providers.bzl",
3-
"LabeledJars",
4-
"ScalaConfiguration",
5-
"ScalaInfo",
6-
"ZincConfiguration",
7-
"ZincInfo",
3+
_LabeledJars = "LabeledJars",
4+
_ScalaConfiguration = "ScalaConfiguration",
5+
_ScalaInfo = "ScalaInfo",
6+
_ZincConfiguration = "ZincConfiguration",
7+
_ZincInfo = "ZincInfo",
88
)
9-
load("//rules/common:private/utils.bzl", "write_launcher")
10-
load(":private/import.bzl", "create_intellij_info")
9+
load("//rules/common:private/utils.bzl", _write_launcher = "write_launcher")
10+
load(":private/import.bzl", _create_intellij_info = "create_intellij_info")
1111

1212
runner_common_attributes = {
1313
"_java_toolchain": attr.label(
@@ -37,6 +37,7 @@ scala_binary_private_attributes = dict({
3737
),
3838
"_java_stub_template": attr.label(
3939
default = Label("@anx_java_stub_template//file"),
40+
allow_single_file = True,
4041
),
4142
}, **runner_common_attributes)
4243

@@ -45,10 +46,10 @@ scala_test_private_attributes = scala_binary_private_attributes
4546
def runner_common(ctx):
4647
runner = ctx.toolchains["@rules_scala_annex//rules/scala:runner_toolchain_type"]
4748

48-
scala_configuration = ctx.attr.scala[ScalaConfiguration]
49+
scala_configuration = ctx.attr.scala[_ScalaConfiguration]
4950
scala_configuration_runtime_deps = _collect(JavaInfo, scala_configuration.runtime_classpath)
5051

51-
zinc_configuration = ctx.attr.scala[ZincConfiguration]
52+
zinc_configuration = ctx.attr.scala[_ZincConfiguration]
5253

5354
sdeps = java_common.merge(_collect(JavaInfo, scala_configuration.runtime_classpath + ctx.attr.deps))
5455
sruntime_deps = java_common.merge(_collect(JavaInfo, ctx.attr.runtime_deps))
@@ -94,7 +95,7 @@ def runner_common(ctx):
9495
macro_classpath = [
9596
dep[JavaInfo].transitive_runtime_jars
9697
for dep in ctx.attr.deps
97-
if ScalaInfo in dep and dep[ScalaInfo].macro
98+
if _ScalaInfo in dep and dep[_ScalaInfo].macro
9899
]
99100
compile_classpath = depset(order = "preorder", transitive = macro_classpath + [sdeps.transitive_compile_time_jars])
100101

@@ -128,7 +129,7 @@ def runner_common(ctx):
128129

129130
javacopts = [ctx.expand_location(option, ctx.attr.data) for option in ctx.attr.javacopts + java_common.default_javac_opts(ctx, java_toolchain_attr = "_java_toolchain")]
130131

131-
zincs = [dep[ZincInfo] for dep in ctx.attr.deps if ZincInfo in dep]
132+
zincs = [dep[_ZincInfo] for dep in ctx.attr.deps if _ZincInfo in dep]
132133

133134
args = ctx.actions.args()
134135
args.add_all(depset(transitive = [zinc.deps for zinc in zincs]), map_each = _analysis)
@@ -179,7 +180,7 @@ def runner_common(ctx):
179180

180181
deps_toolchain = ctx.toolchains["@rules_scala_annex//rules/scala:deps_toolchain_type"]
181182
deps_checks = {}
182-
labeled_jars = depset(transitive = [dep[LabeledJars].values for dep in ctx.attr.deps])
183+
labeled_jars = depset(transitive = [dep[_LabeledJars].values for dep in ctx.attr.deps])
183184
deps_inputs, _, deps_input_manifests = ctx.resolve_command(tools = [deps_toolchain.runner])
184185
for name in ("direct", "used"):
185186
deps_check = ctx.actions.declare_file("{}/deps_check_{}".format(ctx.label.name, name))
@@ -237,7 +238,7 @@ def runner_common(ctx):
237238
for jar in java_info.outputs.jars:
238239
jars.append(jar.class_jar)
239240
jars.append(jar.ijar)
240-
zinc_info = ZincInfo(
241+
zinc_info = _ZincInfo(
241242
apis = apis,
242243
label = ctx.label,
243244
relations = relations,
@@ -262,9 +263,9 @@ def runner_common(ctx):
262263
return struct(
263264
deps_check = deps_check,
264265
java_info = java_info,
265-
scala_info = ScalaInfo(macro = ctx.attr.macro, scala_configuration = scala_configuration),
266+
scala_info = _ScalaInfo(macro = ctx.attr.macro, scala_configuration = scala_configuration),
266267
zinc_info = zinc_info,
267-
intellij_info = create_intellij_info(ctx.label, ctx.attr.deps, java_info),
268+
intellij_info = _create_intellij_info(ctx.label, ctx.attr.deps, java_info),
268269
files = depset(files),
269270
mains_files = depset([mains_file]),
270271
)
@@ -299,9 +300,6 @@ def _collect(index, iterable):
299300

300301
def _analysis(analysis):
301302
return (["--analysis", str(analysis.label), analysis.apis.path, analysis.relations.path] + [jar.path for jar in analysis.jars])
302-
"""
303-
Ew. Bazel 0.13.0's map_each will allow us to produce multiple args from each item.
304-
"""
305303

306304
def _labeled_group(labeled_jars):
307305
return (["--group", "_{}".format(labeled_jars.label)] + [jar.path for jar in labeled_jars.jars.to_list()])
@@ -355,7 +353,7 @@ def scala_binary_implementation(ctx):
355353
rjars = depset([ctx.outputs.jar], transitive = [transitive_rjars])
356354
_build_deployable(ctx, rjars.to_list())
357355

358-
files = write_launcher(
356+
files = _write_launcher(
359357
ctx,
360358
ctx.outputs.bin,
361359
java_info.transitive_runtime_deps,
@@ -406,7 +404,7 @@ def scala_test_implementation(ctx):
406404
args.add_all("--shared_classpath", shared_deps.transitive_runtime_deps, map_each = _short_path)
407405
elif ctx.attr.isolation == "process":
408406
subprocess_executable = ctx.actions.declare_file("{}/subprocess".format(ctx.label.name))
409-
files += write_launcher(
407+
files += _write_launcher(
410408
ctx,
411409
subprocess_executable,
412410
runner_jars,
@@ -422,7 +420,7 @@ def scala_test_implementation(ctx):
422420
ctx.actions.write(args_file, args)
423421
files.append(args_file)
424422

425-
files += write_launcher(
423+
files += _write_launcher(
426424
ctx,
427425
ctx.outputs.bin,
428426
runner_jars,
@@ -453,11 +451,5 @@ def scala_test_implementation(ctx):
453451
java = res.intellij_info,
454452
)
455453

456-
def _analyses(analyses):
457-
return [_analysis(analysis) for analysis in analyses]
458-
459454
def _short_path(file):
460455
return file.short_path
461-
462-
def _short_paths(files):
463-
return [file.short_path for file in files]

rules/scala/private/import.bzl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@rules_scala_annex//rules:providers.bzl", "IntellijInfo")
1+
load("@rules_scala_annex//rules:providers.bzl", _IntellijInfo = "IntellijInfo")
22

33
scala_import_private_attributes = {
44
"_java_toolchain": attr.label(
@@ -71,10 +71,10 @@ def scala_import_implementation(ctx):
7171

7272
def create_intellij_info(label, deps, java_info):
7373
# note: tried using transitive_exports from a JavaInfo that was given non-empty exports, but it was always empty
74-
return IntellijInfo(
74+
return _IntellijInfo(
7575
outputs = java_info.outputs,
7676
transitive_exports = depset(
7777
[label],
78-
transitive = [(dep[IntellijInfo] if IntellijInfo in dep else dep[JavaInfo]).transitive_exports for dep in deps],
78+
transitive = [(dep[_IntellijInfo] if _IntellijInfo in dep else dep[JavaInfo]).transitive_exports for dep in deps],
7979
),
8080
)

rules/scalac/private.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ _common_private_attributes = {
3131
scalac_library_private_attributes = _common_private_attributes
3232
scalac_binary_private_attributes = dict({
3333
"_java_stub_template": attr.label(
34+
allow_single_file = True,
3435
default = Label("@anx_java_stub_template//file"),
3536
),
3637
}, **_common_private_attributes)

rules/scalafmt/private/test.bzl

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
load("//rules/common:private/utils.bzl", "write_launcher")
2-
31
scala_format_private_attributes = {
42
"_format": attr.label(
53
cfg = "host",

0 commit comments

Comments
 (0)