-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install Required GraalVM Components (#1651)
Project manager ensures that the required GraalVM components are installed.
- Loading branch information
1 parent
d75b56d
commit a94590d
Showing
17 changed files
with
501 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...anager-test/src/main/scala/org/enso/runtimeversionmanager/test/NoopComponentUpdater.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.enso.runtimeversionmanager.test | ||
|
||
import org.enso.runtimeversionmanager.components.{ | ||
GraalVMComponent, | ||
RuntimeComponentUpdater | ||
} | ||
|
||
import scala.util.Try | ||
|
||
/** Test component updater that does not do anything. */ | ||
object NoopComponentUpdater extends RuntimeComponentUpdater { | ||
|
||
/** @inheritdoc */ | ||
override def list: Try[Seq[GraalVMComponent]] = | ||
Try(Seq()) | ||
|
||
/** @inheritdoc */ | ||
override def install(components: Seq[GraalVMComponent]): Try[Unit] = | ||
Try(()) | ||
} |
16 changes: 16 additions & 0 deletions
16
...test/src/main/scala/org/enso/runtimeversionmanager/test/NoopComponentUpdaterFactory.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.enso.runtimeversionmanager.test | ||
|
||
import org.enso.runtimeversionmanager.OS | ||
import org.enso.runtimeversionmanager.components.{ | ||
GraalRuntime, | ||
RuntimeComponentUpdater, | ||
RuntimeComponentUpdaterFactory | ||
} | ||
|
||
/** Test factory creating a noop updater. */ | ||
object NoopComponentUpdaterFactory extends RuntimeComponentUpdaterFactory { | ||
|
||
/** @inheritdoc */ | ||
override def build(runtime: GraalRuntime, os: OS): RuntimeComponentUpdater = | ||
NoopComponentUpdater | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...n-manager/src/main/scala/org/enso/runtimeversionmanager/components/GraalVMComponent.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.enso.runtimeversionmanager.components | ||
|
||
/** A component of the GraalVM distribution. */ | ||
case class GraalVMComponent(id: String) | ||
|
||
object GraalVMComponent { | ||
|
||
val js: GraalVMComponent = GraalVMComponent("js") | ||
val python: GraalVMComponent = GraalVMComponent("python") | ||
val R: GraalVMComponent = GraalVMComponent("R") | ||
} |
52 changes: 52 additions & 0 deletions
52
.../main/scala/org/enso/runtimeversionmanager/components/GraalVMComponentConfiguration.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.enso.runtimeversionmanager.components | ||
|
||
import org.enso.runtimeversionmanager.OS | ||
|
||
/** Component configuration of the GraalVM distribution. */ | ||
class GraalVMComponentConfiguration extends RuntimeComponentConfiguration { | ||
|
||
import GraalVMComponentConfiguration._ | ||
|
||
/** @inheritdoc */ | ||
override def getRequiredComponents( | ||
version: GraalVMVersion, | ||
os: OS | ||
): Seq[GraalVMComponent] = | ||
version.graalVersion match { | ||
case GraalVersions.Major(v) if v > 20 && os.hasSulongSupport => | ||
Seq(GraalVMComponent.python, GraalVMComponent.R) | ||
case _ => | ||
Seq() | ||
} | ||
|
||
} | ||
object GraalVMComponentConfiguration { | ||
|
||
/** OS extensions. */ | ||
implicit private class OSExtensions(os: OS) { | ||
|
||
/** Check if the provided OS supports Sulong runtime. | ||
* | ||
* Sulong is a Graal sub-project, providing an engine for running | ||
* LLVM bitcode on GraalVM. | ||
* | ||
* @return `true` if the OS supports Sulong runtime and `false` otherwise | ||
*/ | ||
def hasSulongSupport: Boolean = | ||
os match { | ||
case OS.Linux => true | ||
case OS.MacOS => true | ||
case OS.Windows => false | ||
} | ||
} | ||
|
||
private object GraalVersions { | ||
|
||
/** Get the major Graal version number. */ | ||
object Major { | ||
def unapply(version: String): Option[Int] = { | ||
version.takeWhile(_ != '.').toIntOption | ||
} | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...er/src/main/scala/org/enso/runtimeversionmanager/components/GraalVMComponentUpdater.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.enso.runtimeversionmanager.components | ||
|
||
import java.nio.file.Path | ||
|
||
import org.enso.runtimeversionmanager.OS | ||
|
||
import scala.sys.process._ | ||
import scala.util.{Success, Try} | ||
|
||
/** Module that manages components of the GraalVM distribution. | ||
* | ||
* @param runtime the GraalVM runtime | ||
* @param os the operating system | ||
*/ | ||
class GraalVMComponentUpdater(runtime: GraalRuntime, os: OS) | ||
extends RuntimeComponentUpdater { | ||
|
||
import GraalVMComponentUpdater._ | ||
|
||
/** List the installed GraalVM components. | ||
* | ||
* @return the list of installed GraalVM components | ||
*/ | ||
override def list: Try[Seq[GraalVMComponent]] = { | ||
val suppressStderr = ProcessLogger(_ => ()) | ||
val process = Process( | ||
Seq[String](Paths.gu, "list", "-v"), | ||
Some(runtime.path.toFile), | ||
("JAVA_HOME", runtime.path), | ||
("GRAALVM_HOME", runtime.path) | ||
) | ||
|
||
for { | ||
lines <- Try(process.lazyLines(suppressStderr)) | ||
} yield ListOut.parse(lines) | ||
} | ||
|
||
/** Install the provided GraalVM components. | ||
* | ||
* @param components the list of components to install | ||
*/ | ||
override def install(components: Seq[GraalVMComponent]): Try[Unit] = { | ||
if (components.nonEmpty) { | ||
val componentsList = components.map(_.id) | ||
val process = Process( | ||
Seq[String](Paths.gu, "install") ++ componentsList, | ||
Some(runtime.path.toFile), | ||
("JAVA_HOME", runtime.path), | ||
("GRAALVM_HOME", runtime.path) | ||
) | ||
Try(process.!!) | ||
} else { | ||
Success(()) | ||
} | ||
} | ||
|
||
private object Paths { | ||
|
||
/** Path to `gu` executable. */ | ||
val gu: Path = os match { | ||
case OS.Linux => runtime.path / "bin" / "gu" | ||
case OS.MacOS => runtime.path / "bin" / "gu" | ||
case OS.Windows => runtime.path / "bin" / "gu.cmd" | ||
} | ||
} | ||
} | ||
object GraalVMComponentUpdater { | ||
|
||
implicit private def pathToString(path: Path): String = | ||
path.toAbsolutePath.toString | ||
|
||
implicit private class PathExtensions(path: Path) { | ||
|
||
def /(child: String): Path = path.resolve(child) | ||
} | ||
|
||
/** Parser for the `gu list -v` command output. */ | ||
object ListOut { | ||
|
||
private val ID: String = "ID" | ||
private val separator: Char = ':' | ||
|
||
/** Extract the GraalVM components from the gu output. | ||
* | ||
* @param lines the gu output | ||
* @return the list of GraalVM components. | ||
*/ | ||
def parse(lines: Seq[String]): Seq[GraalVMComponent] = | ||
lines | ||
.filter(_.startsWith(ID)) | ||
.map(_.dropWhile(_ != separator).drop(1).trim) | ||
.map(GraalVMComponent(_)) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../main/scala/org/enso/runtimeversionmanager/components/RuntimeComponentConfiguration.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.enso.runtimeversionmanager.components | ||
|
||
import org.enso.runtimeversionmanager.OS | ||
|
||
/** Provides configuration of the runtime components. */ | ||
trait RuntimeComponentConfiguration { | ||
|
||
/** Return the list of components required for the provided version of | ||
* the runtime installed on the provided OS. | ||
* | ||
* @param version the runtime version | ||
* @param os the operating system | ||
* @return the list of required components | ||
*/ | ||
def getRequiredComponents( | ||
version: GraalVMVersion, | ||
os: OS | ||
): Seq[GraalVMComponent] | ||
} |
19 changes: 19 additions & 0 deletions
19
...er/src/main/scala/org/enso/runtimeversionmanager/components/RuntimeComponentUpdater.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.enso.runtimeversionmanager.components | ||
|
||
import scala.util.Try | ||
|
||
/** Module that manages components of the runtime distribution. */ | ||
trait RuntimeComponentUpdater { | ||
|
||
/** List the installed runtime components. | ||
* | ||
* @return the list of installed runtime components | ||
*/ | ||
def list: Try[Seq[GraalVMComponent]] | ||
|
||
/** Install the provided runtime components. | ||
* | ||
* @param components the list of components to install | ||
*/ | ||
def install(components: Seq[GraalVMComponent]): Try[Unit] | ||
} |
Oops, something went wrong.