Skip to content

Commit ae91219

Browse files
committed
Testing Support
We now build `swift-test`, which will create a test runner based on the layout of your Test modules as per our testing proposal: https://github.com/apple/swift-evolution/blob/master/proposals/0019-package-manager-testing.md Also includes a significant refactor. I am sorry this is not more atomic, but the work just kept expanding in scope and keeping history straight was too much work. Notable improvements aside from the testing propopsal: * Whole Module Optimization is applied to release builds * A single llbuild.yaml file is created for all packages in a project, this allows llbuild to properly manage build dependencies * A new products feature has been added to Package.swift which allows you to define product targets (like dynamic libraries) that consist of a series of modules The refactor involved creating many more modules with much more refined and defined scope and responsibility. The code is now much more maintainable.
1 parent f7f0d74 commit ae91219

File tree

126 files changed

+3226
-3693
lines changed

Some content is hidden

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

126 files changed

+3226
-3693
lines changed

Fixtures/DependencyResolution/External/Complex/app/Package.swift

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2015 - 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+
111
import PackageDescription
212

313
let package = Package(

Fixtures/DependencyResolution/External/Complex/app/main.swift

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2015 - 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+
111
import FisherYates
212
import PlayingCard
313
import DeckOfPlayingCards

Fixtures/DependencyResolution/External/Complex/deck-of-playing-cards/src/Deck.swift

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2015 - 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+
111
import FisherYates
212
import PlayingCard
313

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import PackageDescription
2+
3+
let package = Package(
4+
name: "FooLib1",
5+
targets: [Target(name: "cli", dependencies: ["FooLib1"])])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import FooLib1
2+
3+
print(FooLib1())

Package.swift

+41-10
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,52 @@
1111
import PackageDescription
1212

1313
let package = Package(
14-
name: "SwiftPackageManager",
14+
name: "SwiftPM",
1515
targets: [
1616
Target(
17-
name: "sys",
18-
dependencies: [.Target(name: "POSIX")]),
19-
Target(
17+
/** “Swifty” POSIX functions from libc */
2018
name: "POSIX",
21-
dependencies: [.Target(name: "libc")]),
19+
dependencies: ["libc"]),
20+
Target(
21+
/** Abstractions for common operations */
22+
name: "Utility",
23+
dependencies: ["POSIX"]),
24+
Target(
25+
/** Base types for the package-engine */
26+
name: "PackageType",
27+
dependencies: ["PackageDescription", "Utility"]), //FIXME dependency on PackageDescription sucks
28+
Target( //FIXME Carpet is too general, we only need `Path`
29+
name: "ManifestParser",
30+
dependencies: ["PackageDescription", "PackageType"]),
31+
Target(
32+
/** Turns Packages into Modules & Products */
33+
name: "Transmute",
34+
dependencies: ["PackageDescription", "PackageType"]),
35+
Target(
36+
/** Fetches Packages and their dependencies */
37+
name: "Get",
38+
dependencies: ["ManifestParser"]),
2239
Target(
23-
name: "dep",
24-
dependencies: [.Target(name: "sys"), .Target(name: "PackageDescription")]),
40+
/** Builds Modules and Products */
41+
name: "Build",
42+
dependencies: ["PackageType"]),
2543
Target(
26-
name: "swift-get",
27-
dependencies: [.Target(name: "dep")]),
44+
/** Common components of both executables */
45+
name: "Multitool",
46+
dependencies: ["PackageType"]),
2847
Target(
2948
name: "swift-build",
30-
dependencies: [.Target(name: "dep")]),
49+
dependencies: ["Get", "Transmute", "Build", "Multitool"]),
50+
Target(
51+
name: "swift-test",
52+
dependencies: ["Multitool"]),
3153
])
54+
55+
56+
// otherwise executables are auto-determined you could
57+
// prevent this by asking for the auto-determined list
58+
// here and editing it.
59+
60+
let dylib = Product(name: "PackageDescription", type: .Library(.Dynamic), modules: "PackageDescription")
61+
62+
products.append(dylib)

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ following options:
5454
swiftpm/Utilities/bootstrap --swiftc path/to/snapshot/usr/bin/swiftc --sbt path/to/snapshot/usr/bin/swift-build-tool
5555

