Skip to content

Commit

Permalink
Merge pull request #70 from Cyberbeni/sourcekit-fix
Browse files Browse the repository at this point in the history
Export LINUX_SOURCEKIT_LIB_PATH on Linux
  • Loading branch information
Cyberbeni authored Oct 31, 2020
2 parents 03cddd9 + e4eac54 commit a676167
Show file tree
Hide file tree
Showing 8 changed files with 614 additions and 523 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ jobs:
uses: ./
with:
url: https://github.com/realm/SwiftLint
version: '^0'
version: '*'
use-cache: ${{ runner.os == 'Linux' }}
- name: Test tools in path
run: |
which swiftformat
which xcbeautify
which swiftlint
echo "class Test {}" > ./test.swift
swiftformat --lint ./test.swift
xcbeautify --version
swiftlint lint ./test.swift
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions lib/environment_fixer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions src/environment_fixer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as core from '@actions/core'
import * as fs from 'fs'
import * as os from 'os'
import { env } from 'process'

export class SwiftEnvironmentFixer {
static async fixSourceKitPath () {
const envVar = 'LINUX_SOURCEKIT_LIB_PATH'
if(env[envVar] != undefined) {
return
}
await core.group(`Setting ${envVar}`, async () => {
let exported = false
const libName = 'libsourcekitdInProc.so'
const possiblePaths = ['/usr/share/swift/usr/lib', '/usr/lib']
for (const path of possiblePaths) {
if (fs.existsSync(`${path}/${libName}`)) {
core.info(`Setting to: '${path}'`)
core.exportVariable(envVar, path)
exported = true
break
}
}
if (!exported) {
core.warning(`Failed to find suitable path for ${envVar}`)
}
})
}

static async fixAll() {
if (os.platform() == 'linux') {
await this.fixSourceKitPath()
}
}
}
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from '@actions/core'
import { SwiftEnvironmentFixer } from './environment_fixer'
import { SwiftToolInstaller } from './installer'

// Inputs
Expand All @@ -12,6 +13,7 @@ const useCache: boolean = core.getInput('use-cache') == 'true'

async function main(): Promise<void> {
await SwiftToolInstaller.install(url, branch, version, useCache)
await SwiftEnvironmentFixer.fixAll()
}

main().catch(error => { core.setFailed(error.message); })
main().catch(error => { core.setFailed(error.message) })
4 changes: 4 additions & 0 deletions types/environment_fixer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare class SwiftEnvironmentFixer {
static fixSourceKitPath(): Promise<void>;
static fixAll(): Promise<void>;
}
Loading

0 comments on commit a676167

Please sign in to comment.