# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

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


class ScalaInferSubsystem(Subsystem):
    options_scope = "scala-infer"
    help = "Options controlling which dependencies will be inferred for Scala targets."

    imports = BoolOption(
        default=True,
        help="Infer a target's dependencies by parsing import statements from sources.",
    )
    consumed_types = BoolOption(
        default=True,
        help="Infer a target's dependencies by parsing consumed types from sources.",
    )
    package_objects = BoolOption(
        default=True,
        help="Add dependency on the package object to every target.",
    )
    force_add_siblings_as_dependencies = BoolOption(
        default=False,
        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.
            """
        ),
    )
