Skip to content

Commit

Permalink
More info when critical failure occurs (#11092)
Browse files Browse the repository at this point in the history
* More info when critical failure occurs

Log problematic module to help with debugging critical failure.

* One more exception

* s/System.err/Logger.error/

* maybe append slf4j deps

* fix what looks like a long standing typo

`GeneratedFormatTests.java` not `GeneratedFormatTests..java`

* one more typo

* Fix directory where to look for classpath

`./run java-gen test --skip-version-check` now works. At least locally.

* Local is fine, CI is not. More temporary debugging...

* Ensure project's managedClasspath is exported

Running java tests requires us knowing all additional dependencies as
they have to be added to the classpath manually. That can only be
ensured by invoking the right sbt target.

* Move sbt call after graalvm setup

* removing CI debugging

* Apply suggestions from code review

Co-authored-by: Kaz Wesley <[email protected]>

---------

Co-authored-by: Kaz Wesley <[email protected]>
  • Loading branch information
hubertp and kazcw authored Sep 23, 2024
1 parent c4ace00 commit 7c41329
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
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 @@ -806,7 +806,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;
}
10 changes: 9 additions & 1 deletion lib/rust/parser/generate-java/java/org/enso/syntax2/Parser.java
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 @@ -141,7 +143,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);
throw e;
}
}

public static String getWarningMessage(Warning warning) {
Expand Down

0 comments on commit 7c41329

Please sign in to comment.