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

Set go DebugConfguration working directory for tests #6748

Merged
merged 2 commits into from
Sep 12, 2024
Merged
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 @@ -409,6 +409,8 @@ private static File findExecutable(Label target, List<File> outputs) {
private static final Pattern TEST_SRCDIR = Pattern.compile("TEST_SRCDIR=([^ ]+)");
// Matches RUNFILES_<NAME>=<value>
private static final Pattern RUNFILES_VAR = Pattern.compile("RUNFILES_([A-Z_]+)=([^ ]+)");
// Matches TEST_TARGET=//<package_path>:<target>
private static final Pattern TEST_TARGET = Pattern.compile("TEST_TARGET=//([^:]*):([^\\s]+)");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested it both with bzlmod and without it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have bzlmod in some form in our company's repo which I have also tested this on, however I'm not familiar with what it does and what implications it can bring. So, no, and I don't really know how to test this extensively.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the main difference between bzlmod and non-bzlmod projects is the introduction of canonical repository names. Also some rulesets behave differently depending on whether bzlmod is enabled or not (however user-visible differences are usually a bug).

I was asking because whenever there's a target pattern with a single @ or without any @s it is possible that under bzlmod it got turned into a @@ (we - JetBrains - have run into such problems in out Hirschgarten repo).

But if it works with bzlmod it's much more probable that it will work without it than the other way round :)

So I'll merge it if it works for you!

// Matches a space-delimited arg list. Supports wrapping arg in single quotes.
private static final Pattern ARGS = Pattern.compile("([^\']\\S*|\'.+?\')\\s*");

Expand Down Expand Up @@ -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(
Expand All @@ -452,6 +453,21 @@ private static ExecutableInfo parseScriptPathFile(
workspaceName,
args.get(1))
.toFile();

Matcher testTarget = TEST_TARGET.matcher(text);
if (testTarget.find()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that thanks to this if this shouldn't break anything

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 {
Expand Down
Loading