From 420581bc75610ae2a394df7f2a6f457200a2c715 Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Mahunt Date: Sun, 15 Sep 2024 21:41:58 +0530 Subject: [PATCH] fix: fixed older Swift toolchain installations on Windows (#307) * chore: test older Swift release installation support on Windows * fix: fixed older Swift toolchain installations * chore: added more logs --- .github/workflows/main.yml | 3 +++ src/installer/windows/installation/approach.ts | 15 ++++++++++----- src/installer/windows/installation/index.ts | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a537595..48ce664 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -162,6 +162,9 @@ jobs: - os: macos-13 swift: 'latest' development: false + - os: windows-latest + swift: '5.9' + development: false - os: ubuntu-latest swift: '5.3.0' development: false diff --git a/src/installer/windows/installation/approach.ts b/src/installer/windows/installation/approach.ts index 21a0763..a143b14 100644 --- a/src/installer/windows/installation/approach.ts +++ b/src/installer/windows/installation/approach.ts @@ -13,13 +13,21 @@ export async function firstDirectoryLayout(root?: string) { await fs.access(toolchain) const winsdk = path.join('Developer', 'SDKs', 'Windows.sdk') const sdkroot = path.join(devdir, 'Platforms', 'Windows.platform', winsdk) - const runtime = path.join(location, 'Swift', 'runtime-development') + const runtimeRoot = path.join(location, 'Swift') + const runtime = path.join(runtimeRoot, 'runtime-development') + const devPath = path.join(systemDrive, 'Program Files', 'Swift') + try { + await fs.access(devPath) + await fs.cp(devPath, runtimeRoot, {recursive: true}) + } catch (error) { + core.debug(`Runtime check failed with "${error}"`) + } core.debug('First installation approach succeeded') return new Installation(location, toolchain, sdkroot, runtime, devdir) } export async function secondDirectoryLayout(root?: string) { - core.debug('Trying secong installation approach') + core.debug('Trying second installation approach') const systemDrive = root ?? process.env.SystemDrive ?? 'C:' const location = path.join(systemDrive, 'Program Files', 'Swift') const toolchainName = '0.0.0+Asserts' @@ -28,9 +36,6 @@ export async function secondDirectoryLayout(root?: string) { const winsdk = path.join('Developer', 'SDKs', 'Windows.sdk') const sdkroot = path.join(location, 'Platforms', 'Windows.platform', winsdk) const runtime = path.join(location, 'Runtimes', '0.0.0') - const runtimeRoot = path.join(location, 'Swift') - const devPath = path.join(systemDrive, 'Program Files', 'Swift') - await fs.cp(devPath, runtimeRoot, {recursive: true}) core.debug('Second installation approach succeeded') return new Installation(location, toolchain, sdkroot, runtime) } diff --git a/src/installer/windows/installation/index.ts b/src/installer/windows/installation/index.ts index 5df8810..d7eb9d5 100644 --- a/src/installer/windows/installation/index.ts +++ b/src/installer/windows/installation/index.ts @@ -36,7 +36,7 @@ Installation.get = async (install?: string) => { core.debug(`Development directory at "${installation.devdir}"`) return installation } catch (error) { - core.debug(`Failed ${counter} time(s)`) + core.debug(`Failed ${counter} time(s), recent error "${error}"`) } } return undefined