3
3
import Foundation
4
4
import PackageDescription
5
5
6
- // MARK: - Parse build arguments
7
-
8
- func hasEnvironmentVariable( _ name: String ) -> Bool {
9
- return ProcessInfo . processInfo. environment [ name] != nil
10
- }
11
-
12
- /// Use the `NonDarwinLogger` even if `os_log` can be imported.
13
- ///
14
- /// This is useful when running tests using `swift test` because xctest will not display the output from `os_log` on the
15
- /// command line.
16
- let forceNonDarwinLogger = hasEnvironmentVariable ( " SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER " )
17
-
18
- // When building the toolchain on the CI, don't add the CI's runpath for the
19
- // final build before installing.
20
- let installAction = hasEnvironmentVariable ( " SOURCEKIT_LSP_CI_INSTALL " )
21
-
22
- /// Assume that all the package dependencies are checked out next to sourcekit-lsp and use that instead of fetching a
23
- /// remote dependency.
24
- let useLocalDependencies = hasEnvironmentVariable ( " SWIFTCI_USE_LOCAL_DEPS " )
25
-
26
- // MARK: - Compute custom build settings
27
-
28
- var sourcekitLSPLinkSettings : [ LinkerSetting ] = [ ]
29
- if installAction {
30
- sourcekitLSPLinkSettings += [ . unsafeFlags( [ " -no-toolchain-stdlib-rpath " ] , . when( platforms: [ . linux, . android] ) ) ]
31
- }
32
-
33
- var lspLoggingSwiftSettings : [ SwiftSetting ] = [ ]
34
- if forceNonDarwinLogger {
35
- lspLoggingSwiftSettings += [ . define( " SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER " ) ]
36
- }
37
-
38
- // MARK: - Build the package
39
-
40
6
let package = Package (
41
7
name: " SourceKitLSP " ,
42
8
platforms: [ . macOS( " 12.0 " ) ] ,
@@ -45,9 +11,7 @@ let package = Package(
45
11
. library( name: " _SourceKitLSP " , targets: [ " SourceKitLSP " ] ) ,
46
12
. library( name: " LSPBindings " , targets: [ " LanguageServerProtocol " , " LanguageServerProtocolJSONRPC " ] ) ,
47
13
] ,
48
- dependencies: [
49
- // See 'Dependencies' below.
50
- ] ,
14
+ dependencies: dependencies,
51
15
targets: [
52
16
// Formatting style:
53
17
// - One section for each target and its test target
@@ -311,31 +275,70 @@ let package = Package(
311
275
]
312
276
)
313
277
314
- // MARK: Dependencies
278
+ // MARK: - Parse build arguments
279
+
280
+ func hasEnvironmentVariable( _ name: String ) -> Bool {
281
+ return ProcessInfo . processInfo. environment [ name] != nil
282
+ }
283
+
284
+ /// Use the `NonDarwinLogger` even if `os_log` can be imported.
285
+ ///
286
+ /// This is useful when running tests using `swift test` because xctest will not display the output from `os_log` on the
287
+ /// command line.
288
+ var forceNonDarwinLogger : Bool { hasEnvironmentVariable ( " SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER " ) }
289
+
290
+ // When building the toolchain on the CI, don't add the CI's runpath for the
291
+ // final build before installing.
292
+ var installAction : Bool { hasEnvironmentVariable ( " SOURCEKIT_LSP_CI_INSTALL " ) }
293
+
294
+ /// Assume that all the package dependencies are checked out next to sourcekit-lsp and use that instead of fetching a
295
+ /// remote dependency.
296
+ var useLocalDependencies : Bool { hasEnvironmentVariable ( " SWIFTCI_USE_LOCAL_DEPS " ) }
297
+
298
+ // MARK: - Dependencies
315
299
316
300
// When building with the swift build-script, use local dependencies whose contents are controlled
317
301
// by the external environment. This allows sourcekit-lsp to take advantage of the automation used
318
302
// for building the swift toolchain, such as `update-checkout`, or cross-repo PR tests.
319
303
320
- if useLocalDependencies {
321
- package . dependencies += [
322
- . package ( path: " ../indexstore-db " ) ,
323
- . package ( name: " swift-package-manager " , path: " ../swiftpm " ) ,
324
- . package ( path: " ../swift-tools-support-core " ) ,
325
- . package ( path: " ../swift-argument-parser " ) ,
326
- . package ( path: " ../swift-syntax " ) ,
327
- . package ( path: " ../swift-crypto " ) ,
328
- ]
329
- } else {
330
- let relatedDependenciesBranch = " main "
331
-
332
- // Building standalone.
333
- package . dependencies += [
334
- . package ( url: " https://github.com/apple/indexstore-db.git " , branch: relatedDependenciesBranch) ,
335
- . package ( url: " https://github.com/apple/swift-package-manager.git " , branch: relatedDependenciesBranch) ,
336
- . package ( url: " https://github.com/apple/swift-tools-support-core.git " , branch: relatedDependenciesBranch) ,
337
- . package ( url: " https://github.com/apple/swift-argument-parser.git " , from: " 1.2.2 " ) ,
338
- . package ( url: " https://github.com/apple/swift-syntax.git " , branch: relatedDependenciesBranch) ,
339
- . package ( url: " https://github.com/apple/swift-crypto.git " , from: " 3.0.0 " ) ,
340
- ]
304
+ var dependencies : [ Package . Dependency ] {
305
+ if useLocalDependencies {
306
+ return [
307
+ . package ( path: " ../indexstore-db " ) ,
308
+ . package ( name: " swift-package-manager " , path: " ../swiftpm " ) ,
309
+ . package ( path: " ../swift-tools-support-core " ) ,
310
+ . package ( path: " ../swift-argument-parser " ) ,
311
+ . package ( path: " ../swift-syntax " ) ,
312
+ . package ( path: " ../swift-crypto " ) ,
313
+ ]
314
+ } else {
315
+ let relatedDependenciesBranch = " main "
316
+
317
+ return [
318
+ . package ( url: " https://github.com/apple/indexstore-db.git " , branch: relatedDependenciesBranch) ,
319
+ . package ( url: " https://github.com/apple/swift-package-manager.git " , branch: relatedDependenciesBranch) ,
320
+ . package ( url: " https://github.com/apple/swift-tools-support-core.git " , branch: relatedDependenciesBranch) ,
321
+ . package ( url: " https://github.com/apple/swift-argument-parser.git " , from: " 1.2.2 " ) ,
322
+ . package ( url: " https://github.com/apple/swift-syntax.git " , branch: relatedDependenciesBranch) ,
323
+ . package ( url: " https://github.com/apple/swift-crypto.git " , from: " 3.0.0 " ) ,
324
+ ]
325
+ }
326
+ }
327
+
328
+ // MARK: - Compute custom build settings
329
+
330
+ var sourcekitLSPLinkSettings : [ LinkerSetting ] {
331
+ if installAction {
332
+ return [ . unsafeFlags( [ " -no-toolchain-stdlib-rpath " ] , . when( platforms: [ . linux, . android] ) ) ]
333
+ } else {
334
+ return [ ]
335
+ }
336
+ }
337
+
338
+ var lspLoggingSwiftSettings : [ SwiftSetting ] {
339
+ if forceNonDarwinLogger {
340
+ return [ . define( " SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER " ) ]
341
+ } else {
342
+ return [ ]
343
+ }
341
344
}
0 commit comments