-
-
Notifications
You must be signed in to change notification settings - Fork 287
Centralize dependency logic #975
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e746893
calling
Jamie5 8b0da8a
lint
Jamie5 927e8c0
Merge remote-tracking branch 'origin/master' into calling
Jamie5 7ea430a
path
Jamie5 9baabe4
Merge branch 'master' into calling
Jamie5 9d60be2
comments
Jamie5 f442b26
comments
Jamie5 fe91373
lint
Jamie5 4a897f4
comment
Jamie5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# This file contains all computations for what the dependency mode is | ||
# (i.e. transitive, plus-one, direct, etc) | ||
# and what/how dependency analysis is performed (unused deps, strict deps, etc). | ||
|
||
def new_dependency_info( | ||
dependency_mode, | ||
unused_deps_mode, | ||
strict_deps_mode, | ||
dependency_tracking_method): | ||
is_strict_deps_on = strict_deps_mode != "off" | ||
|
||
# Currently we do not support running both strict and unused deps at the same time | ||
if is_strict_deps_on: | ||
ittaiz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
unused_deps_mode = "off" | ||
|
||
is_unused_deps_on = unused_deps_mode != "off" | ||
|
||
need_direct_jars = is_strict_deps_on or is_unused_deps_on | ||
need_direct_targets = is_unused_deps_on | ||
|
||
return struct( | ||
dependency_mode = dependency_mode, | ||
need_indirect_info = is_strict_deps_on, | ||
need_direct_jars = need_direct_jars, | ||
need_direct_targets = need_direct_targets, | ||
need_direct_info = need_direct_jars or need_direct_targets, | ||
dependency_tracking_method = "high-level", | ||
unused_deps_mode = unused_deps_mode, | ||
strict_deps_mode = strict_deps_mode, | ||
use_analyzer = is_strict_deps_on or is_unused_deps_on, | ||
) | ||
|
||
# TODO(https://github.com/bazelbuild/rules_scala/issues/987): Clariy the situation | ||
def legacy_unclear_dependency_info_for_protobuf_scrooge(ctx): | ||
return new_dependency_info( | ||
dependency_mode = _legacy_unclear_dependency_mode_for_protobuf_scrooge(ctx), | ||
unused_deps_mode = "off", | ||
strict_deps_mode = get_strict_deps_mode(ctx), | ||
dependency_tracking_method = "high-level", | ||
) | ||
|
||
# TODO(https://github.com/bazelbuild/rules_scala/issues/987): Clariy the situation | ||
def _legacy_unclear_dependency_mode_for_protobuf_scrooge(ctx): | ||
if is_strict_deps_on(ctx): | ||
return "transitive" | ||
else: | ||
return "direct" | ||
|
||
def get_strict_deps_mode(ctx): | ||
if not hasattr(ctx.attr, "_dependency_analyzer_plugin"): | ||
return "off" | ||
|
||
# when the strict deps FT is removed the "default" check | ||
# will be removed since "default" will mean it's turned on | ||
if ctx.fragments.java.strict_java_deps == "default": | ||
return "off" | ||
return ctx.fragments.java.strict_java_deps | ||
|
||
def is_strict_deps_on(ctx): | ||
return get_strict_deps_mode(ctx) != "off" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,6 @@ | |
# | ||
# DOCUMENT THIS | ||
# | ||
load( | ||
"@io_bazel_rules_scala//scala/private:rule_impls.bzl", | ||
"is_dependency_analyzer_off", | ||
"is_plus_one_deps_off", | ||
) | ||
load( | ||
"@io_bazel_rules_scala//scala/private:common.bzl", | ||
"collect_jars", | ||
|
@@ -46,41 +41,32 @@ def phase_collect_jars_junit_test(ctx, p): | |
) | ||
return _phase_collect_jars_default(ctx, p, args) | ||
|
||
def phase_collect_jars_library_for_plugin_bootstrapping(ctx, p): | ||
args = struct( | ||
unused_dependency_checker_mode = "off", | ||
) | ||
return _phase_collect_jars_default(ctx, p, args) | ||
|
||
def phase_collect_jars_common(ctx, p): | ||
return _phase_collect_jars_default(ctx, p) | ||
|
||
def _phase_collect_jars_default(ctx, p, _args = struct()): | ||
return _phase_collect_jars( | ||
ctx, | ||
p, | ||
_args.base_classpath if hasattr(_args, "base_classpath") else p.scalac_provider.default_classpath, | ||
_args.extra_deps if hasattr(_args, "extra_deps") else [], | ||
_args.extra_runtime_deps if hasattr(_args, "extra_runtime_deps") else [], | ||
_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, | ||
p, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wdyt about passing in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good |
||
base_classpath, | ||
extra_deps, | ||
extra_runtime_deps, | ||
unused_dependency_checker_mode): | ||
unused_dependency_checker_is_off = unused_dependency_checker_mode == "off" | ||
dependency_analyzer_is_off = is_dependency_analyzer_off(ctx) | ||
|
||
extra_runtime_deps): | ||
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), | ||
p.dependency.dependency_mode, | ||
p.dependency.need_direct_info, | ||
p.dependency.need_indirect_info, | ||
) | ||
|
||
( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.