Skip to content

Commit 9c3d5f3

Browse files
make sure that objdump is available before calling it
1 parent 18d2483 commit 9c3d5f3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/toolchain/toolchain.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,25 @@ export class SwiftToolchain {
529529
return await findBinaryInPath("swift");
530530
}
531531

532-
private static async isXcrunShim(binary: string): Promise<boolean> {
532+
private static async isXcrunShim(binary: string, logger?: SwiftLogger): Promise<boolean> {
533533
if (!(await fileExists(binary))) {
534534
return false;
535535
}
536-
const objdumpOutput = await execFile("/usr/bin/objdump", ["-h", binary]);
537-
return objdumpOutput.stdout.includes("__xcrun_shim");
536+
// Make sure that either Xcode or CommandLineTools are installed before attempting to run objdump.
537+
try {
538+
await execFile("xcode-select", ["-p"]);
539+
} catch (error) {
540+
logger?.error(error);
541+
return false;
542+
}
543+
// Use objdump to determine if this is an xcrun shim.
544+
try {
545+
const objdumpOutput = await execFile("/usr/bin/objdump", ["-h", binary]);
546+
return objdumpOutput.stdout.includes("__xcrun_shim");
547+
} catch (error) {
548+
logger?.error(error);
549+
return false;
550+
}
538551
}
539552

540553
/**
@@ -553,7 +566,7 @@ export class SwiftToolchain {
553566
// swift may be a symbolic link
554567
const realSwiftBinaryPath = await fs.realpath(swiftBinaryPath);
555568
// Check if the swift binary is managed by xcrun
556-
if (process.platform === "darwin" && (await this.isXcrunShim(realSwiftBinaryPath))) {
569+
if (await this.isXcrunShim(realSwiftBinaryPath, logger)) {
557570
const { stdout } = await execFile("xcrun", ["--find", "swift"], {
558571
env: configuration.swiftEnvironmentVariables,
559572
});

0 commit comments

Comments
 (0)