From 47517d0aa68a2453b0bdb2ca0bbb394f1868a696 Mon Sep 17 00:00:00 2001 From: muldrik <62476306+muldrik@users.noreply.github.com> Date: Thu, 12 Sep 2024 23:01:01 +0200 Subject: [PATCH] set go DebugConfguration test working directory to match the run's (#6748) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Andrzej Głuszak --- .../run/BlazeGoRunConfigurationRunner.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/golang/src/com/google/idea/blaze/golang/run/BlazeGoRunConfigurationRunner.java b/golang/src/com/google/idea/blaze/golang/run/BlazeGoRunConfigurationRunner.java index efad6c78165..2f1ce2cc197 100644 --- a/golang/src/com/google/idea/blaze/golang/run/BlazeGoRunConfigurationRunner.java +++ b/golang/src/com/google/idea/blaze/golang/run/BlazeGoRunConfigurationRunner.java @@ -409,6 +409,8 @@ private static File findExecutable(Label target, List outputs) { private static final Pattern TEST_SRCDIR = Pattern.compile("TEST_SRCDIR=([^ ]+)"); // Matches RUNFILES_= private static final Pattern RUNFILES_VAR = Pattern.compile("RUNFILES_([A-Z_]+)=([^ ]+)"); + // Matches TEST_TARGET=//: + private static final Pattern TEST_TARGET = Pattern.compile("TEST_TARGET=//([^:]*):([^\\s]+)"); // Matches a space-delimited arg list. Supports wrapping arg in single quotes. private static final Pattern ARGS = Pattern.compile("([^\']\\S*|\'.+?\')\\s*"); @@ -443,7 +445,6 @@ private static ExecutableInfo parseScriptPathFile( while (runfilesVars.find()) { envVars.put(String.format("RUNFILES_%s", runfilesVars.group(1)), runfilesVars.group(2)); } - workingDir = workspaceRoot.directory(); String workspaceName = execRoot.getName(); binary = Paths.get( @@ -452,6 +453,21 @@ private static ExecutableInfo parseScriptPathFile( workspaceName, args.get(1)) .toFile(); + + Matcher testTarget = TEST_TARGET.matcher(text); + if (testTarget.find()) { + String packagePath = testTarget.group(1); + workingDir = + Paths.get( + workspaceRoot.directory().getPath(), + testScrDir.group(1), + workspaceName, + packagePath) + .toFile(); + } else { + workingDir = workspaceRoot.directory(); + } + // Remove everything except the args. args = args.subList(2, args.size() - 1); } else {