Skip to content

Rebranch swift-package-manager for swift-3.0. #592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 46 commits into from
Aug 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8a539e8
Include the path in the a chdir error message.
abertelrud Aug 2, 2016
c72c0df
https://bugs.swift.org/browse/SR-2262 Generated Xcode projects should…
abertelrud Aug 3, 2016
0b2d148
[DependencyResolver] Factor out a type for constraint sets.
ddunbar Aug 3, 2016
abe8bae
[DependencyResolver] Add merge function between constraint sets.
ddunbar Aug 3, 2016
570b57d
[DependencyResolver] Add VersionAssignmentSet.merge.
ddunbar Aug 3, 2016
d7a08ac
[DependencyResolver] Add & adopt sequence conformances.
ddunbar Aug 3, 2016
bc9a19f
[DependencyResolver] Fix ordering of mock package versions.
ddunbar Aug 3, 2016
dc8c63d
[DependencyResolver] Provide constraints in resolve(), not init.
ddunbar Aug 3, 2016
cf2afca
[TestSupport] Move XCTAssertThrows into test support.
ddunbar Aug 3, 2016
5d34f13
Merge pull request #587 from abertelrud/xcodeproj-generation
abertelrud Aug 3, 2016
fb6975e
[DependencyResolver] Add initial cut at primary resolution loop.
ddunbar Aug 3, 2016
0af68d4
Remove workaround for SR-1457 now that it has been fixed.
abertelrud Aug 3, 2016
e8fdcf8
Simplify some of the option structs (this is not an essential change …
abertelrud Aug 3, 2016
a9b2c1d
[DependencyResolver] Add note on current client caching expectations.
ddunbar Aug 4, 2016
e422c14
[SourceControl] Add RepositoryHandle.open().
ddunbar Aug 4, 2016
aa7502c
[CheckoutManager] Ensure fetch targets are clear.
ddunbar Aug 4, 2016
fb38916
[DependencyResolver] Properly merge incoming constraints from resolve().
ddunbar Aug 4, 2016
a1970d9
[PackageLoading] Add support for loading manifests from any FileSystem.
ddunbar Aug 4, 2016
11ba855
Fix a comment.
ddunbar Aug 4, 2016
04f9449
[SourceControl] Add RepositorySpecifier: Hashable.
ddunbar Aug 4, 2016
d5813df
Make the bootstrap script conditionally enable code coverage in a gen…
abertelrud Aug 4, 2016
2164da1
Add a line of output for how the Xcode project is being generated, si…
abertelrud Aug 4, 2016
42309df
[Basic] Introduce a Condition wrapper.
ddunbar Aug 4, 2016
f54ecae
Revert "[Basic] Introduce a Condition wrapper."
jrose-apple Aug 5, 2016
8dda2e3
[Basic] Introduce a Condition wrapper.
ddunbar Aug 4, 2016
5d6cc90
[Docs] Tidy up README a bit.
ddunbar Aug 6, 2016
fde884e
[Swift] Update for @noescape deprecation.
ddunbar Aug 6, 2016
bf4d43b
[Commands] Factor out common helper for version information.
ddunbar Aug 6, 2016
0b45b6d
[PackageLoading] Split out function which loads a specific manifest f…
ddunbar Aug 7, 2016
8285334
[Build] Eliminate unused package version metadata feature.
ddunbar Aug 7, 2016
8e12654
[Utility] Sink version extraction into Utility.Git.
ddunbar Aug 7, 2016
389e49b
[Get] Use known version map to get appropriate tag.
ddunbar Aug 7, 2016
71faa6a
[DependencyResolver] Allow getDependencies to fail.
ddunbar Aug 7, 2016
53e7519
Renaming Streamable => TextOutputStreamable
Aug 8, 2016
53d25f3
Merge pull request #590 from apple/textoutputstreamable
tkremenek Aug 8, 2016
0aceda4
[Utility] Fix ordering expectation on versions.
ddunbar Aug 9, 2016
04a1505
[PackageLoading] Add support for version specific manifest loading.
ddunbar Aug 7, 2016
86c3018
[Utility] Add support for version-specific repository tags.
ddunbar Aug 7, 2016
cf9d6ba
[Documentation] Add section on version-specific features (SE-0135).
ddunbar Aug 7, 2016
f48e1cf
[Utility] Update for review feedback.
ddunbar Aug 7, 2016
d34d7f1
[Get] Update getRepositoryVersion for SE-0135.
ddunbar Aug 9, 2016
f865129
[PackageLoading] Ignore version-specific manifests.
ddunbar Aug 9, 2016
9b1f8a7
Merge branch 'SE-0135' of https://github.com/ddunbar/swift-package-ma…
ddunbar Aug 9, 2016
c508f63
[Commands] Add `package init --type=empty`.
ddunbar Aug 9, 2016
b15db80
Merge branch 'package-init-empty' of https://github.com/ddunbar/swift…
ddunbar Aug 9, 2016
12b6d5a
Adapt to Swift version on swift-3.0-branch.
ddunbar Aug 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Documentation/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [Build an Executable](#build-an-executable)
* [Create a Package](#create-a-package)
* [Distribute a Package](#distribute-a-package)
* [Handling version-specific logic](#version-specific-logic)
* [Reference](Reference.md)
* [Resources](Resources.md)

Expand Down Expand Up @@ -323,3 +324,76 @@ import Foundation
## Distribute a Package

*Content to come.*

## Handling version-specific logic

The package manager is designed to support packages which work with a variety of
Swift project versions, including both the language and the package manager version.

In most cases, if you want to support multiple Swift versions in a package you
should do so by using the language-specific version checks available in the
source code itself. However, in some circumstances this may become
unmanageable; in particular, when the package manifest itself cannot be written
to be Swift version agnostic (for example, because it optionally adopts new
package manager features not present in older versions).

The package manager has support for a mechanism to allow Swift version-specific
customizations for the both package manifest and the package versions which will
be considered.

### Version-specific tag selection

The tags which define the versions of the package available for clients to use
can _optionally_ be suffixed with a marker in the form of `@swift-3`. When the
package manager is determining the available tags for a repository, _if_ a
version-specific marker is available which matches the current tool version,
then it will *only* consider the versions which have the version-specific
marker. Conversely, version-specific tags will be ignored by any non-matching
tool version.

For example, suppose the package `Foo` has the tags
`[1.0.0, 1.2.0@swift-3, 1.3.0]`. If version 3.0 of the package manager is
evaluating the available versions for this repository, it will only ever
consider version `1.2.0`. However, version 4.0 would consider only `1.0.0` and
`1.3.0`.

This feature is intended for use in the following scenarios:

1. A package wishes to maintain support for Swift 3.0 in older versions, but
newer versions of the package require Swift 4.0 for the manifest to be
readable. Since Swift 3.0 will not know to ignore those versions, it would
fail when performing dependency resolution on the package if no action is
taken. In this case, the author can re-tag the last versions which supported
Swift 3.0 appropriately.

2. A package wishes to maintain dual support for Swift 3.0 and Swift 4.0 at the
same version numbers, but this requires substantial differences in the
code. In this case, the author can maintain parallel tag sets for both
versions.

It is *not* expected the packages would ever use this feature unless absolutely
necessary to support existing clients. In particular, packages *should not*
adopt this syntax for tagging versions supporting the _latest GM_ Swift version.

The package manager supports looking for any of the following marked tags, in
order of preference:

1. `MAJOR.MINOR.PATCH` (e.g., `[email protected]`)
2. `MAJOR.MINOR` (e.g., `[email protected]`)
3. `MAJOR` (e.g., `1.2.0@swift-3`)

### Version-specific manifest selection

The package manager will additionally look for a version-specific marked
manifest version when loading the particular version of a package, by searching
for a manifest in the form of `[email protected]`. The set of markers looked
for is the same as for version-specific tag selection.

This feature is intended for use in cases where a package wishes to maintain
compatibility with multiple Swift project versions, but requires a substantively
different manifest file for this to be viable (e.g., due to changes in the
manifest API).

It is *not* expected the packages would ever use this feature unless absolutely
necessary to support existing clients. In particular, packages *should not*
adopt this syntax for tagging versions supporting the _latest GM_ Swift version.
6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ let package = Package(
Target(
/** Abstractions for common operations, should migrate to Basic */
name: "Utility",
dependencies: ["POSIX", "Basic"]),
dependencies: ["POSIX", "Basic", "PackageDescription"]),
// FIXME: We should be kill the PackageDescription dependency above.
Target(
/** Source control operations */
name: "SourceControl",
Expand Down Expand Up @@ -111,6 +112,9 @@ let package = Package(

// MARK: Additional Test Dependencies

Target(
name: "BasicTests",
dependencies: ["TestSupport"]),
Target(
name: "BuildTests",
dependencies: ["Build", "TestSupport"]),
Expand Down
26 changes: 11 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Swift Package Manager Project

> **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.
> **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.

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.

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.
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.

---

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

export TOOLCHAINS=swift

* Xcode 7.2:

export PATH=/Library/Toolchains/swift-latest.xctoolchain/usr/bin:$PATH

* Linux:

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

### Managing Swift Environments

The `TOOLCHAINS` environment variable on OS X can be used to control which `swift` is instantiated:
The `TOOLCHAINS` environment variable on OS X can be used to control which `swift` is executed:

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

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

This feature requires Xcode 7.3.
This feature requires Xcode 7.3 or later.

---

## Development

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:
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:

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

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

### Choosing a Swift Version

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:
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:

1. In `swift-package`'s parent directory.
2. (on OS X) by calling `xcrun --find swiftc`
3. in PATH
1. In `swift-package`'s parent directory.
2. On OS X, by calling `xcrun --find swiftc`.
3. By searching the PATH.

---

## Documentation

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

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

---

Expand Down
48 changes: 48 additions & 0 deletions Sources/Basic/Condition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
This source file is part of the Swift.org open source project

Copyright 2016 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import Foundation

// FIXME: Temporary compatibility shims.
#if !os(macOS)
private typealias NSCondition = Foundation.Condition
#endif

/// A simple condition wrapper.
public struct Condition {
private let _condition = NSCondition()

/// Create a new condition.
public init() {}

/// Wait for the condition to become available.
public func wait() {
_condition.wait()
}

/// Signal the availability of the condition (awake one thread waiting on
/// the condition).
public func signal() {
_condition.signal()
}

/// Broadcast the availability of the condition (awake all threads waiting
/// on the condition).
public func broadcast() {
_condition.broadcast()
}

/// A helper method to execute the given body while condition is locked.
public func whileLocked<T>(_ body: () throws -> T) rethrows -> T {
_condition.lock()
defer { _condition.unlock() }
return try body()
}
}
4 changes: 2 additions & 2 deletions Sources/Basic/GraphAlgorithms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public enum GraphError: Swift.Error {
/// - Complexity: O(v + e) where (v, e) are the number of vertices and edges
/// reachable from the input nodes via the relation.
public func topologicalSort<T: Hashable>(
_ nodes: [T], successors: @noescape (T) -> [T]) throws -> [T] {
_ nodes: [T], successors: (T) -> [T]) throws -> [T] {
// Implements a topological sort via recursion and reverse postorder DFS.
func visit(_ node: T,
_ stack: inout OrderedSet<T>, _ visited: inout Set<T>, _ result: inout [T],
_ successors: @noescape (T) -> [T]) throws {
_ successors: (T) -> [T]) throws {
// Mark this node as visited -- we are done if it already was.
if !visited.insert(node).inserted {
return
Expand Down
14 changes: 2 additions & 12 deletions Sources/Basic/Lock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import Foundation

// FIXME: Temporary compatibility shims.
#if !os(macOS)
public typealias NSLock = Foundation.Lock
public typealias NSCondition = Foundation.Condition
private typealias NSLock = Foundation.Lock
#endif

/// A simple lock wrapper.
Expand All @@ -25,18 +24,9 @@ public struct Lock {
}

/// Execute the given block while holding the lock.
public mutating func withLock<T> (_ body: @noescape () throws -> T) rethrows -> T {
public mutating func withLock<T> (_ body: () throws -> T) rethrows -> T {
_lock.lock()
defer { _lock.unlock() }
return try body()
}
}

public extension NSCondition {
/// A helper method to execute the given body while condition is locked.
public func whileLocked<T>(_ body: @noescape () throws -> T) rethrows -> T {
lock()
defer { unlock() }
return try body()
}
}
6 changes: 3 additions & 3 deletions Sources/Basic/OutputByteStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public class OutputByteStream: TextOutputStream {
}

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

Expand Down Expand Up @@ -318,7 +318,7 @@ public func <<<(stream: OutputByteStream, value: ByteStreamable) -> OutputByteSt
}

@discardableResult
public func <<<(stream: OutputByteStream, value: Streamable) -> OutputByteStream {
public func <<<(stream: OutputByteStream, value: TextOutputStreamable) -> OutputByteStream {
stream.write(value)
return stream
}
Expand Down
11 changes: 11 additions & 0 deletions Sources/Basic/SwiftShims.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
This source file is part of the Swift.org open source project

Copyright 2016 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

public typealias TextOutputStreamable = Streamable
7 changes: 2 additions & 5 deletions Sources/Basic/SynchronizedQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import Foundation

/// This class can be used as a shared queue between multiple threads providing
/// thread safe APIs.
public final class SynchronizedQueue<Element> {

/// Storage for queued elements.
private var storage: [Element]

/// Condition variable to block the thread trying dequeue and queue is empty.
private var notEmptyCondition: NSCondition
private var notEmptyCondition: Condition

/// Create a default instance of queue.
public init() {
storage = []
notEmptyCondition = NSCondition()
notEmptyCondition = Condition()
}

/// Safely enqueue an element to end of the queue and signals a thread blocked on dequeue.
Expand Down
4 changes: 2 additions & 2 deletions Sources/Basic/Thread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ final public class Thread {
private var thread: ThreadImpl!

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

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

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

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