Commit 1f8ce112 authored by Ivan Mazhukin's avatar Ivan Mazhukin

prefer active eepm root for docker tests

parent a1dbed62
...@@ -79,3 +79,5 @@ Important settings: ...@@ -79,3 +79,5 @@ Important settings:
- `epmDockerTest.parallelJobs`: pass `-j N` when greater than `1`. - `epmDockerTest.parallelJobs`: pass `-j N` when greater than `1`.
- `epmDockerTest.localEpmRoot`: local eepm tree for outside-container `./bin/epm play` commands. - `epmDockerTest.localEpmRoot`: local eepm tree for outside-container `./bin/epm play` commands.
- `epmDockerTest.eepmDir`, `epmDockerTest.eepmSource`, `epmDockerTest.remoteHost`, `epmDockerTest.remoteUser`, `epmDockerTest.builderUser`, `epmDockerTest.builderPath`, `epmDockerTest.logRoot`: map to the same script options. - `epmDockerTest.eepmDir`, `epmDockerTest.eepmSource`, `epmDockerTest.remoteHost`, `epmDockerTest.remoteUser`, `epmDockerTest.builderUser`, `epmDockerTest.builderPath`, `epmDockerTest.logRoot`: map to the same script options.
For Docker test commands, auto-detection prefers the nearest parent directory of the active editor that contains both `bin/epm` and `epm-docker-test.sh`. That directory is used as the command working directory, and its `epm-docker-test.sh` is used as the runner.
...@@ -483,23 +483,29 @@ function resolvePaths() { ...@@ -483,23 +483,29 @@ function resolvePaths() {
const config = getConfig(); const config = getConfig();
const workspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath; const workspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
const configuredScript = config.get('scriptPath', '').trim(); const configuredScript = config.get('scriptPath', '').trim();
const script = configuredScript ? resolveWorkspacePath(configuredScript) : findScript(workspaceFolder); const configuredCwd = config.get('workingDirectory', '').trim();
const detectedEepmRoot = configuredCwd ? undefined : findEepmRootFromActiveEditor();
const script = configuredScript
? resolveWorkspacePath(configuredScript)
: findScript(workspaceFolder, detectedEepmRoot);
if (!script || !fs.existsSync(script)) { if (!script || !fs.existsSync(script)) {
vscode.window.showErrorMessage('Could not find epm-docker-test.sh. Set epmDockerTest.scriptPath.'); vscode.window.showErrorMessage('Could not find epm-docker-test.sh. Set epmDockerTest.scriptPath.');
return undefined; return undefined;
} }
const configuredCwd = config.get('workingDirectory', '').trim();
const cwd = configuredCwd const cwd = configuredCwd
? resolveWorkspacePath(configuredCwd) ? resolveWorkspacePath(configuredCwd)
: workspaceFolder || path.dirname(script); : detectedEepmRoot || workspaceFolder || path.dirname(script);
return { script, cwd }; return { script, cwd };
} }
function findScript(workspaceFolder) { function findScript(workspaceFolder, detectedEepmRoot) {
const candidates = []; const candidates = [];
if (detectedEepmRoot) {
candidates.push(path.join(detectedEepmRoot, 'epm-docker-test.sh'));
}
if (workspaceFolder) { if (workspaceFolder) {
candidates.push( candidates.push(
path.join(workspaceFolder, 'epm-docker-test.sh'), path.join(workspaceFolder, 'epm-docker-test.sh'),
...@@ -510,6 +516,32 @@ function findScript(workspaceFolder) { ...@@ -510,6 +516,32 @@ function findScript(workspaceFolder) {
return candidates.find((candidate) => fs.existsSync(candidate)); return candidates.find((candidate) => fs.existsSync(candidate));
} }
function findEepmRootFromActiveEditor() {
const editor = vscode.window.activeTextEditor;
const filePath = editor?.document?.uri?.scheme === 'file' ? editor.document.uri.fsPath : undefined;
if (!filePath) {
return undefined;
}
let current;
try {
current = fs.statSync(filePath).isDirectory() ? filePath : path.dirname(filePath);
} catch {
return undefined;
}
while (current && current !== path.dirname(current)) {
if (
fs.existsSync(path.join(current, 'bin', 'epm')) &&
fs.existsSync(path.join(current, 'epm-docker-test.sh'))
) {
return current;
}
current = path.dirname(current);
}
return undefined;
}
function inferAppFromActiveEditor(eepmRoot) { function inferAppFromActiveEditor(eepmRoot) {
const editor = vscode.window.activeTextEditor; const editor = vscode.window.activeTextEditor;
const filePath = editor?.document?.uri?.scheme === 'file' ? editor.document.uri.fsPath : undefined; const filePath = editor?.document?.uri?.scheme === 'file' ? editor.document.uri.fsPath : undefined;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment