From 7ec2e9edd97ce443312143904c1b21d86a91655f Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 12 Mar 2023 19:58:37 -0400 Subject: [PATCH] Implement platform support --- build.sbt | 4 +- .../CoursierDependencyResolution.scala | 3 +- .../src/main/scala/lmcoursier/FromSbt.scala | 41 ++++++++++++++----- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/build.sbt b/build.sbt index 72125ae67..79c59b94b 100644 --- a/build.sbt +++ b/build.sbt @@ -24,7 +24,7 @@ inThisBuild(List( case v => v } }, - version := "2.0.0-alpha4-SNAPSHOT", + version := "2.0.0-alpha6-SNAPSHOT", scalaVersion := scala3, )) @@ -52,7 +52,7 @@ ThisBuild / assemblyMergeStrategy := { val coursierVersion0 = "2.1.0-M5" val lmVersion = "1.3.4" val lm2_13Version = "1.5.0-M3" -val lm3Version = "2.0.0-alpha7" +val lm3Version = "2.0.0-alpha12" lazy val scalafixGen = Def.taskDyn { val root = (ThisBuild / baseDirectory).value.toURI.toString diff --git a/modules/lm-coursier/src/main/scala/lmcoursier/CoursierDependencyResolution.scala b/modules/lm-coursier/src/main/scala/lmcoursier/CoursierDependencyResolution.scala index 408357d19..a2d3bd93c 100644 --- a/modules/lm-coursier/src/main/scala/lmcoursier/CoursierDependencyResolution.scala +++ b/modules/lm-coursier/src/main/scala/lmcoursier/CoursierDependencyResolution.scala @@ -147,7 +147,8 @@ class CoursierDependencyResolution( val sbv = module0.scalaModuleInfo.map(_.scalaBinaryVersion).getOrElse { sv.split('.').take(2).mkString(".") } - val (mod, ver) = FromSbt.moduleVersion(module0.module, sv, sbv, optionalCrossVer = true) + val projectPlatform = module0.scalaModuleInfo.flatMap(_.platform) + val (mod, ver) = FromSbt.moduleVersion(module0.module, sv, sbv, optionalCrossVer = true, projectPlatform = projectPlatform) val interProjectDependencies = { val needed = conf.interProjectDependencies.exists { p => p.module == mod && p.version == ver diff --git a/modules/lm-coursier/src/main/scala/lmcoursier/FromSbt.scala b/modules/lm-coursier/src/main/scala/lmcoursier/FromSbt.scala index 2e3c7bbeb..4b9349484 100644 --- a/modules/lm-coursier/src/main/scala/lmcoursier/FromSbt.scala +++ b/modules/lm-coursier/src/main/scala/lmcoursier/FromSbt.scala @@ -11,11 +11,16 @@ object FromSbt { moduleId: ModuleID, scalaVersion: => String, scalaBinaryVersion: => String, - optionalCrossVer: Boolean = false + optionalCrossVer: Boolean = false, + projectPlatform: Option[String], ): String = { val name0 = moduleId.name + val name1 = + moduleId.crossVersion match + case _: Disabled => name0 + case _ => addPlatformSuffix(name0, moduleId.platformOpt, projectPlatform) val updatedName = CrossVersion(moduleId.crossVersion, scalaVersion, scalaBinaryVersion) - .fold(name0)(_(name0)) + .fold(name1)(_(name1)) if (!optionalCrossVer || updatedName.length <= name0.length) updatedName else { @@ -27,6 +32,19 @@ object FromSbt { } } + 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), None) => addSuffix(p) + case (_, Some(p)) => addSuffix(p) + case _ => name + } + } + private def attributes(attr: Map[String, String]): Map[String, String] = attr.map { case (k, v) => k.stripPrefix("e:") -> v @@ -38,10 +56,11 @@ object FromSbt { module: ModuleID, scalaVersion: String, scalaBinaryVersion: String, - optionalCrossVer: Boolean + optionalCrossVer: Boolean, + projectPlatform: Option[String], ): (Module, String) = { - val fullName = sbtModuleIdName(module, scalaVersion, scalaBinaryVersion, optionalCrossVer) + val fullName = sbtModuleIdName(module, scalaVersion, scalaBinaryVersion, optionalCrossVer, projectPlatform) val module0 = Module(Organization(module.organization), ModuleName(fullName), attributes(module.extraDependencyAttributes)) val version = module.revision @@ -54,18 +73,19 @@ object FromSbt { scalaVersion: String, scalaBinaryVersion: String ): (Module, String) = - moduleVersion(module, scalaVersion, scalaBinaryVersion, optionalCrossVer = false) + moduleVersion(module, scalaVersion, scalaBinaryVersion, optionalCrossVer = false, projectPlatform = None) def dependencies( module: ModuleID, scalaVersion: String, scalaBinaryVersion: String, - optionalCrossVer: Boolean = false + optionalCrossVer: Boolean = false, + projectPlatform: Option[String] = None, ): Seq[(Configuration, Dependency)] = { // TODO Warn about unsupported properties in `module` - val (module0, version) = moduleVersion(module, scalaVersion, scalaBinaryVersion, optionalCrossVer) + val (module0, version) = moduleVersion(module, scalaVersion, scalaBinaryVersion, optionalCrossVer, projectPlatform) val dep = Dependency( module0, @@ -131,10 +151,11 @@ object FromSbt { allDependencies: Seq[ModuleID], ivyConfigurations: Map[Configuration, Seq[Configuration]], scalaVersion: String, - scalaBinaryVersion: String + scalaBinaryVersion: String, + projectPlatform: Option[String], ): Project = { - val deps = allDependencies.flatMap(dependencies(_, scalaVersion, scalaBinaryVersion)) + val deps = allDependencies.flatMap(dependencies(_, scalaVersion, scalaBinaryVersion, projectPlatform = projectPlatform)) val prefix = "e:" + SbtPomExtraProperties.POM_INFO_KEY_PREFIX val properties = projectID @@ -147,7 +168,7 @@ object FromSbt { Project( Module( Organization(projectID.organization), - ModuleName(sbtModuleIdName(projectID, scalaVersion, scalaBinaryVersion)), + ModuleName(sbtModuleIdName(projectID, scalaVersion, scalaBinaryVersion, projectPlatform = projectPlatform)), attributes(projectID.extraDependencyAttributes) ), projectID.revision,