Skip to content

Commit 64bb1e2

Browse files
authored
Prevent the toolkit latest deprecation warning from being logged more than once (#2657)
1 parent ba5e53b commit 64bb1e2

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

modules/cli/src/main/scala/scala/cli/commands/shared/SharedOptions.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import dependency.parser.DependencyParser
1212

1313
import java.io.{File, InputStream}
1414
import java.nio.file.Paths
15+
import java.util.concurrent.atomic.AtomicBoolean
1516

1617
import scala.build.EitherCps.{either, value}
1718
import scala.build.Ops.EitherOptOps
@@ -324,6 +325,7 @@ final case class SharedOptions(
324325
s"""[${Console.YELLOW}warn${Console.RESET}] Jars with the ${ScalaCliConsole.GRAY}*-sources.jar${Console.RESET} name suffix are assumed to be source jars.
325326
|The following jars were assumed to be source jars and will be treated as such: $assumedSourceJarsString""".stripMargin
326327
)
328+
val resolvedToolkitDependency = SharedOptions.resolveToolkitDependency(withToolkit, logger)
327329
bo.BuildOptions(
328330
sourceGeneratorOptions = bo.SourceGeneratorOptions(
329331
useBuildInfo = sourceGenerator.useBuildInfo,
@@ -394,13 +396,13 @@ final case class SharedOptions(
394396
SharedOptions.parseDependencies(
395397
dependencies.dependency.map(Positioned.none),
396398
ignoreErrors
397-
) ++ SharedOptions.resolveToolkitDependency(withToolkit, logger)
399+
) ++ resolvedToolkitDependency
398400
),
399401
extraCompileOnlyDependencies = ShadowingSeq.from(
400402
SharedOptions.parseDependencies(
401403
dependencies.compileOnlyDependency.map(Positioned.none),
402404
ignoreErrors
403-
) ++ SharedOptions.resolveToolkitDependency(withToolkit, logger)
405+
) ++ resolvedToolkitDependency
404406
)
405407
),
406408
internal = bo.InternalOptions(
@@ -720,14 +722,18 @@ object SharedOptions {
720722
}
721723
}
722724

725+
// TODO: remove this state after resolving https://github.com/VirtusLab/scala-cli/issues/2658
726+
private val loggedDeprecatedToolkitWarning: AtomicBoolean = AtomicBoolean(false)
723727
private def resolveToolkitDependency(
724728
toolkitVersion: Option[String],
725729
logger: Logger
726730
): Seq[Positioned[AnyDependency]] = {
727731
if (
728-
toolkitVersion.contains("latest")
732+
(toolkitVersion.contains("latest")
729733
|| toolkitVersion.contains(Toolkit.typelevel + ":latest")
730-
|| toolkitVersion.contains(Constants.typelevelOrganization + ":latest")
734+
|| toolkitVersion.contains(
735+
Constants.typelevelOrganization + ":latest"
736+
)) && !loggedDeprecatedToolkitWarning.getAndSet(true)
731737
) logger.message(
732738
WarningMessages.deprecatedToolkitLatest(
733739
s"--toolkit ${toolkitVersion.map(_.replace("latest", "default")).getOrElse("default")}"

modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,10 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
22122212
cwd = root,
22132213
mergeErrIntoOut = true
22142214
)
2215-
expect(resLatest.out.text().contains("Using 'latest' for toolkit is deprecated"))
2215+
val warningText = "Using 'latest' for toolkit is deprecated"
2216+
expect(resLatest.out.text().contains(warningText))
2217+
val warningCount = resLatest.out.text().sliding(warningText.length).count(_ == warningText)
2218+
expect(warningCount == 1)
22162219
}
22172220
}
22182221
}

0 commit comments

Comments
 (0)