Skip to content

Commit 87e2b89

Browse files
authored
Merge pull request #592 from ddunbar/swift-3-rebranch
Rebranch swift-package-manager for swift-3.0.
2 parents c9bdf38 + 12b6d5a commit 87e2b89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1660
-525
lines changed

Documentation/Usage.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [Build an Executable](#build-an-executable)
1212
* [Create a Package](#create-a-package)
1313
* [Distribute a Package](#distribute-a-package)
14+
* [Handling version-specific logic](#version-specific-logic)
1415
* [Reference](Reference.md)
1516
* [Resources](Resources.md)
1617

@@ -323,3 +324,76 @@ import Foundation
323324
## Distribute a Package
324325

325326
*Content to come.*
327+
328+
## Handling version-specific logic
329+
330+
The package manager is designed to support packages which work with a variety of
331+
Swift project versions, including both the language and the package manager version.
332+
333+
In most cases, if you want to support multiple Swift versions in a package you
334+
should do so by using the language-specific version checks available in the
335+
source code itself. However, in some circumstances this may become
336+
unmanageable; in particular, when the package manifest itself cannot be written
337+
to be Swift version agnostic (for example, because it optionally adopts new
338+
package manager features not present in older versions).
339+
340+
The package manager has support for a mechanism to allow Swift version-specific
341+
customizations for the both package manifest and the package versions which will
342+
be considered.
343+
344+
### Version-specific tag selection
345+
346+
The tags which define the versions of the package available for clients to use
347+
can _optionally_ be suffixed with a marker in the form of `@swift-3`. When the
348+
package manager is determining the available tags for a repository, _if_ a
349+
version-specific marker is available which matches the current tool version,
350+
then it will *only* consider the versions which have the version-specific
351+
marker. Conversely, version-specific tags will be ignored by any non-matching
352+
tool version.
353+
354+
For example, suppose the package `Foo` has the tags
355+
`[1.0.0, 1.2.0@swift-3, 1.3.0]`. If version 3.0 of the package manager is
356+
evaluating the available versions for this repository, it will only ever
357+
consider version `1.2.0`. However, version 4.0 would consider only `1.0.0` and
358+
`1.3.0`.
359+
360+
This feature is intended for use in the following scenarios:
361+
362+
1. A package wishes to maintain support for Swift 3.0 in older versions, but
363+
newer versions of the package require Swift 4.0 for the manifest to be
364+
readable. Since Swift 3.0 will not know to ignore those versions, it would
365+
fail when performing dependency resolution on the package if no action is
366+
taken. In this case, the author can re-tag the last versions which supported
367+
Swift 3.0 appropriately.
368+
369+
2. A package wishes to maintain dual support for Swift 3.0 and Swift 4.0 at the
370+
same version numbers, but this requires substantial differences in the
371+
code. In this case, the author can maintain parallel tag sets for both
372+
versions.
373+
374+
It is *not* expected the packages would ever use this feature unless absolutely
375+
necessary to support existing clients. In particular, packages *should not*
376+
adopt this syntax for tagging versions supporting the _latest GM_ Swift version.
377+
378+
The package manager supports looking for any of the following marked tags, in
379+
order of preference:
380+
381+
1. `MAJOR.MINOR.PATCH` (e.g., `[email protected]`)
382+
2. `MAJOR.MINOR` (e.g., `[email protected]`)
383+
3. `MAJOR` (e.g., `1.2.0@swift-3`)
384+
385+
### Version-specific manifest selection
386+
387+
The package manager will additionally look for a version-specific marked
388+
manifest version when loading the particular version of a package, by searching
389+
for a manifest in the form of `[email protected]`. The set of markers looked
390+
for is the same as for version-specific tag selection.
391+
392+
This feature is intended for use in cases where a package wishes to maintain
393+
compatibility with multiple Swift project versions, but requires a substantively
394+
different manifest file for this to be viable (e.g., due to changes in the
395+
manifest API).
396+
397+
It is *not* expected the packages would ever use this feature unless absolutely
398+
necessary to support existing clients. In particular, packages *should not*
399+
adopt this syntax for tagging versions supporting the _latest GM_ Swift version.

Package.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ let package = Package(
4343
Target(
4444
/** Abstractions for common operations, should migrate to Basic */
4545
name: "Utility",
46-
dependencies: ["POSIX", "Basic"]),
46+
dependencies: ["POSIX", "Basic", "PackageDescription"]),
47+
// FIXME: We should be kill the PackageDescription dependency above.
4748
Target(
4849
/** Source control operations */
4950
name: "SourceControl",
@@ -111,6 +112,9 @@ let package = Package(
111112

112113
// MARK: Additional Test Dependencies
113114

115+
Target(
116+
name: "BasicTests",
117+
dependencies: ["TestSupport"]),
114118
Target(
115119
name: "BuildTests",
116120
dependencies: ["Build", "TestSupport"]),

README.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Swift Package Manager Project
22

3-
> **PLEASE NOTE** The Swift Package Manager is still in early design and development — we are aiming to have it stable and ready for use with Swift 3 but currently all details are subject to change and many important features are yet to be implemented. Additionally, it is important to note that the Swift language syntax is not stable, so packages you write will (likely) break as Swift evolves.
3+
> **PLEASE NOTE** The Swift Package Manager is still in early design and development — we are aiming to have it stable and ready for use with Swift 3 but currently all details are subject to change and many important features are yet to be implemented. Additionally, it is important to note that the Swift language syntax is not stable, so packages you write will (likely) break as Swift evolves.
44
55
The Swift Package Manager is a tool for managing distribution of source code, aimed at making it easy to share your code and reuse others’ code. The tool directly addresses the challenges of compiling and linking Swift packages, managing dependencies, versioning, and supporting flexible distribution and collaboration models.
66

7-
We’ve designed the system to make it really easy to share packages on services like GitHub, but packages are also great for private personal development, sharing code within a team, or at any other granularity.
7+
We’ve designed the system to make it easy to share packages on services like GitHub, but packages are also great for private personal development, sharing code within a team, or at any other granularity.
88

99
---
1010

@@ -52,10 +52,6 @@ The package manager is bundled with the [**Trunk Development** Snapshots availab
5252

5353
export TOOLCHAINS=swift
5454

55-
* Xcode 7.2:
56-
57-
export PATH=/Library/Toolchains/swift-latest.xctoolchain/usr/bin:$PATH
58-
5955
* Linux:
6056

6157
export PATH=path/to/toolchain/usr/bin:$PATH
@@ -73,7 +69,7 @@ The following indicates you have not installed a snapshot successfully:
7369

7470
### Managing Swift Environments
7571

76-
The `TOOLCHAINS` environment variable on OS X can be used to control which `swift` is instantiated:
72+
The `TOOLCHAINS` environment variable on OS X can be used to control which `swift` is executed:
7773

7874
```sh
7975
$ xcrun --find swift
@@ -91,13 +87,13 @@ On OS X `/usr/bin/swift` is just a stub that forwards invocations to the active
9187

9288
To use a specific toolchain you can set `TOOLCHAINS` to the `CFBundleIdentifier` in an `.xctoolchain`’s Info.plist.
9389

94-
This feature requires Xcode 7.3.
90+
This feature requires Xcode 7.3 or later.
9591

9692
---
9793

9894
## Development
9995

100-
The Package Manager is itself a Swift Package and thus can be used to build itself. However we recommend instead one of the three following options:
96+
The Package Manager project is itself a Swift Package and can be used to build itself. If you are interested in contributing to the package manager, however, we recommend one of the three following options:
10197

10298
1. Using the [Swift project `build-script`](https://github.com/apple/swift/blob/master/README.md):
10399

@@ -120,19 +116,19 @@ Note that either of the latter two options may not be compatible with the `maste
120116

121117
### Choosing a Swift Version
122118

123-
The `SWIFT_EXEC` environment variable specifies the `swiftc` executable path used by `swift package`. If it is not set, SwiftPM will try to locate it:
119+
The `SWIFT_EXEC` environment variable specifies the `swiftc` executable path used by `swift package`. If it is not set, the package manager will try to locate it:
124120

125-
1. In `swift-package`'s parent directory.
126-
2. (on OS X) by calling `xcrun --find swiftc`
127-
3. in PATH
121+
1. In `swift-package`'s parent directory.
122+
2. On OS X, by calling `xcrun --find swiftc`.
123+
3. By searching the PATH.
128124

129125
---
130126

131127
## Documentation
132128

133-
For extensive documentation on using Swift Package Manager, creating packages, and more, see [Documentation/README](Documentation/README.md).
129+
For extensive documentation on using Swift Package Manager, creating packages, and more, see [Documentation](Documentation).
134130

135-
For additional documentation on developing Swift Package Manager, see [Documentation/Internals](Documentation/Internals).
131+
For additional documentation on developing the Swift Package Manager itself, see [Documentation/Internals](Documentation/Internals).
136132

137133
---
138134

Sources/Basic/Condition.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import Foundation
12+
13+
// FIXME: Temporary compatibility shims.
14+
#if !os(macOS)
15+
private typealias NSCondition = Foundation.Condition
16+
#endif
17+
18+
/// A simple condition wrapper.
19+
public struct Condition {
20+
private let _condition = NSCondition()
21+
22+
/// Create a new condition.
23+
public init() {}
24+
25+
/// Wait for the condition to become available.
26+
public func wait() {
27+
_condition.wait()
28+
}
29+
30+
/// Signal the availability of the condition (awake one thread waiting on
31+
/// the condition).
32+
public func signal() {
33+
_condition.signal()
34+
}
35+
36+
/// Broadcast the availability of the condition (awake all threads waiting
37+
/// on the condition).
38+
public func broadcast() {
39+
_condition.broadcast()
40+
}
41+
42+
/// A helper method to execute the given body while condition is locked.
43+
public func whileLocked<T>(_ body: () throws -> T) rethrows -> T {
44+
_condition.lock()
45+
defer { _condition.unlock() }
46+
return try body()
47+
}
48+
}

Sources/Basic/GraphAlgorithms.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public enum GraphError: Swift.Error {
3131
/// - Complexity: O(v + e) where (v, e) are the number of vertices and edges
3232
/// reachable from the input nodes via the relation.
3333
public func topologicalSort<T: Hashable>(
34-
_ nodes: [T], successors: @noescape (T) -> [T]) throws -> [T] {
34+
_ nodes: [T], successors: (T) -> [T]) throws -> [T] {
3535
// Implements a topological sort via recursion and reverse postorder DFS.
3636
func visit(_ node: T,
3737
_ stack: inout OrderedSet<T>, _ visited: inout Set<T>, _ result: inout [T],
38-
_ successors: @noescape (T) -> [T]) throws {
38+
_ successors: (T) -> [T]) throws {
3939
// Mark this node as visited -- we are done if it already was.
4040
if !visited.insert(node).inserted {
4141
return

Sources/Basic/Lock.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import Foundation
1212

1313
// FIXME: Temporary compatibility shims.
1414
#if !os(macOS)
15-
public typealias NSLock = Foundation.Lock
16-
public typealias NSCondition = Foundation.Condition
15+
private typealias NSLock = Foundation.Lock
1716
#endif
1817

1918
/// A simple lock wrapper.
@@ -25,18 +24,9 @@ public struct Lock {
2524
}
2625

2726
/// Execute the given block while holding the lock.
28-
public mutating func withLock<T> (_ body: @noescape () throws -> T) rethrows -> T {
27+
public mutating func withLock<T> (_ body: () throws -> T) rethrows -> T {
2928
_lock.lock()
3029
defer { _lock.unlock() }
3130
return try body()
3231
}
3332
}
34-
35-
public extension NSCondition {
36-
/// A helper method to execute the given body while condition is locked.
37-
public func whileLocked<T>(_ body: @noescape () throws -> T) rethrows -> T {
38-
lock()
39-
defer { unlock() }
40-
return try body()
41-
}
42-
}

Sources/Basic/OutputByteStream.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public class OutputByteStream: TextOutputStream {
192192
}
193193

194194
/// Write an arbitrary streamable to the buffer.
195-
public final func write(_ value: Streamable) {
195+
public final func write(_ value: TextOutputStreamable) {
196196
// Get a mutable reference.
197197
var stream: OutputByteStream = self
198198
value.write(to: &stream)
@@ -260,7 +260,7 @@ precedencegroup StreamingPrecedence {
260260
//
261261
// NOTE: It would be nice to use a protocol here and the adopt it by all the
262262
// things we can efficiently stream out. However, that doesn't work because we
263-
// ultimately need to provide a manual overload sometimes, e.g., Streamable, but
263+
// ultimately need to provide a manual overload sometimes, e.g., TextOutputStreamable, but
264264
// that will then cause ambiguous lookup versus the implementation just using
265265
// the defined protocol.
266266

@@ -318,7 +318,7 @@ public func <<<(stream: OutputByteStream, value: ByteStreamable) -> OutputByteSt
318318
}
319319

320320
@discardableResult
321-
public func <<<(stream: OutputByteStream, value: Streamable) -> OutputByteStream {
321+
public func <<<(stream: OutputByteStream, value: TextOutputStreamable) -> OutputByteStream {
322322
stream.write(value)
323323
return stream
324324
}

Sources/Basic/SwiftShims.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
public typealias TextOutputStreamable = Streamable

Sources/Basic/SynchronizedQueue.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,19 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import Foundation
12-
1311
/// This class can be used as a shared queue between multiple threads providing
1412
/// thread safe APIs.
1513
public final class SynchronizedQueue<Element> {
16-
1714
/// Storage for queued elements.
1815
private var storage: [Element]
1916

2017
/// Condition variable to block the thread trying dequeue and queue is empty.
21-
private var notEmptyCondition: NSCondition
18+
private var notEmptyCondition: Condition
2219

2320
/// Create a default instance of queue.
2421
public init() {
2522
storage = []
26-
notEmptyCondition = NSCondition()
23+
notEmptyCondition = Condition()
2724
}
2825

2926
/// Safely enqueue an element to end of the queue and signals a thread blocked on dequeue.

Sources/Basic/Thread.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ final public class Thread {
2020
private var thread: ThreadImpl!
2121

2222
/// Condition variable to support blocking other threads using join when this thread has not finished executing.
23-
private var finishedCondition: NSCondition
23+
private var finishedCondition: Condition
2424

2525
/// A boolean variable to track if this thread has finished executing its task.
2626
private var finished: Bool
2727

2828
/// Creates an instance of thread class with closure to be executed when start() is called.
2929
public init(task: @escaping () -> Void) {
3030
finished = false
31-
finishedCondition = NSCondition()
31+
finishedCondition = Condition()
3232

3333
// Wrap the task with condition notifying any other threads blocked due to this thread.
3434
// Capture self weakly to avoid reference cycle. In case Thread is deinited before the task

0 commit comments

Comments
 (0)