Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
62 changes: 60 additions & 2 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 @@ -65,10 +70,63 @@ def _phase_collect_jars(
extra_deps,
extra_runtime_deps,
unused_dependency_checker_mode):
return collect_jars_from_common_ctx(
return _collect_jars_from_common_ctx(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than calling _collect_jars_from_common_ctx, can we just move the logic in _collect_jars_from_common_ctx to _phase_collect_jars? _phase_collect_jars seems to do nothing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

ctx,
base_classpath,
extra_deps,
extra_runtime_deps,
unused_dependency_checker_mode == "off",
)

# 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 _collect_jars_from_common_ctx(
ctx,
base_classpath,
extra_deps = [],
extra_runtime_deps = [],
unused_dependency_checker_is_off = True):
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
13 changes: 8 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,15 @@
#
# 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)
return _collect_srcjars(ctx.attr.deps)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, why not

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


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