-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preinstalling With Dependencies (#1981)
- Loading branch information
Showing
41 changed files
with
1,161 additions
and
123 deletions.
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
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
70 changes: 70 additions & 0 deletions
70
...r/src/main/scala/org/enso/languageserver/libraries/CompilerBasedDependencyExtractor.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,70 @@ | ||
package org.enso.languageserver.libraries | ||
|
||
import org.enso.editions.LibraryName | ||
import org.enso.libraryupload.DependencyExtractor | ||
import org.enso.loggingservice.{JavaLoggingLogHandler, LogLevel} | ||
import org.enso.pkg.Package | ||
import org.enso.pkg.SourceFile | ||
import org.enso.polyglot.{PolyglotContext, RuntimeOptions} | ||
import org.graalvm.polyglot.Context | ||
|
||
import java.io.File | ||
|
||
/** A dependency extractor that runs the compiler in a mode that only parses the | ||
* source code and runs just the basic preprocessing phases to find out what | ||
* libraries are imported by the project. | ||
* | ||
* @param logLevel the log level to use for the runtime context that will do | ||
* the parsing | ||
*/ | ||
class CompilerBasedDependencyExtractor(logLevel: LogLevel) | ||
extends DependencyExtractor[File] { | ||
|
||
/** @inheritdoc */ | ||
override def findDependencies(pkg: Package[File]): Set[LibraryName] = { | ||
val context = createContextWithProject(pkg) | ||
|
||
def findImportedLibraries(file: SourceFile[File]): Set[LibraryName] = { | ||
val module = context.getTopScope.getModule(file.qualifiedName.toString) | ||
val imports = module.gatherImportStatements() | ||
val importedLibraries = imports.map { rawName => | ||
LibraryName.fromString(rawName) match { | ||
case Left(error) => | ||
throw new IllegalStateException(error) | ||
case Right(value) => value | ||
} | ||
} | ||
importedLibraries.toSet | ||
} | ||
|
||
val sourcesImports = pkg.listSources.toSet.flatMap(findImportedLibraries) | ||
val itself = pkg.libraryName | ||
|
||
// Builtins need to be removed from the set of the dependencies, because | ||
// even if they are imported, they are not a typical library. | ||
val builtins = LibraryName("Standard", "Builtins") | ||
|
||
sourcesImports - itself - builtins | ||
} | ||
|
||
/** Creates a simple runtime context with the given package loaded as its | ||
* project root. | ||
*/ | ||
private def createContextWithProject(pkg: Package[File]): PolyglotContext = { | ||
val context = Context | ||
.newBuilder() | ||
.allowExperimentalOptions(true) | ||
.allowAllAccess(true) | ||
.option(RuntimeOptions.PROJECT_ROOT, pkg.root.getCanonicalPath) | ||
.option("js.foreign-object-prototype", "true") | ||
.option( | ||
RuntimeOptions.LOG_LEVEL, | ||
JavaLoggingLogHandler.getJavaLogLevelFor(logLevel).getName | ||
) | ||
.logHandler( | ||
JavaLoggingLogHandler.create(JavaLoggingLogHandler.defaultLevelMapping) | ||
) | ||
.build | ||
new PolyglotContext(context) | ||
} | ||
} |
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
9 changes: 7 additions & 2 deletions
9
...uage-server/src/main/scala/org/enso/languageserver/libraries/LibraryInstallerConfig.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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
package org.enso.languageserver.libraries | ||
|
||
import org.enso.distribution.{DistributionManager, LanguageHome} | ||
import org.enso.distribution.locking.ResourceManager | ||
import org.enso.distribution.{DistributionManager, LanguageHome} | ||
import org.enso.libraryupload.DependencyExtractor | ||
|
||
import java.io.File | ||
|
||
/** Gathers configuration needed by the library installer used in the | ||
* `library/preinstall` endpoint. | ||
* | ||
* @param distributionManager the distribution manager | ||
* @param resourceManager a resource manager instance | ||
* @param languageHome language home, if detected / applicable | ||
* @param dependencyExtractor a dependency extractor | ||
*/ | ||
case class LibraryInstallerConfig( | ||
distributionManager: DistributionManager, | ||
resourceManager: ResourceManager, | ||
languageHome: Option[LanguageHome] | ||
languageHome: Option[LanguageHome], | ||
dependencyExtractor: DependencyExtractor[File] | ||
) |
Oops, something went wrong.