mirror of
https://github.com/enso-org/enso.git
synced 2024-12-22 23:31:42 +03:00
Fix Benchmark processor when run from a root directory with different 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.
This commit is contained in:
parent
8516ed5cbb
commit
5244003be8
@ -2,6 +2,7 @@ package org.enso.benchmarks;
|
||||
|
||||
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 {
|
||||
@ -21,26 +22,30 @@ public class Utils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
@ -5,6 +5,7 @@ import java.io.File;
|
||||
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;
|
||||
@ -20,6 +21,7 @@ import javax.tools.Diagnostic.Kind;
|
||||
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;
|
||||
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user