-
Notifications
You must be signed in to change notification settings - Fork 323
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
Install Required GraalVM Components #1651
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a206129
feat: install components
4e6 823a1a0
feat: component updater factory
4e6 b121d50
fix: launcher
4e6 71472cb
feat: recover migration
4e6 60dea58
test: fix runtime version manager
4e6 bee9551
fix: java home
4e6 1b5677f
fix: cleanup runtime on faiulre
4e6 e7322ff
Merge branch 'main' into wip/db/graal-migration
4e6 49283ee
Merge branch 'main' into wip/db/graal-migration
4e6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JS is installed by default.