Skip to content

Commit

Permalink
fix: fixed older Swift toolchain installations on Windows (#307)
Browse files Browse the repository at this point in the history
* chore: test older Swift release installation support on Windows

* fix: fixed older Swift toolchain installations

* chore: added more logs
  • Loading branch information
soumyamahunt authored Sep 15, 2024
1 parent 6973bb8 commit 420581b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions src/installer/windows/installation/approach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion src/installer/windows/installation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 420581b

Please sign in to comment.