[2.x] refactor: Hide addPlatformSuffix, keep documented FromSbt duplicate

This commit is contained in:
Ali Rashid 2026-06-02 23:14:38 +03:00
parent e2601b7ca6
commit 770fedb72e
No known key found for this signature in database
GPG Key ID: 390A98FD741968E1
2 changed files with 26 additions and 5 deletions

View File

@ -168,17 +168,17 @@ private[librarymanagement] abstract class CrossVersionFunctions {
/**
* Appends the platform suffix (e.g. `native0.5`, `sjs1`) to `name`, preferring an explicit
* `platformOpt` over the `projectPlatform`. `""` and `jvm` add no suffix.
* `platformOpt` over the `projectPlatform`. `""` and `jvm` add no suffix. Keep in sync with
* `lmcoursier.FromSbt.addPlatformSuffix` (until lm-coursier moves under sbt).
*/
def addPlatformSuffix(
private[sbt] def addPlatformSuffix(
name: String,
platformOpt: Option[String],
projectPlatform: Option[String]
): String =
(platformOpt orElse projectPlatform) match {
platformOpt.orElse(projectPlatform) match
case Some(p) if p.nonEmpty && p != Platform.jvm => crossName(name, p)
case _ => name
}
/** Cross-versions `exclude` according to its `crossVersion`. */
private[sbt] def substituteCross(

View File

@ -32,7 +32,7 @@ object FromSbt {
val name1 =
crossVersion match
case _: Disabled => name0
case _ => CrossVersion.addPlatformSuffix(name0, platformOpt, projectPlatform)
case _ => addPlatformSuffix(name0, platformOpt, projectPlatform)
val updatedName = CrossVersion(crossVersion, scalaVersion, scalaBinaryVersion)
.fold(name1)(_(name1))
if (!optionalCrossVer || updatedName.length <= name0.length)
@ -46,6 +46,27 @@ object FromSbt {
}
}
// Duplicate of sbt.librarymanagement.CrossVersion.addPlatformSuffix. Keep the two in sync
// until lm-coursier moves under sbt
private def addPlatformSuffix(
name: String,
platformOpt: Option[String],
projectPlatform: Option[String]
): String = {
def addSuffix(platformName: String): String =
platformName match {
case "" | "jvm" => name
case _ => s"${name}_$platformName"
}
(platformOpt, projectPlatform) match {
case (Some(p), _) =>
addSuffix(p) // Use explicit platform if set (don't override with project platform)
case (None, Some(p)) =>
addSuffix(p) // Only use project platform if dependency has no explicit platform
case _ => name
}
}
private def attributes(attr: Map[String, String]): Map[String, String] =
attr
.map { (k, v) =>