Skip to content

Commit

Permalink
unify all of the default info phases implementations (#958)
Browse files Browse the repository at this point in the history
* unify all of the default info phases implementations

* collect_data = True
  • Loading branch information
andyscott authored Jan 29, 2020
1 parent f9c6a4c commit 96f9d94
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 53 deletions.
1 change: 1 addition & 0 deletions scala/private/phases/phase_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def _phase_compile(
class_jar = out.class_jar,
coverage = out.coverage.external,
full_jars = out.full_jars,
files = depset(out.full_jars),
ijar = out.ijar,
ijars = out.ijars,
rjars = depset(out.full_jars, transitive = [rjars]),
Expand Down
1 change: 1 addition & 0 deletions scala/private/phases/phase_coverage_runfiles.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ def phase_coverage_runfiles(ctx, p):
coverage_runfiles = ctx.files._jacocorunner + ctx.files._lcov_merger + coverage_replacements.values()
return struct(
coverage_runfiles = coverage_runfiles,
runfiles = depset(coverage_runfiles),
rjars = rjars,
)
8 changes: 6 additions & 2 deletions scala/private/phases/phase_declare_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ load(

def phase_declare_executable(ctx, p):
if (is_windows(ctx)):
return ctx.actions.declare_file("%s.exe" % ctx.label.name)
return struct(
executable = ctx.actions.declare_file("%s.exe" % ctx.label.name),
)
else:
return ctx.actions.declare_file(ctx.label.name)
return struct(
executable = ctx.actions.declare_file(ctx.label.name),
)
51 changes: 28 additions & 23 deletions scala/private/phases/phase_default_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,39 @@
#
# DOCUMENT THIS
#
def phase_default_info_binary(ctx, p):
return struct(
external_providers = {
"DefaultInfo": DefaultInfo(
executable = p.declare_executable,
files = depset([p.declare_executable] + p.compile.full_jars),
runfiles = p.runfiles.runfiles,
),
},
)

def phase_default_info_library(ctx, p):
return struct(
external_providers = {
"DefaultInfo": DefaultInfo(
files = depset(p.compile.full_jars),
runfiles = p.runfiles.runfiles,
),
},
)
def phase_default_info(ctx, p):
executable = None
files = []
runfiles = []

phase_names = dir(p)
phase_names.remove("to_json")
phase_names.remove("to_proto")
for phase_name in phase_names:
phase = getattr(p, phase_name)

if hasattr(phase, "executable"):
if executable == None:
executable = phase.executable
else:
fail("only one executable may be provided")

if hasattr(phase, "files"):
files.append(phase.files)

if hasattr(phase, "runfiles"):
runfiles.append(phase.runfiles)

def phase_default_info_scalatest(ctx, p):
return struct(
external_providers = {
"DefaultInfo": DefaultInfo(
executable = p.declare_executable,
files = depset([p.declare_executable] + p.compile.full_jars),
runfiles = ctx.runfiles(p.coverage_runfiles.coverage_runfiles, transitive_files = p.runfiles.runfiles.files),
executable = executable,
files = depset(transitive = files),
# TODO:
# Per Bazel documentation, we should avoid using collect_data. The core phases need to be updated
# before we can make the adjustment.
runfiles = ctx.runfiles(transitive_files = depset(transitive = runfiles), collect_data = True),
),
},
)
9 changes: 3 additions & 6 deletions scala/private/phases/phase_runfiles.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def phase_runfiles_scalatest(ctx, p):

args = struct(
transitive_files = depset(
[p.declare_executable, p.java_wrapper] + ctx.files._java_runtime + runfiles_ext,
[p.java_wrapper] + ctx.files._java_runtime + runfiles_ext,
transitive = [p.compile.rjars],
),
args_file = args_file,
Expand All @@ -38,7 +38,7 @@ def _phase_runfiles_default(ctx, p, _args = struct()):
return _phase_runfiles(
ctx,
_args.transitive_files if hasattr(_args, "transitive_files") else depset(
[p.declare_executable, p.java_wrapper] + ctx.files._java_runtime,
[p.java_wrapper] + ctx.files._java_runtime,
transitive = [p.compile.rjars],
),
_args.args_file if hasattr(_args, "args_file") else None,
Expand All @@ -49,10 +49,7 @@ def _phase_runfiles(
transitive_files,
args_file):
return struct(
runfiles = ctx.runfiles(
transitive_files = transitive_files,
collect_data = True,
),
runfiles = transitive_files,
args_file = args_file,
)

Expand Down
2 changes: 1 addition & 1 deletion scala/private/phases/phase_write_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _phase_write_executable(
jvm_flags,
use_jacoco,
main_class):
executable = p.declare_executable
executable = p.declare_executable.executable
wrapper = p.java_wrapper

if (is_windows(ctx)):
Expand Down
11 changes: 2 additions & 9 deletions scala/private/phases/phases.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ load(
_phase_runfiles_library = "phase_runfiles_library",
_phase_runfiles_scalatest = "phase_runfiles_scalatest",
)
load(
"@io_bazel_rules_scala//scala/private:phases/phase_default_info.bzl",
_phase_default_info_binary = "phase_default_info_binary",
_phase_default_info_library = "phase_default_info_library",
_phase_default_info_scalatest = "phase_default_info_scalatest",
)
load("@io_bazel_rules_scala//scala/private:phases/phase_default_info.bzl", _phase_default_info = "phase_default_info")
load("@io_bazel_rules_scala//scala/private:phases/phase_scalac_provider.bzl", _phase_scalac_provider = "phase_scalac_provider")
load("@io_bazel_rules_scala//scala/private:phases/phase_write_manifest.bzl", _phase_write_manifest = "phase_write_manifest")
load("@io_bazel_rules_scala//scala/private:phases/phase_collect_srcjars.bzl", _phase_collect_srcjars = "phase_collect_srcjars")
Expand Down Expand Up @@ -127,9 +122,7 @@ phase_runfiles_scalatest = _phase_runfiles_scalatest
phase_runfiles_common = _phase_runfiles_common

# default_info
phase_default_info_binary = _phase_default_info_binary
phase_default_info_library = _phase_default_info_library
phase_default_info_scalatest = _phase_default_info_scalatest
phase_default_info = _phase_default_info

# scalafmt
phase_scalafmt = _phase_scalafmt
4 changes: 2 additions & 2 deletions scala/private/rules/scala_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ load(
"phase_collect_jars_common",
"phase_compile_binary",
"phase_declare_executable",
"phase_default_info_binary",
"phase_default_info",
"phase_java_wrapper_common",
"phase_merge_jars",
"phase_runfiles_common",
Expand All @@ -42,7 +42,7 @@ def _scala_binary_impl(ctx):
("merge_jars", phase_merge_jars),
("runfiles", phase_runfiles_common),
("write_executable", phase_write_executable_common),
("default_info", phase_default_info_binary),
("default_info", phase_default_info),
],
)

Expand Down
4 changes: 2 additions & 2 deletions scala/private/rules/scala_junit_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ load(
"phase_collect_jars_junit_test",
"phase_compile_junit_test",
"phase_declare_executable",
"phase_default_info_binary",
"phase_default_info",
"phase_java_wrapper_common",
"phase_jvm_flags",
"phase_merge_jars",
Expand Down Expand Up @@ -47,7 +47,7 @@ def _scala_junit_test_impl(ctx):
("runfiles", phase_runfiles_common),
("jvm_flags", phase_jvm_flags),
("write_executable", phase_write_executable_junit_test),
("default_info", phase_default_info_binary),
("default_info", phase_default_info),
],
)

Expand Down
8 changes: 4 additions & 4 deletions scala/private/rules/scala_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ load(
"phase_compile_library",
"phase_compile_library_for_plugin_bootstrapping",
"phase_compile_macro_library",
"phase_default_info_library",
"phase_default_info",
"phase_merge_jars",
"phase_runfiles_library",
"phase_scalac_provider",
Expand Down Expand Up @@ -66,7 +66,7 @@ def _scala_library_impl(ctx):
("merge_jars", phase_merge_jars),
("runfiles", phase_runfiles_library),
("collect_exports_jars", phase_collect_exports_jars),
("default_info", phase_default_info_library),
("default_info", phase_default_info),
],
)

Expand Down Expand Up @@ -142,7 +142,7 @@ def _scala_library_for_plugin_bootstrapping_impl(ctx):
("merge_jars", phase_merge_jars),
("runfiles", phase_runfiles_library),
("collect_exports_jars", phase_collect_exports_jars),
("default_info", phase_default_info_library),
("default_info", phase_default_info),
],
)

