Skip to content

Commit afc3471

Browse files
authored
Fix launch configs not being found when using symlinked binary path (#1837)
* Fix launch configs not being found when using symlinked binary path Launch configs generated prior to #1831 used the symlinked `debug` folder in the program path. Launch confgs are now generated with the bin-path returned from a `swift build --show-bin-path` invocation, which is the full path and not the symlink. In order to find the right launch config when doing a `> Swift: Run` or `> Swift: Debug` we need to follow any symlinks in the launch config path to check for equivalence with the real path when searching for the launch config to use. * Fixup paths in SwiftSnippet tests
1 parent 20b4baf commit afc3471

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/debugger/launch.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// SPDX-License-Identifier: Apache-2.0
1212
//
1313
//===----------------------------------------------------------------------===//
14+
import { realpathSync } from "fs";
1415
import * as path from "path";
1516
import { isDeepStrictEqual } from "util";
1617
import * as vscode from "vscode";
@@ -130,7 +131,6 @@ export async function getLaunchConfiguration(
130131
: vscode.workspace.getConfiguration("launch", folderCtx.workspaceFolder);
131132
const launchConfigs = wsLaunchSection.get<vscode.DebugConfiguration[]>("configurations") || [];
132133
const { folder } = getFolderAndNameSuffix(folderCtx);
133-
134134
try {
135135
// Use dynamic path resolution with --show-bin-path
136136
const binPath = await folderCtx.toolchain.buildFlags.getBuildBinaryPath(
@@ -141,10 +141,21 @@ export async function getLaunchConfiguration(
141141
);
142142
const targetPath = path.join(binPath, target);
143143

144+
const expandPath = (p: string) =>
145+
p.replace(
146+
`$\{workspaceFolder:${folderCtx.workspaceFolder.name}}`,
147+
folderCtx.folder.fsPath
148+
);
149+
144150
// Users could be on different platforms with different path annotations,
145151
// so normalize before we compare.
146152
const launchConfig = launchConfigs.find(
147-
config => path.normalize(config.program) === path.normalize(targetPath)
153+
config =>
154+
// Old launch configs had program paths that looked like ${workspaceFolder:test}/defaultPackage/.build/debug,
155+
// where `debug` was a symlink to the host-triple-folder/debug. Because targetPath is determined by `--show-bin-path`
156+
// in `getBuildBinaryPath` we need to follow this symlink to get the real path if we want to compare them.
157+
path.normalize(realpathSync(expandPath(config.program))) ===
158+
path.normalize(targetPath)
148159
);
149160
return launchConfig;
150161
} catch (error) {

test/integration-tests/SwiftSnippet.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414
import { expect } from "chai";
15+
import { realpathSync } from "fs";
1516
import * as vscode from "vscode";
1617

1718
import { WorkspaceContext } from "@src/WorkspaceContext";
@@ -78,9 +79,12 @@ tag("large").suite("SwiftSnippet Test Suite", function () {
7879
expect(succeeded).to.be.true;
7980
const session = await sessionPromise;
8081
expect(vscode.Uri.file(session.configuration.program).fsPath).to.equal(
81-
testAssetUri(
82-
"defaultPackage/.build/debug/hello" + (process.platform === "win32" ? ".exe" : "")
83-
).fsPath
82+
realpathSync(
83+
testAssetUri(
84+
"defaultPackage/.build/debug/hello" +
85+
(process.platform === "win32" ? ".exe" : "")
86+
).fsPath
87+
)
8488
);
8589
expect(session.configuration).to.have.property("noDebug", true);
8690
});
@@ -115,9 +119,12 @@ tag("large").suite("SwiftSnippet Test Suite", function () {
115119

116120
const session = await sessionPromise;
117121
expect(vscode.Uri.file(session.configuration.program).fsPath).to.equal(
118-
testAssetUri(
119-
"defaultPackage/.build/debug/hello" + (process.platform === "win32" ? ".exe" : "")
120-
).fsPath
122+
realpathSync(
123+
testAssetUri(
124+
"defaultPackage/.build/debug/hello" +
125+
(process.platform === "win32" ? ".exe" : "")
126+
).fsPath
127+
)
121128
);
122129
expect(session.configuration).to.not.have.property("noDebug");
123130
});

0 commit comments

Comments
 (0)