Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support mix of launcherType in version overrides #2975

Merged
merged 7 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ import dataclass._
versionOverride.prebuiltBinaries
.getOrElse(prebuiltBinaries)
}
.withLauncherType {
versionOverride.launcherType
.getOrElse(launcherType)
}
}
.getOrElse(this)
val deps = overriddenDesc.dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ object RawAppDescriptor {
properties: Option[RawAppDescriptor.Properties] = None,
@since("2.1.0-M4")
prebuilt: Option[String] = None,
prebuiltBinaries: Option[Map[String, String]] = None
prebuiltBinaries: Option[Map[String, String]] = None,
@since("2.1.10")
launcherType: Option[String] = None
) {
def versionOverride: ValidatedNel[String, VersionOverride] = {
val versionRangeV = coursier.core.Parse
Expand All @@ -303,8 +305,13 @@ object RawAppDescriptor {
case None => (None, None)
}

(versionRangeV, repositoriesV, dependenciesV).mapN {
(versionRange, repositories, dependencies) =>
val launcherTypeV: ValidatedNel[String, Option[LauncherType]] =
launcherType.map(lt =>
Validated.fromEither(LauncherType.parse(lt).left.map(NonEmptyList.one))
).sequence

(versionRangeV, repositoriesV, dependenciesV, launcherTypeV).mapN {
(versionRange, repositories, dependencies, launcherType) =>
VersionOverride(versionRange)
.withDependencies(dependencies)
.withRepositories(repositories)
Expand All @@ -313,6 +320,7 @@ object RawAppDescriptor {
.withJavaProperties(properties.map(_.props.sorted))
.withPrebuiltLauncher(prebuilt)
.withPrebuiltBinaries(prebuiltBinaries)
.withLauncherType(launcherType)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ import coursier.core.{Repository, VersionInterval}
javaProperties: Option[Seq[(String, String)]] = None,
@since("2.1.0-M4")
prebuiltLauncher: Option[String] = None,
prebuiltBinaries: Option[Map[String, String]] = None
prebuiltBinaries: Option[Map[String, String]] = None,
@since("2.1.10")
launcherType: Option[LauncherType] = None
)
65 changes: 47 additions & 18 deletions modules/install/src/test/scala/coursier/install/InstallTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import utest._
import scala.jdk.CollectionConverters._
import scala.util.control.NonFatal
import coursier.core.Version
import scala.util.Properties
import scala.util.{Properties, Using}

object InstallTests extends TestSuite {

Expand Down Expand Up @@ -92,6 +92,11 @@ object InstallTests extends TestSuite {
new String(FileUtil.readFully(zf.getInputStream(ent)), StandardCharsets.UTF_8)
}

private def findInSource(f: File, needle: String, enc: String = "ISO_8859_1") =
Using(scala.io.Source.fromFile(f, enc)) { s =>
s.getLines().exists(line => line.contains(needle))
}.get

private def commandOutput(command: String*): String =
commandOutput(new File("."), mergeError = false, expectedReturnCode = 0, command: _*)
private def commandOutput(
Expand Down Expand Up @@ -765,14 +770,18 @@ object InstallTests extends TestSuite {
val id = "scalac"
val versionOverride =
RawAppDescriptor.RawVersionOverride("(,2.max]")
.withLauncherType(Some("bootstrap"))
.withDependencies(Some(List("org.scala-lang:scala-compiler:2.12.8")))
.withMainClass(Some("scala.tools.nsc.Main"))
.withProperties(Some(RawAppDescriptor.Properties(
Seq("scala.usejavacp" -> "true")
)))
val appInfo0 = appInfo(
RawAppDescriptor(List("org.scala-lang:scala3-compiler_3:3.0.1"))
RawAppDescriptor(List("org.scala-lang:scala3-compiler_3:3.3.3"))
.withRepositories(List("central"))
.withMainClass(Some("dotty.tools.dotc.Main"))
.withProperties(RawAppDescriptor.Properties(
Seq("scala.usejavacp" -> "true")
.withLauncherType("prebuilt")
.withPrebuilt(Some(
"zip+https://github.com/scala/scala3/releases/download/${version}/scala3-${version}.zip!scala3-${version}/bin/scalac"
))
.withVersionOverrides(List(versionOverride)),
id
Expand All @@ -787,6 +796,14 @@ object InstallTests extends TestSuite {
val launcher = installDir0.actualDest(id)
assert(Files.isRegularFile(launcher))

// for a prebuilt launcher, we expect the path of the launcher to appear somewhere in the script
val scala3path = {
val original =
"github.com/scala/scala3/releases/download/3.3.3/scala3-3.3.3.zip/scala3-3.3.3/bin/scala"
if (currentOs == "windows") original.replace('/', '\\')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use currentOs here because if ran from e.g. macOS then the Mac-formatted path will actually be in the launcher.

else original
}

def testRun(expectedUrls: Seq[String], expectedProperties: Seq[String]): Unit = {
assert(Files.isRegularFile(launcher))

Expand All @@ -804,19 +821,28 @@ object InstallTests extends TestSuite {
assert(properties == expectedProperties)
}

val scala3CompilerJars =
Seq(
"https://repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/3.0.1/scala3-compiler_3-3.0.1.jar",
"https://repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.0.1/scala3-library_3-3.0.1.jar",
"https://repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.6/scala-library-2.13.6.jar"
)
val scala3Properties =
Seq(
"bootstrap.mainClass=dotty.tools.dotc.Main",
"scala.usejavacp=true",
"scala3-compiler_3.version=3.0.1"
def searchInScript(needle: String): Unit = {
assert(Files.isRegularFile(launcher))

val foundNeedle = findInSource(launcher.toFile(), needle)
val expected = true
assert(foundNeedle == expected)
}

def testOutput(expectedInOut: String): Unit = {
val output = commandOutput(
tmpDir.toFile,
mergeError = true,
expectedReturnCode = 0,
launcher.toAbsolutePath.toString,
"-version"
)
testRun(scala3CompilerJars, scala3Properties)
assert(output.contains(expectedInOut))
}

searchInScript(scala3path)
if (currentOs == os)
testOutput("Scala compiler version 3.3.3 -- Copyright 2002-2024, LAMP/EPFL")

val overridenAppInfo = appInfo0.overrideVersion("2.12.8")
val overridden = installDir0.createOrUpdate(overridenAppInfo)
Expand All @@ -835,12 +861,15 @@ object InstallTests extends TestSuite {
"scala.usejavacp=true",
"scala-compiler.version=2.12.8"
)

testRun(scala2CompilerJars, scala2Properties)

val updated = installDir0.createOrUpdate(appInfo0)
assert(updated.exists(identity))

testRun(scala3CompilerJars, scala3Properties)
bishabosha marked this conversation as resolved.
Show resolved Hide resolved
searchInScript(scala3path)
if (currentOs == os)
testOutput("Scala compiler version 3.3.3 -- Copyright 2002-2024, LAMP/EPFL")
}

test("linux") - run("linux", "x86_64")
Expand Down
2 changes: 1 addition & 1 deletion modules/tests/metadata
Submodule metadata updated 25 files
+ https/github.com/scala/scala3/releases/download/3.3.3/scala3-3.3.3.zip
+ https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.3.1/jna-5.3.1.jar
+634 −0 https/repo1.maven.org/maven2/org/jline/jline-parent/3.19.0/jline-parent-3.19.0.pom
+ https/repo1.maven.org/maven2/org/jline/jline-reader/3.19.0/jline-reader-3.19.0.jar
+42 −0 https/repo1.maven.org/maven2/org/jline/jline-reader/3.19.0/jline-reader-3.19.0.pom
+ https/repo1.maven.org/maven2/org/jline/jline-terminal-jna/3.19.0/jline-terminal-jna-3.19.0.jar
+62 −0 https/repo1.maven.org/maven2/org/jline/jline-terminal-jna/3.19.0/jline-terminal-jna-3.19.0.pom
+ https/repo1.maven.org/maven2/org/jline/jline-terminal/3.19.0/jline-terminal-3.19.0.jar
+43 −0 https/repo1.maven.org/maven2/org/jline/jline-terminal/3.19.0/jline-terminal-3.19.0.pom
+ https/repo1.maven.org/maven2/org/scala-lang/modules/scala-asm/9.5.0-scala-1/scala-asm-9.5.0-scala-1.jar
+41 −0 https/repo1.maven.org/maven2/org/scala-lang/modules/scala-asm/9.5.0-scala-1/scala-asm-9.5.0-scala-1.pom
+ https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar
+44 −0 https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.pom
+ https/repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/3.3.3/scala3-compiler_3-3.3.3.jar
+142 −0 https/repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/3.3.3/scala3-compiler_3-3.3.3.pom
+ https/repo1.maven.org/maven2/org/scala-lang/scala3-interfaces/3.3.3/scala3-interfaces-3.3.3.jar
+99 −0 https/repo1.maven.org/maven2/org/scala-lang/scala3-interfaces/3.3.3/scala3-interfaces-3.3.3.pom
+ https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.3/scala3-library_3-3.3.3.jar
+104 −0 https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.3/scala3-library_3-3.3.3.pom
+ https/repo1.maven.org/maven2/org/scala-lang/tasty-core_3/3.3.3/tasty-core_3-3.3.3.jar
+104 −0 https/repo1.maven.org/maven2/org/scala-lang/tasty-core_3/3.3.3/tasty-core_3-3.3.3.pom
+ https/repo1.maven.org/maven2/org/scala-sbt/compiler-interface/1.9.3/compiler-interface-1.9.3.jar
+86 −0 https/repo1.maven.org/maven2/org/scala-sbt/compiler-interface/1.9.3/compiler-interface-1.9.3.pom
+ https/repo1.maven.org/maven2/org/scala-sbt/util-interface/1.9.2/util-interface-1.9.2.jar
+73 −0 https/repo1.maven.org/maven2/org/scala-sbt/util-interface/1.9.2/util-interface-1.9.2.pom