Skip to content

Commit

Permalink
Add [scala-infer].force_add_siblings_as_dependencies and deprecate …
Browse files Browse the repository at this point in the history
…it defaulting to true (#15841)

Fixes #14382
  • Loading branch information
somdoron authored Jun 17, 2022
1 parent 7f134e9 commit 42bead6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/python/pants/backend/scala/subsystems/scala_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from pants.option.option_types import BoolOption
from pants.option.subsystem import Subsystem
from pants.util.strutil import softwrap


class ScalaInferSubsystem(Subsystem):
Expand All @@ -19,3 +20,18 @@ class ScalaInferSubsystem(Subsystem):
default=True,
help="Infer a target's dependencies by parsing consumed types from sources.",
)
force_add_siblings_as_dependencies = BoolOption(
"--force-add-siblings-as-dependencies",
default=True,
help=softwrap(
"""
If true, add a dependency on all scala_source targets generated by the same scala_sources target generator.
If false, the dependencies will only be added if [scala-infer].imports is also set to false.
Setting this option to true reduces the precision of dependency information.
That means that you may end up compiling more than is necessary for a particular task,
and that compilation will be invalidated more frequently than actually necessary.
However, setting to true may be helpful if compilation fails due to missing dependencies.
"""
),
)
34 changes: 31 additions & 3 deletions src/python/pants/backend/scala/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from dataclasses import dataclass

from pants.backend.scala.subsystems.scala_infer import ScalaInferSubsystem
from pants.base.deprecated import warn_or_error
from pants.engine.rules import collect_rules, rule
from pants.engine.target import (
COMMON_TARGET_FIELDS,
Expand Down Expand Up @@ -36,9 +38,35 @@ class ScalaSettingsRequest(TargetFilesGeneratorSettingsRequest):


@rule
def scala_settings_request(_: ScalaSettingsRequest) -> TargetFilesGeneratorSettings:
# TODO: See https://github.com/pantsbuild/pants/issues/14382.
return TargetFilesGeneratorSettings(add_dependencies_on_all_siblings=True)
def scala_settings_request(
scala_infer_subsystem: ScalaInferSubsystem, _: ScalaSettingsRequest
) -> TargetFilesGeneratorSettings:
if scala_infer_subsystem.options.is_default("force_add_siblings_as_dependencies"):
warn_or_error(
removal_version="2.14.0.dev0",
entity="`force_add_siblings_as_dependencies` defaulting to True",
hint=softwrap(
"""
Setting this option to true reduces the precision of dependency information.
That means that you may end up compiling more than is necessary for a particular task,
and that compilation will be invalidated more frequently than actually necessary.
However, setting to true may be helpful if compilation fails due to missing dependencies.
We have made several improvements to Pants's Scala dependency inference,
where we no longer think it's necessary to adding dependencies on sibling targets.
If you have compilation failures after disabling this option, please consider opening an issue at
https://github.com/pantsbuild/pants/issues/new so that we can continue to improve Pants's dependency inference.
To opt into the new default early, set `force_add_siblings_as_dependencies = false` in the `[scala_infer]`
section in `pants.toml`. Otherwise, set to `true` to silence this warning.
"""
),
)

return TargetFilesGeneratorSettings(
add_dependencies_on_all_siblings=scala_infer_subsystem.force_add_siblings_as_dependencies
or not scala_infer_subsystem.imports
)


class ScalaSourceField(SingleSourceField):
Expand Down

0 comments on commit 42bead6

Please sign in to comment.