Expand Down Expand Up @@ -197,7 +197,7 @@ def _scala_macro_library_impl(ctx):
("merge_jars", phase_merge_jars),
("runfiles", phase_runfiles_library),
("collect_exports_jars", phase_collect_exports_jars),
("default_info", phase_default_info_library),
("default_info", phase_default_info),
],
)

Expand Down
4 changes: 2 additions & 2 deletions scala/private/rules/scala_repl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ load(
"phase_collect_jars_repl",
"phase_compile_repl",
"phase_declare_executable",
"phase_default_info_binary",
"phase_default_info",
"phase_java_wrapper_repl",
"phase_merge_jars",
"phase_runfiles_common",
Expand Down Expand Up @@ -43,7 +43,7 @@ def _scala_repl_impl(ctx):
("merge_jars", phase_merge_jars),
("runfiles", phase_runfiles_common),
("write_executable", phase_write_executable_repl),
("default_info", phase_default_info_binary),
("default_info", phase_default_info),
],
)

Expand Down
4 changes: 2 additions & 2 deletions scala/private/rules/scala_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ load(
"phase_compile_scalatest",
"phase_coverage_runfiles",
"phase_declare_executable",
"phase_default_info_scalatest",
"phase_default_info",
"phase_java_wrapper_common",
"phase_merge_jars",
"phase_runfiles_scalatest",
Expand Down Expand Up @@ -44,7 +44,7 @@ def _scala_test_impl(ctx):
("runfiles", phase_runfiles_scalatest),
("coverage_runfiles", phase_coverage_runfiles),
("write_executable", phase_write_executable_scalatest),
("default_info", phase_default_info_scalatest),
("default_info", phase_default_info),
],
)

Expand Down

0 comments on commit 96f9d94

Please sign in to comment.