Skip to content

Commit 9ea61da

Browse files
committed
Order package manifest to start with the package declaration
Instead of starting with environment variable parsing, start with the actual package manifest, which is most likely the most interesting to most users. rdar://121441220
1 parent 6768cfc commit 9ea61da

File tree

1 file changed

+62
-59
lines changed

1 file changed

+62
-59
lines changed

Package.swift

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,6 @@
33
import Foundation
44
import PackageDescription
55

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-
406
let package = Package(
417
name: "SourceKitLSP",
428
platforms: [.macOS("12.0")],
@@ -45,9 +11,7 @@ let package = Package(
4511
.library(name: "_SourceKitLSP", targets: ["SourceKitLSP"]),
4612
.library(name: "LSPBindings", targets: ["LanguageServerProtocol", "LanguageServerProtocolJSONRPC"]),
4713
],
48-
dependencies: [
49-
// See 'Dependencies' below.
50-
],
14+
dependencies: dependencies,
5115
targets: [
5216
// Formatting style:
5317
// - One section for each target and its test target
@@ -311,31 +275,70 @@ let package = Package(
311275
]
312276
)
313277

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
315299

316300
// When building with the swift build-script, use local dependencies whose contents are controlled
317301
// by the external environment. This allows sourcekit-lsp to take advantage of the automation used
318302
// for building the swift toolchain, such as `update-checkout`, or cross-repo PR tests.
319303

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+
}
341344
}

0 commit comments

Comments
 (0)