Skip to content

Commit 630ee50

Browse files
authored
initial support for registry publishing (#6101)
motivation: support publishing to registry changes: * split SwiftPackageRegistryTool to multiple files as its growing large * add "swift package-registry publish" command * implement client side for registry requirments API * add test
1 parent 8c8a3c4 commit 630ee50

File tree

7 files changed

+758
-329
lines changed

7 files changed

+758
-329
lines changed

Sources/CoreCommands/Options.swift

Lines changed: 82 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@
1212

1313
import ArgumentParser
1414

15+
import struct Foundation.URL
16+
1517
import enum PackageFingerprint.FingerprintCheckingMode
18+
1619
import enum PackageModel.BuildConfiguration
1720
import struct PackageModel.BuildFlags
1821
import struct PackageModel.EnabledSanitizers
22+
import struct PackageModel.PackageIdentity
1923
import enum PackageModel.Sanitizer
2024

2125
import struct SPMBuildCore.BuildSystemProvider
2226

2327
import struct TSCBasic.AbsolutePath
28+
import var TSCBasic.localFileSystem
2429
import struct TSCBasic.StringError
30+
2531
import struct TSCUtility.Triple
26-
import var TSCBasic.localFileSystem
32+
import struct TSCUtility.Version
2733

2834
public struct GlobalOptions: ParsableArguments {
2935
public init() {}
@@ -53,20 +59,36 @@ public struct GlobalOptions: ParsableArguments {
5359
public struct LocationOptions: ParsableArguments {
5460
public init() {}
5561

56-
@Option(name: .customLong("package-path"), help: "Specify the package path to operate on (default current directory). This changes the working directory before any other operation", completion: .directory)
62+
@Option(
63+
name: .customLong("package-path"),
64+
help: "Specify the package path to operate on (default current directory). This changes the working directory before any other operation",
65+
completion: .directory
66+
)
5767
public var packageDirectory: AbsolutePath?
5868

5969
@Option(name: .customLong("cache-path"), help: "Specify the shared cache directory path", completion: .directory)
6070
public var cacheDirectory: AbsolutePath?
6171

62-
@Option(name: .customLong("config-path"), help: "Specify the shared configuration directory path", completion: .directory)
72+
@Option(
73+
name: .customLong("config-path"),
74+
help: "Specify the shared configuration directory path",
75+
completion: .directory
76+
)
6377
public var configurationDirectory: AbsolutePath?
6478

65-
@Option(name: .customLong("security-path"), help: "Specify the shared security directory path", completion: .directory)
79+
@Option(
80+
name: .customLong("security-path"),
81+
help: "Specify the shared security directory path",
82+
completion: .directory
83+
)
6684
public var securityDirectory: AbsolutePath?
6785

6886
/// The custom .build directory, if provided.
69-
@Option(name: .customLong("scratch-path"), help: "Specify a custom scratch directory path (default .build)", completion: .directory)
87+
@Option(
88+
name: .customLong("scratch-path"),
89+
help: "Specify a custom scratch directory path (default .build)",
90+
completion: .directory
91+
)
7092
var _scratchDirectory: AbsolutePath?
7193

7294
@Option(name: .customLong("build-path"), help: .hidden)
@@ -90,19 +112,24 @@ public struct LocationOptions: ParsableArguments {
90112
@Option(
91113
name: .customLong("pkg-config-path"),
92114
help:
93-
"""
94-
Specify alternative path to search for pkg-config `.pc` files. Use the option multiple times to
95-
specify more than one path.
96-
""",
97-
completion: .directory)
115+
"""
116+
Specify alternative path to search for pkg-config `.pc` files. Use the option multiple times to
117+
specify more than one path.
118+
""",
119+
completion: .directory
120+
)
98121
public var pkgConfigDirectories: [AbsolutePath] = []
99122
}
100123

101124
public struct CachingOptions: ParsableArguments {
102125
public init() {}
103126

104127
/// Disables package caching.
105-
@Flag(name: .customLong("dependency-cache"), inversion: .prefixedEnableDisable, help: "Use a shared cache when fetching dependencies")
128+
@Flag(
129+
name: .customLong("dependency-cache"),
130+
inversion: .prefixedEnableDisable,
131+
help: "Use a shared cache when fetching dependencies"
132+
)
106133
public var useDependenciesCache: Bool = true
107134

108135
/// Disables manifest caching.
@@ -114,7 +141,10 @@ public struct CachingOptions: ParsableArguments {
114141
public var cacheBuildManifest: Bool = true
115142

116143
/// Disables manifest caching.
117-
@Option(name: .customLong("manifest-cache"), help: "Caching mode of Package.swift manifests (shared: shared cache, local: package's build directory, none: disabled")
144+
@Option(
145+
name: .customLong("manifest-cache"),
146+
help: "Caching mode of Package.swift manifests (shared: shared cache, local: package's build directory, none: disabled"
147+
)
118148
public var manifestCachingMode: ManifestCachingMode = .shared
119149

120150
public enum ManifestCachingMode: String, ExpressibleByArgument {
@@ -167,7 +197,8 @@ public struct SecurityOptions: ParsableArguments {
167197
@Option(
168198
name: .customLong("netrc-file"),
169199
help: "Specify the netrc file path",
170-
completion: .file())
200+
completion: .file()
201+
)
171202
public var netrcFilePath: AbsolutePath?
172203

173204
/// Whether to use keychain for authenticating with remote servers
@@ -197,15 +228,19 @@ public struct ResolverOptions: ParsableArguments {
197228
public var shouldEnableResolverPrefetching: Bool = true
198229

199230
/// Use Package.resolved file for resolving dependencies.
200-
@Flag(name: [.long, .customLong("disable-automatic-resolution"), .customLong("only-use-versions-from-resolved-file")], help: "Only use versions from the Package.resolved file and fail resolution if it is out-of-date")
231+
@Flag(
232+
name: [.long, .customLong("disable-automatic-resolution"), .customLong("only-use-versions-from-resolved-file")],
233+
help: "Only use versions from the Package.resolved file and fail resolution if it is out-of-date"
234+
)
201235
public var forceResolvedVersions: Bool = false
202236

203237
/// Skip updating dependencies from their remote during a resolution.
204238
@Flag(name: .customLong("skip-update"), help: "Skip updating dependencies from their remote during a resolution")
205239
public var skipDependencyUpdate: Bool = false
206240

207241
@Flag(help: "Define automatic transformation of source control based dependencies to registry based ones")
208-
public var sourceControlToRegistryDependencyTransformation: SourceControlToRegistryDependencyTransformation = .swizzle
242+
public var sourceControlToRegistryDependencyTransformation: SourceControlToRegistryDependencyTransformation =
243+
.swizzle
209244

210245
public enum SourceControlToRegistryDependencyTransformation: EnumerableFlag {
211246
case disabled
@@ -267,7 +302,8 @@ public struct BuildOptions: ParsableArguments {
267302
parsing: .unconditionalSingleValue,
268303
help: ArgumentHelp(
269304
"Pass flag through to the Xcode build system invocations",
270-
visibility: .hidden))
305+
visibility: .hidden
306+
))
271307
public var xcbuildFlags: [String] = []
272308

273309
@Option(name: .customLong("Xmanifest", withSingleDash: true),
@@ -300,20 +336,23 @@ public struct BuildOptions: ParsableArguments {
300336

301337
/// The architectures to compile for.
302338
@Option(
303-
name: .customLong("arch"),
304-
help: ArgumentHelp(
305-
"Build the package for the these architectures",
306-
visibility: .hidden))
339+
name: .customLong("arch"),
340+
help: ArgumentHelp(
341+
"Build the package for the these architectures",
342+
visibility: .hidden
343+
)
344+
)
307345
public var architectures: [String] = []
308346

309347
/// Path to the compilation destination describing JSON file.
310348
@Option(name: .customLong("experimental-destination-selector"), help: .hidden)
311349
public var crossCompilationDestinationSelector: String?
312350

313351
/// Which compile-time sanitizers should be enabled.
314-
@Option(name: .customLong("sanitize"),
315-
help: "Turn on runtime checks for erroneous behavior, possible values: \(Sanitizer.formattedValues)",
316-
transform: { try Sanitizer(argument: $0) })
352+
@Option(
353+
name: .customLong("sanitize"),
354+
help: "Turn on runtime checks for erroneous behavior, possible values: \(Sanitizer.formattedValues)"
355+
)
317356
public var sanitizers: [Sanitizer] = []
318357

319358
public var enabledSanitizers: EnabledSanitizers {
@@ -395,7 +434,8 @@ public struct LinkerOptions: ParsableArguments {
395434
@Flag(
396435
name: .customLong("dead-strip"),
397436
inversion: .prefixedEnableDisable,
398-
help: "Disable/enable dead code stripping by the linker")
437+
help: "Disable/enable dead code stripping by the linker"
438+
)
399439
public var linkerDeadStrip: Bool = true
400440

401441
/// If should link the Swift stdlib statically.
@@ -439,8 +479,8 @@ extension FingerprintCheckingMode: ExpressibleByArgument {
439479
}
440480
}
441481

442-
public extension Sanitizer {
443-
init(argument: String) throws {
482+
extension Sanitizer: ExpressibleByArgument {
483+
public init?(argument: String) {
444484
if let sanitizer = Sanitizer(rawValue: argument) {
445485
self = sanitizer
446486
return
@@ -451,13 +491,27 @@ public extension Sanitizer {
451491
return
452492
}
453493

454-
throw StringError("valid sanitizers: \(Sanitizer.formattedValues)")
494+
return nil
455495
}
456496

457497
/// All sanitizer options in a comma separated string
458498
fileprivate static var formattedValues: String {
459-
return Sanitizer.allCases.map(\.rawValue).joined(separator: ", ")
499+
Sanitizer.allCases.map(\.rawValue).joined(separator: ", ")
460500
}
461501
}
462502

463503
extension BuildSystemProvider.Kind: ExpressibleByArgument {}
504+
505+
extension Version: ExpressibleByArgument {}
506+
507+
extension PackageIdentity: ExpressibleByArgument {
508+
public init?(argument: String) {
509+
self = .plain(argument)
510+
}
511+
}
512+
513+
extension URL: ExpressibleByArgument {
514+
public init?(argument: String) {
515+
self.init(string: argument)
516+
}
517+
}

0 commit comments

Comments
 (0)