Skip to content

Commit

Permalink
Fix Benchmark processor when run from a root directory with different…
Browse files Browse the repository at this point in the history
… name than "enso" (#8382)

This PR fixes commands like `std-benchmarks/benchOnly Startup` for users that have `enso` clonned in multiple directories with different names.
  • Loading branch information
Akirathan authored Nov 24, 2023
1 parent 8516ed5 commit 5244003
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
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

0 comments on commit 5244003

Please sign in to comment.