Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Update API to support the new content roots #1640

Merged
merged 10 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
46 changes: 24 additions & 22 deletions src/js/lib/client/tasks/signArchives.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ const resRoot = path.join(contentRoot, 'Resources')

// TODO: Refactor this once we have a better wau to get the used engine version.
// See the tracking issue for more information https://github.com/enso-org/ide/issues/1359
const ENGINE = '0.2.11'
const ENGINE = '0.2.12'
const ID = '"Developer ID Application: New Byte Order Sp. z o. o. (NM77WTZJFQ)"'
// Placeholder name for temporary archives.
const tmpArchive = 'temporary_archive.zip'

const GRAALVM = 'graalvm-ce-java11-21.1.0';

// Helper to execute a command in a given directory and return the output.
const run = (cmd, cwd) => child_process.execSync(cmd, { shell: true, cwd }).toString()

Expand Down Expand Up @@ -126,124 +128,124 @@ const toSign = [
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.jartool.jmod',
jarContent: ['bin/jarsigner', 'bin/jar'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.jdeps.jmod',
jarContent: ['bin/javap', 'bin/jdeprscan', 'bin/jdeps'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.jstatd.jmod',
jarContent: ['bin/jstatd'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.pack.jmod',
jarContent: ['bin/unpack200', 'bin/pack200'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.hotspot.agent.jmod',
jarContent: ['bin/jhsdb'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.jfr.jmod',
jarContent: ['bin/jfr'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.rmic.jmod',
jarContent: ['bin/rmic'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'java.rmi.jmod',
jarContent: ['bin/rmid', 'bin/rmiregistry'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'java.base.jmod',
jarContent: ['bin/java', 'bin/keytool', 'lib/jspawnhelper'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.jlink.jmod',
jarContent: ['bin/jmod', 'bin/jlink', 'bin/jimage'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.scripting.nashorn.shell.jmod',
jarContent: ['bin/jjs'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.jcmd.jmod',
jarContent: ['bin/jstack', 'bin/jcmd', 'bin/jps', 'bin/jmap', 'bin/jstat', 'bin/jinfo'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.jshell.jmod',
jarContent: ['bin/jshell'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.compiler.jmod',
jarContent: ['bin/javac', 'bin/serialver'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'java.scripting.jmod',
jarContent: ['bin/jrunscript'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.jdi.jmod',
jarContent: ['bin/jdb'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.javadoc.jmod',
jarContent: ['bin/javadoc'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.jconsole.jmod',
jarContent: ['bin/jconsole'],
},
{
jarDir:
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/jmods',
`enso/runtime/${GRAALVM}/Contents/Home/jmods`,
jarName: 'jdk.javadoc.jmod',
jarContent: ['bin/javadoc'],
},
]

// Extra files that need to be signed.
const extra = [
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/MacOS/libjli.dylib',
'enso/runtime/graalvm-ce-java11-21.0.0.2/Contents/Home/languages/llvm/native/bin/ld.lld',
`enso/runtime/${GRAALVM}/Contents/MacOS/libjli.dylib`,
`enso/runtime/${GRAALVM}/Contents/Home/languages/llvm/native/bin/ld.lld`,
]

exports.default = async function () {
Expand Down
7 changes: 4 additions & 3 deletions src/js/lib/project-manager/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ async function get_project_manager_url(): Promise<string> {
const config = await get_build_config()
const target_platform = config.target
console.log('webpack target ' + target_platform)
// Usually it is a good idea to synchronize this constant with `ENGINE_VERSION_FOR_NEW_PROJECTS` in
// src/rust/ide/src/ide/initializer.rs. See also https://github.com/enso-org/ide/issues/1359
const version = '0.2.11'
// This constant MUST be synchronized with `ENGINE` constant in src/js/lib/client/tasks/signArchives.js.
// Also it is usually a good idea to synchronize it with `ENGINE_VERSION_FOR_NEW_PROJECTS` in
// src/rust/ide/src/controller/project.rs. See also https://github.com/enso-org/ide/issues/1359
const version = '0.2.12'
let base_url: string = 'https://github.com/enso-org/'
base_url += 'enso/releases/download/'
base_url += `enso-${version}/enso-project-manager-${version}`
Expand Down
48 changes: 29 additions & 19 deletions src/rust/ide/lib/enso-protocol/src/language_server/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

use crate::prelude::*;

use crate::language_server::MockClient;
use crate::language_server::API;
use crate::language_server::MockClient;
use crate::language_server::types::ContentRoot;
use crate::language_server::types::ContentRootType;

use uuid::Uuid;
use utils::fail::FallibleResult;
Expand Down Expand Up @@ -39,30 +41,41 @@ pub struct Connection {
/// LS client that has already initialized protocol.
#[derivative(Debug="ignore")]
pub client:Box<dyn API>,
/// Content roots obtained during initialization. Guaranteed to be non-empty.
content_roots:Vec<Uuid>,
/// The Project content root, being an only obligatory content root received.
project_root:ContentRoot,
/// Content roots obtained during initialization other than the `project_root`].
content_roots:Vec<ContentRoot>,
}

impl Connection {
/// Takes a client, generates ID for it and initializes the protocol.
pub async fn new(client:impl API + 'static, client_id:Uuid) -> FallibleResult<Self> {
let client = Box::new(client);
let init_response = client.init_protocol_connection(&client_id).await;
let init_response = init_response.map_err(|e| FailedToInitializeProtocol(e.into()))?;
let content_roots = init_response.content_roots;
if content_roots.is_empty() {
Err(MissingContentRoots.into())
} else {
Ok(Connection {client_id,client,content_roots})
}
let client = Box::new(client);
let init_response = client.init_protocol_connection(&client_id).await;
let init_response = init_response.map_err(|e| FailedToInitializeProtocol(e.into()))?;
let mut content_roots = init_response.content_roots;
let project_root = Self::extract_project_root(&mut content_roots)?;
farmaazon marked this conversation as resolved.
Show resolved Hide resolved
Ok(Connection {client_id,client,project_root,content_roots})
}

fn extract_project_root(content_roots:&mut Vec<ContentRoot>) -> FallibleResult<ContentRoot> {
use ContentRootType::*;
let opt_index = content_roots.iter().position(|cr| cr.content_root_type == Project);
let index = opt_index.ok_or(MissingContentRoots)?;
Ok(content_roots.drain(index..=index).next().unwrap())
}

/// Creates a connection which wraps a mock client.
pub fn new_mock(client:MockClient) -> Connection {
Connection {
client : Box::new(client),
client_id : default(),
content_roots : vec![default()],
project_root : ContentRoot {
farmaazon marked this conversation as resolved.
Show resolved Hide resolved
id : default(),
content_root_type : ContentRootType::Project,
name : "Project".to_owned()
},
content_roots : default(),
}
}

Expand All @@ -72,14 +85,11 @@ impl Connection {
}

/// Returns the first content root.
pub fn content_root(&self) -> Uuid {
// Guaranteed to be non-empty thanks to check in `new` and implementation of `new_mock`.
self.content_roots[0]
}
pub fn project_root(&self) -> &ContentRoot { &self.project_root }

/// Lists all content roots for this LS connection.
pub fn content_roots(&self) -> &Vec<Uuid> {
&self.content_roots
pub fn content_roots(&self) -> impl Iterator<Item=&ContentRoot> {
std::iter::once(&self.project_root).chain(self.content_roots.iter())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::language_server::SuggestionsDatabaseEntry;
#[serde(rename_all="camelCase")]
pub struct InitProtocolConnection {
/// List of Root IDs.
pub content_roots:Vec<Uuid>,
pub content_roots:Vec<ContentRoot>,
}

/// Response of `file_read` method.
Expand Down
12 changes: 10 additions & 2 deletions src/rust/ide/lib/enso-protocol/src/language_server/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ fn test_file_requests() {
#[test]
fn test_protocol_connection() {
let init_protocol_connection_response = response::InitProtocolConnection {
content_roots: vec![uuid::Uuid::default()]
content_roots: vec![ContentRoot {
id : default(),
content_root_type : ContentRootType::Project,
name : "Project".to_owned()
}]
};
test_request(
|client| client.init_protocol_connection(&uuid::Uuid::default()),
Expand All @@ -270,7 +274,11 @@ fn test_protocol_connection() {
"clientId" : "00000000-0000-0000-0000-000000000000"
}),
json!({
"contentRoots" : ["00000000-0000-0000-0000-000000000000"]
"contentRoots" : [{
"id" : "00000000-0000-0000-0000-000000000000",
"type" : "Project",
"name" : "Project",
}]
}),
init_protocol_connection_response
);
Expand Down
33 changes: 33 additions & 0 deletions src/rust/ide/lib/enso-protocol/src/language_server/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,39 @@ impl FileSystemObject {



// =====================
// === Content Roots ===
// =====================

/// The type of the annotated content root.
#[derive(Clone,Copy,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)]
pub enum ContentRootType {
/// The project home.
Project,
/// System root `/` on unix systems, or drive root on Windows. In Windows’ case, there may be
/// multiple [`Root`] entries corresponding to the various drives.
Root,
/// The user’s home directory.
Home,
/// An Enso library location.
Library,
/// A content root that has been added by the IDE (unused for now).
Custom
}

/// A content root represents a location on a real file-system that has been virtualized for use in
/// the Cloud.
#[allow(missing_docs)]
#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)]
#[serde(rename_all="camelCase")]
pub struct ContentRoot {
pub id:Uuid,
#[serde(rename="type")]
pub content_root_type : ContentRootType,
pub name : String,
}



// ================
// === Position ===
Expand Down
34 changes: 20 additions & 14 deletions src/rust/ide/src/controller/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ pub const COMPILING_STDLIB_LABEL:&str = "Compiling standard library. It can take

/// The requirements for Engine's version, in format understandable by
/// [`semver::VersionReq::parse`].
pub const ENGINE_VERSION_SUPPORTED : &str = "^0.2.11";
pub const ENGINE_VERSION_SUPPORTED : &str = "^0.2.12";

/// The Engine version used in projects created in IDE.
// Usually it is a good idea to synchronize this version with the bundled Engine version in
// src/js/lib/project-manager/src/build.ts. See also https://github.com/enso-org/ide/issues/1359
pub const ENGINE_VERSION_FOR_NEW_PROJECTS : &str = "0.2.11";
pub const ENGINE_VERSION_FOR_NEW_PROJECTS : &str = "0.2.12";

/// The name of the module initially opened in the project view.
///
Expand Down Expand Up @@ -57,6 +57,23 @@ pub fn main_method_ptr(project_name:impl Str, module_path:&model::module::Path)
}



// =================
// === Utilities ===
// =================

/// Returns the path to package.yaml file for given project.
pub fn package_yaml_path(project_name:&str) -> String {
match platform::current() {
Some(Platform::Linux) |
Some(Platform::MacOS) => format!("~/enso/projects/{}/package.yaml",project_name),
Some(Platform::Windows) =>
format!("%userprofile%\\enso\\projects\\{}\\package.yaml",project_name),
_ => format!("<path-to-enso-projects>/{}/package.yaml",project_name)
}
}


// ==============
// === Handle ===
// ==============
Expand Down Expand Up @@ -177,22 +194,11 @@ impl Project {
let version = self.model.engine_version();
if !requirements.matches(version) {
let message = format!("Unsupported Engine version. Please update engine_version in {} \
to {}.",self.package_yaml_path(),ENGINE_VERSION_FOR_NEW_PROJECTS);
to {}.",package_yaml_path(&self.model.name()),ENGINE_VERSION_FOR_NEW_PROJECTS);
self.status_notifications.publish_event(message);
}
Ok(())
}

fn package_yaml_path(&self) -> String {
let project_name = self.model.name();
match platform::current() {
Some(Platform::Linux) |
Some(Platform::MacOS) => format!("~/enso/projects/{}/package.yaml",project_name),
Some(Platform::Windows) =>
format!("%userprofile%\\enso\\projects\\{}\\package.yaml",project_name),
_ => format!("<path-to-enso-projects>/{}/package.yaml",project_name)
}
}
}


Expand Down
Loading