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

Dynamically Loading Libraries #1826

Merged
merged 19 commits into from
Jul 5, 2021
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
4 changes: 4 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
project ([#1806](https://github.com/enso-org/enso/pull/1806)).
- Fixed a bug where unresolved imports would crash the compiler
([#1822](https://github.com/enso-org/enso/pull/1822)).
- Implemented the ability to dynamically load local libraries
([#1826](https://github.com/enso-org/enso/pull/1826)). Currently, it only
supports the loading of local libraries, but will be integrated with the
editions system soon.

## Tooling

Expand Down
14 changes: 14 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,18 @@ lazy val `logging-service` = project
.dependsOn(`akka-native`)
.dependsOn(`logging-utils`)

lazy val `logging-truffle-connector` = project
.in(file("lib/scala/logging-truffle-connector"))
.settings(
version := "0.1",
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.graalvm.truffle" % "truffle-api" % graalVersion % "provided"
)
)
.dependsOn(`logging-utils`)
.dependsOn(`polyglot-api`)

lazy val cli = project
.in(file("lib/scala/cli"))
.configs(Test)
Expand Down Expand Up @@ -1084,8 +1096,10 @@ lazy val runtime = (project in file("engine/runtime"))
.dependsOn(`polyglot-api`)
.dependsOn(`text-buffer`)
.dependsOn(searcher)
.dependsOn(`library-manager`)
.dependsOn(testkit % Test)
.dependsOn(`logging-utils`)
.dependsOn(`logging-truffle-connector`)
.dependsOn(`docs-generator`)

/* Note [Unmanaged Classpath]
Expand Down
5 changes: 0 additions & 5 deletions distribution/engine/THIRD-PARTY/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ The license information can be found along with the copyright notices.
Copyright notices related to this dependency can be found in the directory `com.thoughtworks.paranamer.paranamer-2.8`.


'slf4j-api', licensed under the MIT License, is distributed with the engine.
The license file can be found at `licenses/MIT`.
Copyright notices related to this dependency can be found in the directory `org.slf4j.slf4j-api-1.7.26`.


'izumi-reflect_2.13', licensed under the BSD-style, is distributed with the engine.
The license information can be found along with the copyright notices.
Copyright notices related to this dependency can be found in the directory `dev.zio.izumi-reflect_2.13-1.0.0-M5`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2013 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/*
* Copyright 2008 Google LLC
*
Expand All @@ -14,20 +28,6 @@
* limitations under the License.
*/

/*
* Copyright 2013 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/*
* Copyright 2008 Google LLC
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 The Error Prone Authors.
* Copyright 2016 The Error Prone Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
*/

/*
* Copyright 2016 The Error Prone Authors.
* Copyright 2015 The Error Prone Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,7 +47,7 @@
*/

/*
* Copyright 2015 The Error Prone Authors.
* Copyright 2014 The Error Prone Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2009-2020 Lightbend Inc. <https://www.lightbend.com>
* Copyright (C) 2017-2020 Lightbend Inc. <https://www.lightbend.com>
*/

/*
* Copyright (C) 2017-2020 Lightbend Inc. <https://www.lightbend.com>
* Copyright (C) 2009-2020 Lightbend Inc. <https://www.lightbend.com>
*/
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* limitations under the License.
*/

Copyright 2017-2019 John A. De Goes and the ZIO Contributors

/*
* Copyright 2017-2020 John A. De Goes and the ZIO Contributors
* Copyright 2017-2018 Łukasz Biały, Paul Chiusano, Michael Pilquist,
Expand All @@ -36,3 +34,5 @@ Copyright 2017-2019 John A. De Goes and the ZIO Contributors
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Copyright 2017-2019 John A. De Goes and the ZIO Contributors
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011,2012 Mathias Doenitz, Johannes Rudolph
* Copyright (C) 2011 Mathias Doenitz
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
*/

/*
* Copyright (C) 2011 Mathias Doenitz
* Copyright (C) 2011,2012 Mathias Doenitz, Johannes Rudolph
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
24 changes: 0 additions & 24 deletions distribution/engine/THIRD-PARTY/org.slf4j.slf4j-api-1.7.26/NOTICES

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2009-2020 Lightbend Inc. <https://www.lightbend.com>
* Copyright (C) 2017-2020 Lightbend Inc. <https://www.lightbend.com>
*/

/*
* Copyright (C) 2017-2020 Lightbend Inc. <https://www.lightbend.com>
* Copyright (C) 2009-2020 Lightbend Inc. <https://www.lightbend.com>
*/
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* limitations under the License.
*/

Copyright 2017-2019 John A. De Goes and the ZIO Contributors

/*
* Copyright 2017-2020 John A. De Goes and the ZIO Contributors
* Copyright 2017-2018 Łukasz Biały, Paul Chiusano, Michael Pilquist,
Expand All @@ -36,3 +34,5 @@ Copyright 2017-2019 John A. De Goes and the ZIO Contributors
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Copyright 2017-2019 John A. De Goes and the ZIO Contributors
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011,2012 Mathias Doenitz, Johannes Rudolph
* Copyright (C) 2011 Mathias Doenitz
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
*/

/*
* Copyright (C) 2011 Mathias Doenitz
* Copyright (C) 2011,2012 Mathias Doenitz, Johannes Rudolph
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
1 change: 1 addition & 0 deletions docs/libraries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Documents in this section describe Enso's library ecosystem.
organizes library versioning.
- [**Repositories:**](./repositories.md) Information on the structure of
repositories providing Enso libraries and Editions.
- [**Sharing Libraries:**](./sharing.md) Information on how to share libraries.
70 changes: 70 additions & 0 deletions docs/libraries/sharing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
layout: developer-doc
title: Sharing Libraries
category: libraries
tags: [libraries, editions, sharing]
order: 3
---

# Sharing Libraries

This document explains how users can share Enso libraries.

<!-- MarkdownTOC levels="2,3" autolink="true" -->

radeusgd marked this conversation as resolved.
Show resolved Hide resolved
- [Sharing Privately](#sharing-privately)
- [Publishing](#publishing)

<!-- /MarkdownTOC -->

## Sharing Privately

To prepare the project for sharing, make sure that it has a proper `namespace`
field set in `package.yaml`. It should be set to something unique, like your
username.

> **NOTE**: The field `namespace` is a temporary workaround and in the near
> future it will be deprecated and handled mostly automatically. For now however
> you need to set it properly.

To share an Enso library, all you need to do is to package the project into an
archive (for example ZIP) and share it (through e-mail, cloud drive services
etc.) with your peers. Now to be able to use the library that was shared with
you, you need to extract it to the directory
`~/enso/libraries/<namespace>/<Project_Name>` (where on Windows `~` should be
interpreted as your user home directory). To make sure that the library is
extracted correctly, make sure that under the path
`~/enso/libraries/<namespace>/<Project_Name>/package.yaml` and that its
`namespace` field has the same value as the name of the `<namespace>` directory.

> The below step is not necessary yet, but it will be needed once the editions
> system is fully integrated, so it is better to perform it for forwards
> compatibility.

Now you need to set up your project properly to be able to use this unpublished
library. The simplest way to do that is to set `prefer-local-libraries` in your
project's `package.yaml` to `true`. This will make all libraries from
`~/enso/libraries` take precedence over published libraries set-up in the
edition. Alternatively, if you do not want to override all libraries, but only
some of them, you can add a local library override, by adding a proper entry in
the `libraries` section of the `edition` in your project's `package.yaml`, like
shown below:

```yaml
edition:
(...)
libraries:
- name: <namespace>.<Project_Name>
repository: local
```

Now, you can use your library by adding a proper import to your project:

```
import <namespace>.<Project_Name>
```

## Publishing

> Soon it will be possible to share the libraries through the Marketplace, but
> it is still a work in progress.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ class MainModule(serverConfig: LanguageServerConfig, logLevel: LogLevel) {
.allowAllAccess(true)
.allowExperimentalOptions(true)
.option(RuntimeServerInfo.ENABLE_OPTION, "true")
.option(RuntimeOptions.PACKAGES_PATH, serverConfig.contentRootPath)
.option(RuntimeOptions.INTERACTIVE_MODE, "true")
.option(RuntimeOptions.PROJECT_ROOT, serverConfig.contentRootPath)
.option(
RuntimeOptions.LOG_LEVEL,
JavaLoggingLogHandler.getJavaLogLevelFor(logLevel).getName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.enso.languageserver.filemanager.ContentRootManagerActor.ContentRoots
import org.enso.languageserver.filemanager.ContentRootManagerProtocol._
import org.enso.languageserver.monitoring.MonitoringProtocol.{Ping, Pong}
import org.enso.languageserver.util.UnhandledLogging
import org.enso.logger.masking.MaskedPath
import org.enso.polyglot.runtime.Runtime.Api

import java.io.File
Expand Down Expand Up @@ -57,17 +58,22 @@ class ContentRootManagerActor(config: Config)
sender() ! ContentRootsAddedNotification(contentRoots.toList)
context.become(mainStage(contentRoots, subscribers + sender()))

case Api.LibraryLoaded(libraryName, libraryVersion, rootPath) =>
case Api.LibraryLoaded(namespace, name, version, rootPath) =>
val libraryRoot = ContentRootWithFile(
ContentRoot.Library(
id = UUID.randomUUID(),
namespace = libraryName.namespace,
name = libraryName.name,
version = libraryVersion.toString
namespace = namespace,
name = name,
version = version.toString
),
file = rootPath.getCanonicalFile
)

logger.trace(
s"Library root for [$namespace.$name:$version] added at " +
s"[${MaskedPath(rootPath.toPath).applyMasking()}]."
)

subscribers.foreach { subscriber =>
subscriber ! ContentRootsAddedNotification(List(libraryRoot))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ package org.enso.languageserver.filemanager
import akka.actor.{ActorRef, ActorSystem}
import akka.testkit.{TestDuration, TestKit, TestProbe}
import org.apache.commons.lang3.SystemUtils
import org.enso.editions.{LibraryName, LibraryVersion}
import org.enso.languageserver.data._
import org.enso.languageserver.filemanager.ContentRootManagerProtocol.{
ContentRootsAddedNotification,
SubscribeToNotifications
}
import org.enso.polyglot.runtime.Runtime.Api
import org.enso.testkit.EitherValue
import org.scalatest.{Inside, OptionValues}
import org.scalatest.concurrent.Futures
import org.scalatest.concurrent.ScalaFutures.convertScalaFuture
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import org.scalatest.{Inside, OptionValues}

import java.io.File
import java.nio.file.{Path => JPath}
Expand Down Expand Up @@ -87,12 +86,10 @@ class ContentRootManagerSpec
fsRoots should not be empty
}

val libraryName = LibraryName("Foo", "Bar")
val libraryVersion = LibraryVersion.Local
val rootPath = new File("foobar")
val rootPath = new File("foobar")

system.eventStream.publish(
Api.LibraryLoaded(libraryName, libraryVersion, rootPath)
Api.LibraryLoaded("Foo", "Bar", "local", rootPath)
)

inside(subscriberProbe.receiveOne(2.seconds.dilated)) {
Expand Down
Loading