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

More info when critical failure occurs #11092

Merged
merged 12 commits into from
Sep 23, 2024
8 changes: 8 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,14 @@ lazy val `syntax-rust-definition` = project
publish / skip := false,
autoScalaLibrary := false,
crossPaths := false,
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion
),
moduleDependencies := {
Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion
)
},
javaModuleName := "org.enso.syntax",
Compile / sourceGenerators += generateParserJavaSources,
Compile / resourceGenerators += generateRustParserLib,
Expand Down
10 changes: 10 additions & 0 deletions build/build/src/engine/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ impl RunContext {
graalpy.install_if_missing(&self.cache).await?;
ide_ci::programs::graalpy::GraalPy.require_present().await?;

if self.config.test_java_generated_from_rust {
// Ensure all runtime dependencies are resolved and exported so that they can be
// appended to classpath
let sbt = engine::sbt::Context {
repo_root: self.paths.repo_root.path.clone(),
system_properties: default(),
};
sbt.call_arg("syntax-rust-definition/Runtime/managedClasspath").await?;
}

prepare_simple_library_server.await??;
Ok(())
}
Expand Down
25 changes: 22 additions & 3 deletions build/build/src/rust/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use ide_ci::programs::Cargo;
use ide_ci::programs::Java;
use ide_ci::programs::Javac;


use std::fs;
use std::path::Path;

const GENERATOR_CRATE_NAME: &str = "enso-parser-generate-java";
const GENERATOR_BIN_NAME: &str = GENERATOR_CRATE_NAME;
const TEST_GENERATOR_BIN_NAME: &str = "java-tests";
const GENERATED_CODE_NAMESPACE: [&str; 3] = ["org", "enso", "syntax2"];
const GENERATED_TEST_CLASS: &str = "GeneratedFormatTests";
const JAVA_EXTENSION: &str = ".java";
const JAVA_EXTENSION: &str = "java";

pub fn cargo_run_generator_cmd(repo_root: &Path, binary_name: &str) -> Result<Command> {
let mut ret = Cargo.cmd()?;
Expand Down Expand Up @@ -50,6 +51,20 @@ pub async fn generate_java(repo_root: &RepoRoot) -> Result {
pub async fn run_self_tests(repo_root: &RepoRoot) -> Result {
let base = &repo_root.target.generated_java;
let lib = &repo_root.lib.rust.parser.generate_java.java;
let external_dependencies_file = lib
.ancestors()
.nth(2)
.unwrap()
.join("target")
.join("streams")
.join("runtime")
.join("managedClasspath")
.join("_global")
.join("streams")
.join("export");

let dependencies_from_string = fs::read_to_string(&external_dependencies_file)?;
let dependencies_from_string = dependencies_from_string.trim_ascii_end();
let package = repo_root.target.generated_java.join_iter(GENERATED_CODE_NAMESPACE);
let test = package.join(GENERATED_TEST_CLASS).with_extension(JAVA_EXTENSION);
let test_class =
Expand All @@ -63,7 +78,11 @@ pub async fn run_self_tests(repo_root: &RepoRoot) -> Result {

Javac
.cmd()?
.apply(&javac::Classpath::new([lib.as_path(), base.as_path()]))
.apply(&javac::Classpath::new([
lib.as_path(),
base.as_path(),
Path::new(dependencies_from_string),
]))
.apply(&javac::Options::Directory(base.into()))
.arg(&test)
.run_ok()
Expand Down
6 changes: 5 additions & 1 deletion build/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,11 @@ pub async fn main_internal(config: Option<Config>) -> Result {
java_gen::Command::Build => generate_job.await,
java_gen::Command::Test => {
generate_job.await?;
let backend_context = ctx.prepare_backend_context(default()).await?;
let config = enso_build::engine::BuildConfigurationFlags {
test_java_generated_from_rust: true,
..Default::default()
};
let backend_context = ctx.prepare_backend_context(config).await?;
backend_context.prepare_build_env().await?;
enso_build::rust::parser::run_self_tests(&repo_root).await
}
Expand Down
2 changes: 2 additions & 0 deletions lib/rust/parser/generate-java/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module org.enso.syntax {
requires org.slf4j;

exports org.enso.syntax2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.io.File;
import java.net.URISyntaxException;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import org.slf4j.LoggerFactory;

public final class Parser implements AutoCloseable {
private static void initializeLibraries() {
Expand Down Expand Up @@ -131,7 +133,13 @@ public Tree parse(CharSequence input) {
var metadata = getMetadata(state);
serializedTree.order(ByteOrder.LITTLE_ENDIAN);
var message = new Message(serializedTree, input, base, metadata);
return Tree.deserialize(message);
try {
return Tree.deserialize(message);
} catch (BufferUnderflowException | IllegalArgumentException e) {
LoggerFactory.getLogger(this.getClass())
.error("Unrecoverable parser failure for: {}", input, e);
Copy link
Member

Choose a reason for hiding this comment

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

This code is calling error(Object,Throwable) method. What's its behavior in Enso?

When running runtime-integration-tests

Will it print the message as well as exception to the (CI) console?

When running in enso CLI mode

Will it print the message as well as exception to the (CI) console? Will it do something different?

When running in Enso IDE mode

What will appear in console and what will appear in associated log file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This PR changes nothing when it comes to how log messages are consumed, this is calling a plain slf4j api. The actual printing is dependent on the implementation/configuration, as you know.

If you don't like the format/output of the logger in CLI or tests then please create a ticket for that. IDE works as expected.

Copy link
Member

Choose a reason for hiding this comment

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

If you don't like the format/output of the logger in CLI or tests then please create a ticket for that. IDE works as expected.

Which is?

What will appear in console and what will appear in associated log file?

Will you, please, answer my question?

throw e;
}
}

public static String getWarningMessage(Warning warning) {
Expand Down
Loading