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

Fix --offline mode for scala-cli as scala installation via coursier #3029

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ final case class SharedOptions(
extraCompileOnlyJars = extraCompileOnlyClassPath,
extraSourceJars = extraSourceJars.extractedClassPath ++ assumedSourceJars,
extraRepositories =
(dependencies.repository ++ ScalaCli.launcherOptions.scalaRunner.cliPredefinedRepository)
(ScalaCli.launcherOptions.scalaRunner.cliPredefinedRepository ++ dependencies.repository)
.map(_.trim)
.filter(_.nonEmpty),
extraDependencies = ShadowingSeq.from(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,61 @@ class SipScalaTests extends ScalaCliSuite with SbtTestHelper with MillTestHelper
expect(res.out.trim().contains(scalaVersion))
}
}

if (!Properties.isWin) // FIXME: run this test on Windows
test("coursier scala installation works in --offline mode") {
TestInputs.empty.fromRoot { root =>
val localCache = root / "local-cache"
val localBin = root / "local-bin"
val sv = "3.5.0-RC4"
os.proc(
TestUtil.cs,
"install",
"--cache",
localCache,
"--install-dir",
localBin,
s"scala:$sv"
).call(cwd = root)
val scalaBinary: os.Path = localBin / "scala"
val fileBytes = os.read.bytes(scalaBinary)
val shebang = new String(fileBytes.takeWhile(_ != '\n'), "UTF-8")
val binaryData = fileBytes.drop(shebang.length + 1)
val execLine = new String(binaryData.takeWhile(_ != '\n'), "UTF-8")
val scriptPathRegex = """exec "([^"]+/bin/scala).*"""".r
val scalaScript = execLine match { case scriptPathRegex(extractedPath) => extractedPath }
val scalaScriptPath = os.Path(scalaScript)
val lineToChange = "eval \"${SCALA_CLI_CMD_BASH[@]}\" \\"
// FIXME: the way the scala script calls the launcher currently ignores the --debug flag
tgodzik marked this conversation as resolved.
Show resolved Hide resolved
val newContent = os.read(scalaScriptPath).replace(
lineToChange,
s"""SCALA_CLI_CMD_BASH=(\"\\\"${TestUtil.cliPath}\\\"\")
|$lineToChange""".stripMargin
)
os.write.over(scalaScriptPath, newContent)
val r =
os.proc(
scalaScript,
"--offline",
"--power",
"--with-compiler",
"-e",
"println(dotty.tools.dotc.config.Properties.versionNumberString)"
).call(
cwd = root,
env = Map("COURSIER_CACHE" -> localCache.toString),
check = false // need to clean up even on failure
)
// clean up cs local binaries
val csPrebuiltBinaryDir =
os.Path(scalaScript.substring(0, scalaScript.indexOf(sv) + sv.length))
try os.remove.all(csPrebuiltBinaryDir)
catch {
case ex: java.nio.file.FileSystemException =>
println(s"Failed to remove $csPrebuiltBinaryDir: $ex")
}
expect(r.exitCode == 0)
expect(r.out.trim() == sv)
}
}
}
6 changes: 4 additions & 2 deletions modules/options/src/main/scala/scala/build/Artifacts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,11 @@ object Artifacts {
val forceVersion = forceScalaVersions ++ forcedVersions

// FIXME Many parameters that we could allow to customize here
var fetcher = coursier.Fetch()
val defaultFetcher = coursier.Fetch()
Gedochao marked this conversation as resolved.
Show resolved Hide resolved
var fetcher = defaultFetcher
.withCache(cache)
.addRepositories(extraRepositoriesWithFallback*)
// repository order matters here, since in some cases coursier resolves only the head
.withRepositories(extraRepositoriesWithFallback ++ defaultFetcher.repositories)
.addDependencies(dependencies.map(_.value)*)
.mapResolutionParams(_.addForceVersion(forceVersion*))
for (classifiers <- classifiersOpt) {
Expand Down
Loading