Skip to content

Commit 41e8872

Browse files
use xcode-select to determine the actual DEVELOPER_DIR value (#1433)
1 parent 4121e2e commit 41e8872

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

src/ui/ToolchainSelection.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function selectToolchainFolder() {
6363
if (!selected || selected.length !== 1) {
6464
return;
6565
}
66-
await setToolchainPath(selected[0].fsPath, "public");
66+
await setToolchainPath(selected[0].fsPath);
6767
}
6868

6969
/**
@@ -275,15 +275,25 @@ export async function showToolchainSelectionQuickPick(activeToolchain: SwiftTool
275275
}
276276
if (selected?.type === "toolchain") {
277277
// Select an Xcode to build with
278-
let developerDir: string | undefined;
279-
if (selected.category === "xcode") {
280-
developerDir = selected.xcodePath;
281-
} else if (xcodePaths.length === 1) {
282-
developerDir = xcodePaths[0];
283-
} else if (process.platform === "darwin" && xcodePaths.length > 1) {
284-
developerDir = await showDeveloperDirQuickPick(xcodePaths);
285-
if (!developerDir) {
286-
return;
278+
let developerDir: string | undefined = undefined;
279+
if (process.platform === "darwin") {
280+
let selectedXcodePath: string | undefined = undefined;
281+
if (selected.category === "xcode") {
282+
selectedXcodePath = selected.xcodePath;
283+
} else if (xcodePaths.length === 1) {
284+
selectedXcodePath = xcodePaths[0];
285+
} else if (xcodePaths.length > 1) {
286+
selectedXcodePath = await showDeveloperDirQuickPick(xcodePaths);
287+
if (!selectedXcodePath) {
288+
return;
289+
}
290+
}
291+
// Find the actual DEVELOPER_DIR based on the selected Xcode app
292+
if (selectedXcodePath) {
293+
developerDir = await SwiftToolchain.getXcodeDeveloperDir({
294+
...process.env,
295+
DEVELOPER_DIR: selectedXcodePath,
296+
});
287297
}
288298
}
289299
// Update the toolchain path
@@ -376,7 +386,7 @@ async function removeToolchainPath() {
376386
*/
377387
async function setToolchainPath(
378388
swiftFolderPath: string | undefined,
379-
developerDir: string | undefined
389+
developerDir?: string
380390
): Promise<boolean> {
381391
let target: vscode.ConfigurationTarget | undefined;
382392
const items: (vscode.QuickPickItem & {
@@ -410,17 +420,15 @@ async function setToolchainPath(
410420
}
411421
const swiftConfiguration = vscode.workspace.getConfiguration("swift");
412422
await swiftConfiguration.update("path", swiftFolderPath, target);
413-
if (developerDir) {
414-
const swiftEnv = configuration.swiftEnvironmentVariables;
415-
await swiftConfiguration.update(
416-
"swiftEnvironmentVariables",
417-
{
418-
...swiftEnv,
419-
DEVELOPER_DIR: developerDir,
420-
},
421-
target
422-
);
423-
}
423+
const swiftEnv = configuration.swiftEnvironmentVariables;
424+
await swiftConfiguration.update(
425+
"swiftEnvironmentVariables",
426+
{
427+
...swiftEnv,
428+
DEVELOPER_DIR: developerDir,
429+
},
430+
target
431+
);
424432
await checkAndRemoveWorkspaceSetting(target);
425433
return true;
426434
}

0 commit comments

Comments
 (0)