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

Fix Benchmark processor when run from a root directory with different name than "enso" #8382

Merged
merged 1 commit into from
Nov 24, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.net.URISyntaxException;
import java.nio.file.Files;

/** Utility methods used by the benchmark classes from the generated code */
public class Utils {
Expand All @@ -21,26 +22,30 @@ public static File findLanguageHomeOverride() {
}

/**
* Returns the root directory of the Enso repository.
* Locates the root of the Enso repository. Heuristic: we just keep going up the directory tree
* until we are in a directory containing ".git" subdirectory. Note that we cannot use the "enso"
* name, as users are free to name their cloned directories however they like.
*
* @return Non-null file pointing to the root directory of the Enso repository.
*/
public static File findRepoRootDir() {
File ensoDir;
File rootDir = null;
try {
ensoDir = new File(Utils.class.getProtectionDomain().getCodeSource().getLocation().toURI());
rootDir = new File(Utils.class.getProtectionDomain().getCodeSource().getLocation().toURI());
} catch (URISyntaxException e) {
throw new IllegalStateException("Unrecheable: ensoDir not found", e);
throw new IllegalStateException("repository root directory not found: " + e.getMessage());
}
for (; ensoDir != null; ensoDir = ensoDir.getParentFile()) {
if (ensoDir.getName().equals("enso")) {
for (; rootDir != null; rootDir = rootDir.getParentFile()) {
// Check if rootDir contains ".git" subdirectory
if (Files.exists(rootDir.toPath().resolve(".git"))) {
break;
}
}
if (ensoDir == null || !ensoDir.exists() || !ensoDir.isDirectory() || !ensoDir.canRead()) {
throw new IllegalStateException("Unrecheable: ensoDir does not exist or is not readable");
if (rootDir == null || !rootDir.exists() || !rootDir.isDirectory() || !rootDir.canRead()) {
throw new IllegalStateException(
"Unreachable: repository root directory does not exist or is not readable");
}
return ensoDir;
return rootDir;
}

public static BenchSpec findSpecByName(BenchGroup group, String specName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
Expand All @@ -20,6 +21,7 @@
import org.enso.benchmarks.BenchGroup;
import org.enso.benchmarks.BenchSpec;
import org.enso.benchmarks.ModuleBenchSuite;
import org.enso.benchmarks.Utils;
import org.enso.polyglot.LanguageInfo;
import org.enso.polyglot.MethodNames.TopScope;
import org.enso.polyglot.RuntimeOptions;
Expand Down Expand Up @@ -71,28 +73,13 @@ public class BenchProcessor extends AbstractProcessor {
"import org.enso.benchmarks.Utils;");

public BenchProcessor() {
File currentDir = null;
try {
currentDir =
new File(
BenchProcessor.class.getProtectionDomain().getCodeSource().getLocation().toURI());
} catch (URISyntaxException e) {
failWithMessage("ensoDir not found: " + e.getMessage());
}
for (; currentDir != null; currentDir = currentDir.getParentFile()) {
if (currentDir.getName().equals("enso")) {
break;
}
}
if (currentDir == null) {
failWithMessage("Unreachable: Could not find Enso root directory");
}
ensoDir = currentDir;
ensoDir = Utils.findRepoRootDir();

// Note that ensoHomeOverride does not have to exist, only its parent directory
ensoHomeOverride = ensoDir.toPath().resolve("distribution").resolve("component").toFile();
}


@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
Expand Down
Loading