5656
`swiftc` and `swift-build-tool` are both executables provided as part of Swift downloadable snapshots, *they are **not** built from the sources in this repository*.
57-
58-
Please note, that the 2.2 release snapshot does not come with `swift-build-tool`, either download the *development* snapshot or build your own copy of `swift-llbuild`.
5957

6058
3. Using the Xcode Project in [Support](Support), this option requires:
6159
* Xcode 7.3 (beta)
@@ -67,7 +65,7 @@ There is further development-oriented documentation in [Documentation/Internals]
6765

6866
## System Requirements
6967

70-
The package manager’s system requirements are the same as [those for Swift](https://github.com/apple/swift#system-requirements).
68+
The package manager’s system requirements are the same as [those for Swift](https://github.com/apple/swift#system-requirements) with the caveat that the package manager requires Git at runtime as well as build-time.
7169

7270
## Contributing
7371

Sources/POSIX/exit.swift renamed to Sources/Build/Configuration.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
@_exported import func libc.exit
11+
public enum Configuration {
12+
case Debug, Release
13+
14+
var dirname: String {
15+
switch self {
16+
case .Debug: return "debug"
17+
case .Release: return "release"
18+
}
19+
}
20+
}

Sources/Build/IncrementalNode.swift

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2015 - 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 Utility
12+
import PackageType
13+
14+
struct IncrementalNode {
15+
let module: SwiftModule
16+
let prefix: String
17+
18+
var tempsPath: String {
19+
return Path.join(prefix, "\(module.c99name).build")
20+
}
21+
22+
var swiftModuleName: String {
23+
return "\(module.c99name).swiftmodule"
24+
}
25+
26+
var objectPaths: [String] {
27+
return module.sources.relativePaths.map{ Path.join(tempsPath, "\($0).o") }
28+
}
29+
30+
var outputs: [String] {
31+
return [module.targetName] + objectPaths
32+
}
33+
34+
var inputs: [String] {
35+
return module.recursiveDependencies.map{ $0.targetName }
36+
}
37+
38+
var moduleOutputPath: String {
39+
return Path.join(prefix, swiftModuleName)
40+
}
41+
}

Sources/Build/YAML.swift

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2015 - 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 struct Utility.Path
12+
import struct libc.FILE
13+
import func libc.fclose
14+
import POSIX
15+
16+
class YAML {
17+
let path: String
18+
private let fp: UnsafeMutablePointer<FILE>
19+
20+
init(path: String...) throws {
21+
self.path = Path.join(path)
22+
fp = try fopen(self.path, mode: .Write)
23+
}
24+
25+
func close() {
26+
fclose(fp)
27+
}
28+
29+
func write(anys: Any...) throws {
30+
var anys = anys
31+
try fputs(anys.removeFirst() as! String, fp)
32+
if !anys.isEmpty {
33+
try fputs(anys.map(toYAML).joinWithSeparator(""), fp)
34+
}
35+
try fputs("\n", fp)
36+
37+
}
38+
}
39+
40+
private func toYAML(any: Any) -> String {
41+
42+
func quote(input: String) -> String {
43+
for c in input.characters {
44+
if c == "@" || c == " " || c == "-" {
45+
return "\"\(input)\""
46+
}
47+
}
48+
return input
49+
}
50+
51+
switch any {
52+
case let string as String where string == "":
53+
return "\"\""
54+
case let string as String:
55+
return string
56+
case let array as [String]:
57+
return "[" + array.map(quote).joinWithSeparator(", ") + "]"
58+
case let bool as Bool:
59+
return bool ? "true" : "false"
60+
default:
61+
fatalError("Unimplemented YAML type")
62+
}
63+
}

0 commit comments

Comments
 (0)