Skip to content

Move code from rule impls/common to phases #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions scala/private/common.bzl
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
load("@io_bazel_rules_scala//scala:jars_to_labels.bzl", "JarsToLabelsInfo")
load("@io_bazel_rules_scala//scala:plusone.bzl", "PlusOneDeps")

def write_manifest(ctx):
main_class = getattr(ctx.attr, "main_class", None)
write_manifest_file(ctx.actions, ctx.outputs.manifest, main_class)

def write_manifest_file(actions, output_file, main_class):
# TODO(bazel-team): I don't think this classpath is what you want
manifest = "Class-Path: \n"
Expand All @@ -13,13 +9,6 @@ def write_manifest_file(actions, output_file, main_class):

actions.write(output = output_file, content = manifest)

def collect_srcjars(targets):
srcjars = []
for target in targets:
if hasattr(target, "srcjars"):
srcjars.append(target.srcjars.srcjar)
return depset(srcjars)

def collect_jars(
dep_targets,
dependency_analyzer_is_off = True,
Expand Down
59 changes: 52 additions & 7 deletions scala/private/phases/phase_collect_jars.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
#
load(
"@io_bazel_rules_scala//scala/private:rule_impls.bzl",
"collect_jars_from_common_ctx",
"is_dependency_analyzer_off",
"is_plus_one_deps_off",
)
load(
"@io_bazel_rules_scala//scala/private:common.bzl",
"collect_jars",
)

def phase_scalatest_collect_jars(ctx, p):
Expand Down Expand Up @@ -59,16 +64,56 @@ def _phase_default_collect_jars(ctx, p, _args = struct()):
_args.unused_dependency_checker_mode if hasattr(_args, "unused_dependency_checker_mode") else p.unused_deps_checker,
)

# Extract very common code out from dependency analysis into single place
# automatically adds dependency on scala-library and scala-reflect
# collects jars from deps, runtime jars from runtime_deps, and
def _phase_collect_jars(
ctx,
base_classpath,
extra_deps,
extra_runtime_deps,
unused_dependency_checker_mode):
return collect_jars_from_common_ctx(
ctx,
base_classpath,
extra_deps,
extra_runtime_deps,
unused_dependency_checker_mode == "off",
unused_dependency_checker_is_off = unused_dependency_checker_mode == "off"
dependency_analyzer_is_off = is_dependency_analyzer_off(ctx)

deps_jars = collect_jars(
ctx.attr.deps + extra_deps + base_classpath,
dependency_analyzer_is_off,
unused_dependency_checker_is_off,
is_plus_one_deps_off(ctx),
)

(
cjars,
transitive_rjars,
jars2labels,
transitive_compile_jars,
deps_providers,
) = (
deps_jars.compile_jars,
deps_jars.transitive_runtime_jars,
deps_jars.jars2labels,
deps_jars.transitive_compile_jars,
deps_jars.deps_providers,
)

transitive_rjars = depset(
transitive = [transitive_rjars] +
_collect_runtime_jars(ctx.attr.runtime_deps + extra_runtime_deps),
)

return struct(
compile_jars = cjars,
jars2labels = jars2labels,
transitive_compile_jars = transitive_compile_jars,
transitive_runtime_jars = transitive_rjars,
deps_providers = deps_providers,
)

def _collect_runtime_jars(dep_targets):
runtime_jars = []

for dep_target in dep_targets:
runtime_jars.append(dep_target[JavaInfo].transitive_runtime_jars)

return runtime_jars
10 changes: 5 additions & 5 deletions scala/private/phases/phase_collect_srcjars.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#
# DOCUMENT THIS
#
load(
"@io_bazel_rules_scala//scala/private:common.bzl",
"collect_srcjars",
)

def phase_collect_srcjars(ctx, p):
# This will be used to pick up srcjars from non-scala library
# targets (like thrift code generation)
return collect_srcjars(ctx.attr.deps)
srcjars = []
for target in ctx.attr.deps:
if hasattr(target, "srcjars"):
srcjars.append(target.srcjars.srcjar)
return depset(srcjars)
Loading