Skip to content

Commit 18d2483

Browse files
only return a single path from findBinaryInPath
1 parent b376487 commit 18d2483

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

src/toolchain/toolchain.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class SwiftToolchain {
134134
folder?: vscode.Uri,
135135
logger?: SwiftLogger
136136
): Promise<SwiftToolchain> {
137-
const swiftBinaryPath = await this.findSwiftBinaryInPath(logger);
137+
const swiftBinaryPath = await this.findSwiftBinaryInPath();
138138
const { toolchainPath, toolchainManager } = await this.getToolchainPath(
139139
swiftBinaryPath,
140140
extensionRoot,
@@ -519,21 +519,14 @@ export class SwiftToolchain {
519519
logger.debug(this.diagnostics);
520520
}
521521

522-
private static async findSwiftBinaryInPath(logger?: SwiftLogger): Promise<string> {
522+
private static async findSwiftBinaryInPath(): Promise<string> {
523523
if (configuration.path !== "") {
524524
const pathFromSettings = expandFilePathTilde(configuration.path);
525525
const windowsExeSuffix = process.platform === "win32" ? ".exe" : "";
526526

527527
return path.join(pathFromSettings, `swift${windowsExeSuffix}`);
528528
}
529-
const foundPaths = await findBinaryInPath("swift");
530-
if (foundPaths.length > 1) {
531-
logger?.warn(
532-
`Found multiple swift binaries in PATH: ${foundPaths.map(p => `"${p}"`).join(", ")}`
533-
);
534-
logger?.warn(`Using swift binary path "${foundPaths[0]}"`);
535-
}
536-
return foundPaths[0];
529+
return await findBinaryInPath("swift");
537530
}
538531

539532
private static async isXcrunShim(binary: string): Promise<boolean> {

src/utilities/shell.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@ import { execFile } from "./utilities";
1717
* Asks the shell where a binary is located. Will always return at least one path unless
1818
* resolution fails completely, in which case the function will throw.
1919
*
20-
* Note: On Windows this has the potential to return multiple paths.
21-
*
2220
* @param binaryName The name of the binary to search for.
2321
* @returns An array of paths found on the system.
2422
*/
25-
export async function findBinaryInPath(binaryName: string): Promise<string[]> {
23+
export async function findBinaryInPath(binaryName: string): Promise<string> {
2624
try {
2725
switch (process.platform) {
2826
case "darwin": {
2927
const { stdout } = await execFile("which", [binaryName]);
30-
return [stdout.trimEnd()];
28+
return stdout.trimEnd();
3129
}
3230
case "win32": {
3331
const command = "where.exe";
@@ -37,7 +35,7 @@ export async function findBinaryInPath(binaryName: string): Promise<string[]> {
3735
if (foundPaths.length === 0) {
3836
throw createParsingError({ command, args, stdout, stderr });
3937
}
40-
return foundPaths;
38+
return foundPaths[0];
4139
}
4240
default: {
4341
// use `type` to find the binary on Linux. Run inside /bin/sh to ensure
@@ -52,7 +50,7 @@ export async function findBinaryInPath(binaryName: string): Promise<string[]> {
5250
if (!binaryNameMatch) {
5351
throw createParsingError({ command, args, stdout, stderr });
5452
}
55-
return [binaryNameMatch[1]];
53+
return binaryNameMatch[1];
5654
}
5755
}
5856
} catch (error) {

test/unit-tests/utilities/shell.test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ suite("Shell Unit Test Suite", () => {
4040
stderr: "",
4141
});
4242

43-
await expect(findBinaryInPath("node")).to.eventually.deep.equal([
44-
"/usr/local/bin/node",
45-
]);
43+
await expect(findBinaryInPath("node")).to.eventually.equalPath(
44+
"/usr/local/bin/node"
45+
);
4646
});
4747

4848
test("throws for a non-existent binary", async () => {
@@ -67,9 +67,9 @@ suite("Shell Unit Test Suite", () => {
6767
stderr: "",
6868
});
6969

70-
await expect(findBinaryInPath("node")).to.eventually.deep.equal([
71-
"/usr/local/bin/node",
72-
]);
70+
await expect(findBinaryInPath("node")).to.eventually.equalPath(
71+
"/usr/local/bin/node"
72+
);
7373
});
7474

7575
test("throws for a non-existent binary", async () => {
@@ -92,10 +92,9 @@ suite("Shell Unit Test Suite", () => {
9292
stderr: "",
9393
});
9494

95-
await expect(findBinaryInPath("node")).to.eventually.deep.equal([
96-
"/usr/local/bin/node",
97-
"/usr/local/other/bin/node",
98-
]);
95+
await expect(findBinaryInPath("node")).to.eventually.equalPath(
96+
"/usr/local/bin/node"
97+
);
9998
});
10099

101100
test("throws for a non-existent binary", async () => {

0 commit comments

Comments
 (0)