Skip to content

Commit

Permalink
Enable check for warnings when runMain
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Aug 18, 2024
1 parent 2cc7ef5 commit 7df58ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
10 changes: 10 additions & 0 deletions engine/common/src/main/java/org/enso/common/ContextFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* @param options additional options for the Context
* @param executionEnvironment optional name of the execution environment to use during execution
* @param warningsLimit maximal number of warnings reported to the user
* @param checkForWarnings name of method to check for warnings
*/
public final class ContextFactory {
private String projectRoot;
Expand All @@ -47,6 +48,7 @@ public final class ContextFactory {
private boolean useGlobalIrCacheLocation = true;
private boolean enableAutoParallelism;
private String executionEnvironment;
private String checkForWarnings;
private int warningsLimit = 100;
private java.util.Map<String, String> options = java.util.Collections.emptyMap();

Expand Down Expand Up @@ -141,6 +143,11 @@ public ContextFactory options(Map<String, String> options) {
return this;
}

public ContextFactory checkForWarnings(String fqnOfMethod) {
this.checkForWarnings = fqnOfMethod;
return this;
}

public Context build() {
if (executionEnvironment != null) {
options.put("enso.ExecutionEnvironment", executionEnvironment);
Expand Down Expand Up @@ -169,6 +176,9 @@ public Context build() {
.out(out)
.err(err)
.in(in);
if (checkForWarnings != null) {
builder.option("enso-debug-server.fn", checkForWarnings);
}
if (messageTransport != null) {
builder.serverTransport(messageTransport);
}
Expand Down
26 changes: 20 additions & 6 deletions engine/runner/src/main/java/org/enso/runner/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,25 @@ private void handleRun(
}
var projectMode = fileAndProject._1();
var file = fileAndProject._2();
var mainFile = file;
if (projectMode) {
var result = PackageManager$.MODULE$.Default().loadPackage(file);
if (result.isSuccess()) {
var s = (scala.util.Success) result;
@SuppressWarnings("unchecked")
var pkg = (org.enso.pkg.Package<java.io.File>) s.get();

mainFile = pkg.mainFile();
if (!mainFile.exists()) {
println("Main file does not exist.");
throw exitFail();
}
} else {
println(((scala.util.Failure) result).exception().getMessage());
throw exitFail();
}
}

var projectRoot = fileAndProject._3();
var options = new HashMap<String, String>();

Expand All @@ -699,6 +718,7 @@ private void handleRun(
.enableIrCaches(enableIrCaches)
.disablePrivateCheck(disablePrivateCheck)
.strictErrors(true)
.checkForWarnings(mainFile.getName().replace(".enso", "") + ".main")
.enableAutoParallelism(enableAutoParallelism)
.enableStaticAnalysis(enableStaticAnalysis)
.executionEnvironment(executionEnvironment != null ? executionEnvironment : "live")
Expand All @@ -724,12 +744,6 @@ private void handleRun(
var s = (scala.util.Success) result;
@SuppressWarnings("unchecked")
var pkg = (org.enso.pkg.Package<java.io.File>) s.get();
var main = pkg.mainFile();
if (!main.exists()) {
println("Main file does not exist.");
context.context().close();
throw exitFail();
}
var mainModuleName = pkg.moduleNameForFile(pkg.mainFile()).toString();
runPackage(context, mainModuleName, file, additionalArgs);
} else {
Expand Down

0 comments on commit 7df58ef

Please sign in to comment.