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

feat: decouple env plugin from language runtimes #452

Merged
merged 3 commits into from
Oct 10, 2023

Conversation

darvld
Copy link
Member

@darvld darvld commented Oct 6, 2023

Ready for review Powered by Pull Request Badge

Summary

This PR updates the Environment plugin to remove dependencies on language plugins.

The env variables proxy is injected through polyglot bindings by default. Languages without support for polyglot bindings may install the env proxy manually to language-scoped bindings using Environment.install(PolyglotContext, GuestLanguage).

@darvld darvld added module:graalvm Modules, changes, and issues relating to GraalVM 🚧 WIP Works-in-progress. Blocks merge labels Oct 6, 2023
@darvld darvld changed the title feat: decouple env plugin from language runtimes. feat: decouple env plugin from language runtimes Oct 6, 2023
@github-actions github-actions bot added platform:jvm PRs and issues relating to JVM support. and removed module:graalvm Modules, changes, and issues relating to GraalVM labels Oct 6, 2023
* @see EnvConfig
*/
@DelicateElideApi public class Environment private constructor (public val config: EnvConfig) {
private val effectiveEnvironment: AtomicReference<MutableMap<String, String?>> = AtomicReference(null)
Copy link
Member Author

Choose a reason for hiding this comment

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

environment is now mapped from the config, we no longer need to manually synchronize or even assign this map (lazy is technically still synchronized).

override val key: Key<Environment> = Key("Environment")

override fun install(scope: InstallationScope, configuration: EnvConfig.() -> Unit): Environment {
// apply the configuration and create the plugin instance
val config = EnvConfig().apply(configuration)
val instance = Environment(config)

// @TODO: graceful language detection
Copy link
Member Author

Choose a reason for hiding this comment

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

fixed, now there's no need for language detection

@@ -60,80 +56,40 @@ import elide.vm.annotations.Polyglot

/** Apply an environment [config] to a context [builder] during the [ContextCreated] event. */
internal fun onContextCreate(builder: PolyglotContextBuilder) {
if (config.app.enabled) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Environment map initialization logic has been moved to a lazy property

private val mutableEnvironmentVariables: MutableMap<String, EnvVar> = ConcurrentSkipListMap()

/** Register an [EnvVar] with the given [key]. */
public fun setEnv(key: String, value: EnvVar) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Following a similar pattern to language bindings in AbstractLanguagePlugin, expose only an immutable map and very restricted mutating operations using methods.

@darvld darvld self-assigned this Oct 7, 2023
@darvld darvld force-pushed the feat/env-plugin-refactor branch 2 times, most recently from a8b92d3 to a084931 Compare October 7, 2023 02:38
Signed-off-by: Dario Valdespino <dvaldespino00@gmail.com>
Signed-off-by: Dario Valdespino <dvaldespino00@gmail.com>
Signed-off-by: Dario Valdespino <dvaldespino00@gmail.com>
@darvld darvld marked this pull request as ready for review October 7, 2023 15:13
@darvld darvld requested a review from sgammon as a code owner October 7, 2023 15:13
@darvld darvld removed the 🚧 WIP Works-in-progress. Blocks merge label Oct 7, 2023
@sgammon sgammon added this to the Release R4: Alpha 8 milestone Oct 7, 2023
@sgammon sgammon merged commit 80cabd0 into main Oct 10, 2023
29 checks passed
@sgammon sgammon deleted the feat/env-plugin-refactor branch October 10, 2023 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:jvm PRs and issues relating to JVM support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants