Skip to content

Commit

Permalink
Fix updating toolkit dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao committed May 23, 2023
1 parent f81fa68 commit de7798b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Expand Up @@ -5,6 +5,7 @@ import caseapp.core.help.HelpFormat

import scala.build.actionable.ActionableDependencyHandler
import scala.build.actionable.ActionableDiagnostic.ActionableDependencyUpdateDiagnostic
import scala.build.internal.Constants
import scala.build.options.{BuildOptions, Scope}
import scala.build.{CrossSources, Logger, Position, Sources}
import scala.cli.CurrentParams
Expand Down Expand Up @@ -60,7 +61,9 @@ object DependencyUpdate extends ScalaCommand[DependencyUpdateOptions] {
val actionableMainUpdateDiagnostics = generateActionableUpdateDiagnostic(Scope.Main)
val actionableTestUpdateDiagnostics = generateActionableUpdateDiagnostic(Scope.Test)
val actionableUpdateDiagnostics =
(actionableMainUpdateDiagnostics ++ actionableTestUpdateDiagnostics).distinct
(actionableMainUpdateDiagnostics ++ actionableTestUpdateDiagnostics)
.distinct
.filter(_.dependencyModuleName != Constants.toolkitTestName)

if (options.all)
updateDependencies(actionableUpdateDiagnostics, logger)
Expand Down
Expand Up @@ -61,7 +61,7 @@ class DependencyUpdateTests extends ScalaCliSuite {
}
}

test("update typelevel toolkit dependence") {
test("update typelevel toolkit dependency") {
val toolkitVersion = "0.0.1"
val testInputs = TestInputs(
os.rel / "Foo.scala" ->
Expand All @@ -79,7 +79,7 @@ class DependencyUpdateTests extends ScalaCliSuite {
os.proc(TestUtil.cli, "--power", "dependency-update", "--all", ".")
.call(cwd = root)

val toolkitDirective = "//> using toolkit \"(.*)\"".r
val toolkitDirective = "//> using toolkit \"typelevel:(.*)\"".r
val updatedToolkitVersionOpt = {
val regexMatch = toolkitDirective.findFirstMatchIn(os.read(root / "Foo.scala"))
regexMatch.map(_.group(1))
Expand Down
Expand Up @@ -3,14 +3,15 @@ package scala.build.actionable
import coursier.Versions
import coursier.core.{Latest, Version}
import coursier.parse.RepositoryParser
import dependency._
import dependency.*

import scala.build.EitherCps.{either, value}
import scala.build.Positioned
import scala.build.actionable.ActionableDiagnostic._
import scala.build.actionable.ActionableDiagnostic.*
import scala.build.actionable.errors.ActionableHandlerError
import scala.build.errors.{BuildException, RepositoryFormatError}
import scala.build.internal.Util._
import scala.build.internal.Constants
import scala.build.internal.Util.*
import scala.build.options.BuildOptions
import scala.build.options.ScalaVersionUtil.versions
import scala.concurrent.duration.DurationInt
Expand All @@ -32,14 +33,22 @@ case object ActionableDependencyHandler
val dependency = setting.value
val currentVersion = dependency.version
val latestVersion = value(findLatestVersion(buildOptions, dependency))
if (Version(latestVersion) > Version(currentVersion) && !isLatestSyntaxVersion(currentVersion))
if (dependency.userParams.contains("toolkit"))
if Version(latestVersion) > Version(currentVersion) && !isLatestSyntaxVersion(currentVersion)
then
if dependency.userParams.contains(Constants.toolkitName) &&
dependency.module.name != Constants.toolkitTestName
then
val toolkitSuggestion =
if dependency.module.organization == Constants.toolkitOrganization then latestVersion
else if dependency.module.organization == Constants.typelevelOrganization then
s"typelevel:$latestVersion"
else s"${dependency.module.organization}:$latestVersion"
Some(ActionableDependencyUpdateDiagnostic(
setting.positions,
currentVersion,
latestVersion,
dependencyModuleName = "toolkit",
suggestion = latestVersion
dependencyModuleName = Constants.toolkitName,
suggestion = toolkitSuggestion
))
else
Some(ActionableDependencyUpdateDiagnostic(
Expand Down

0 comments on commit de7798b

Please sign in to comment.