1414import Foundation
1515import PackageDescription
1616
17- // MARK: - Parse build arguments
18-
19- func hasEnvironmentVariable( _ name: String ) -> Bool {
20- return ProcessInfo . processInfo. environment [ name] != nil
21- }
22-
23- // When building the toolchain on the CI, don't add the CI's runpath for the
24- // final build before installing.
25- let installAction = hasEnvironmentVariable ( " SOURCEKIT_LSP_CI_INSTALL " )
26-
27-
28- // MARK: - Compute custom build settings
29-
30- var swiftformatLinkSettings : [ LinkerSetting ] = [ ]
31- if installAction {
32- swiftformatLinkSettings += [ . unsafeFlags( [ " -no-toolchain-stdlib-rpath " ] , . when( platforms: [ . linux, . android] ) ) ]
33- }
34-
3517let package = Package (
3618 name: " swift-format " ,
3719 platforms: [
@@ -56,9 +38,7 @@ let package = Package(
5638 targets: [ " Lint Source Code " ]
5739 ) ,
5840 ] ,
59- dependencies: [
60- // See the "Dependencies" section below.
61- ] ,
41+ dependencies: dependencies,
6242 targets: [
6343 . target(
6444 name: " _SwiftFormatInstructionCounter "
@@ -156,28 +136,47 @@ let package = Package(
156136 ]
157137)
158138
159- // MARK: Dependencies
139+ // MARK: - Parse build arguments
160140
161- if ProcessInfo . processInfo. environment [ " SWIFTCI_USE_LOCAL_DEPS " ] == nil {
162- // Building standalone.
163- package . dependencies += [
164- . package (
165- url: " https://github.com/apple/swift-argument-parser.git " ,
166- from: " 1.2.2 "
167- ) ,
168- . package (
169- url: " https://github.com/apple/swift-markdown.git " ,
170- from: " 0.2.0 "
171- ) ,
172- . package (
173- url: " https://github.com/apple/swift-syntax.git " ,
174- branch: " main "
175- ) ,
176- ]
177- } else {
178- package . dependencies += [
179- . package ( path: " ../swift-argument-parser " ) ,
180- . package ( path: " ../swift-markdown " ) ,
181- . package ( path: " ../swift-syntax " ) ,
182- ]
141+ func hasEnvironmentVariable( _ name: String ) -> Bool {
142+ return ProcessInfo . processInfo. environment [ name] != nil
143+ }
144+
145+ // When building the toolchain on the CI, don't add the CI's runpath for the
146+ // final build before installing.
147+ var installAction : Bool { hasEnvironmentVariable ( " SOURCEKIT_LSP_CI_INSTALL " ) }
148+
149+ /// Assume that all the package dependencies are checked out next to sourcekit-lsp and use that instead of fetching a
150+ /// remote dependency.
151+ var useLocalDependencies : Bool { hasEnvironmentVariable ( " SWIFTCI_USE_LOCAL_DEPS " ) }
152+
153+ // MARK: - Dependencies
154+
155+ var dependencies : [ Package . Dependency ] {
156+ if useLocalDependencies {
157+ return [
158+ . package ( path: " ../swift-argument-parser " ) ,
159+ . package ( path: " ../swift-markdown " ) ,
160+ . package ( path: " ../swift-syntax " ) ,
161+ ]
162+ } else {
163+ return [
164+ . package ( url: " https://github.com/apple/swift-argument-parser.git " , from: " 1.2.2 " ) ,
165+ . package ( url: " https://github.com/apple/swift-markdown.git " , from: " 0.2.0 " ) ,
166+ . package ( url: " https://github.com/apple/swift-syntax.git " , branch: " main " ) ,
167+ ]
168+ }
183169}
170+
171+
172+
173+ // MARK: - Compute custom build settings
174+
175+ var swiftformatLinkSettings : [ LinkerSetting ] {
176+ if installAction {
177+ return [ . unsafeFlags( [ " -no-toolchain-stdlib-rpath " ] , . when( platforms: [ . linux, . android] ) ) ]
178+ } else {
179+ return [ ]
180+ }
181+ }
182+
0 commit comments