Skip to content

Commit

Permalink
Merge pull request #74 from kostiakoval/private-dependency
Browse files Browse the repository at this point in the history
Add Private dependency to Manifest
  • Loading branch information
mxcl committed Dec 17, 2015
2 parents e1c93ab + 4517b1c commit a63bc45
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Documentation/Package.swift.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ let package = Package(
)
```

A package can require dependencies that are only needed during develop,
as example for testing purposes. `testDependencies` are only fetched
when you build current package. They are not fetched if a package is
specified as a dependency in other package.

```swift
import PackageDescription

let package = Package(
name: "Hello",
testDependencies: [
.Package(url: "ssh://git@example.com/Tester.git", versions: Version(1,0,0)..<Version(2,0,0)),
]
)
```

## Customizing Builds

That the manifest is Swift allows for powerful customization, for example:
Expand Down
13 changes: 12 additions & 1 deletion Sources/PackageDescription/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@ public final class Package {
/// The list of dependencies.
public var dependencies: [Dependency]

/// The list of test dependencies. They aren't exposed to a parent Package
public var testDependencies: [Dependency]

/// The list of folders to exclude.
public var exclude: [String]

/// Construct a package.
public init(name: String? = nil, targets: [Target] = [], dependencies: [Dependency] = [], exclude: [String] = []) {
public init(name: String? = nil, targets: [Target] = [], dependencies: [Dependency] = [], testDependencies: [Dependency] = [], exclude: [String] = []) {
self.name = name
self.targets = targets
self.dependencies = dependencies
self.testDependencies = testDependencies
self.exclude = exclude

// Add custom exit handler to cause package to be dumped at exit, if requested.
Expand Down Expand Up @@ -97,6 +101,13 @@ extension Package: TOMLConvertible {
result += dependency.toTOML()
}
result += "]\n"

result += "testDependencies = ["
for dependency in testDependencies {
result += dependency.toTOML()
}
result += "]\n"

for target in targets {

result += "[[package.targets]]\n"
Expand Down
10 changes: 9 additions & 1 deletion Sources/dep/Manifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ extension PackageDescription.Package {
}
}

// Parse the test dependencies.
var testDependencies: [PackageDescription.Package.Dependency] = []
if case .Some(.Array(let array)) = table.items["testDependencies"] {
for item in array.items {
testDependencies.append(PackageDescription.Package.Dependency.fromTOML(item, baseURL: baseURL))
}
}

//Parse the exclude folders.
var exclude: [String] = []
if case .Some(.Array(let array)) = table.items["exclude"] {
Expand All @@ -52,7 +60,7 @@ extension PackageDescription.Package {
}
}

return PackageDescription.Package(name: name, targets: targets, dependencies: dependencies, exclude: exclude)
return PackageDescription.Package(name: name, targets: targets, dependencies: dependencies, testDependencies: testDependencies, exclude: exclude)
}
}

Expand Down
5 changes: 5 additions & 0 deletions Sources/swift-build/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ do {
try llbuild(srcroot: pkg.path, targets: try pkg.targets(), dependencies: dependencies, prefix: builddir, tmpdir: Path.join(builddir, "\(pkg.name).o"), configuration: configuration)
}

let testDependencies = try get(manifest.package.testDependencies, prefix: depsdir)
for pkg in testDependencies {
try llbuild(srcroot: pkg.path, targets: try pkg.targets(), dependencies: testDependencies, prefix: builddir, tmpdir: Path.join(builddir, "\(pkg.name).o"), configuration: configuration)
}

do {
// build the current directory
try llbuild(srcroot: rootd, targets: targets, dependencies: dependencies, prefix: builddir, tmpdir: Path.join(builddir, "\(pkgname).o"), configuration: configuration)
Expand Down
14 changes: 14 additions & 0 deletions Tests/PackageDescription/PackageDescriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class PackageTests: XCTestCase, XCTestCaseProvider {
return [
("testBasics", testBasics),
("testExclude", testExclude),
("testEmptyTestDependencies", testEmptyTestDependencies),
("testTestDependencies", testTestDependencies),
]
}

Expand All @@ -43,4 +45,16 @@ class PackageTests: XCTestCase, XCTestCaseProvider {
let pFromTOML = Package.fromTOML(parseTOML(p1.toTOML()))
XCTAssertEqual(pFromTOML.exclude, exclude)
}

func testEmptyTestDependencies() {
let p = Package(testDependencies: [])
XCTAssertEqual(p.testDependencies, [])
}

func testTestDependencies() {
let dependencies = [Package.Dependency.Package(url: "../TestingLib", majorVersion: 1)]
let p = Package(testDependencies: dependencies)
let pFromTOML = Package.fromTOML(parseTOML(p.toTOML()))
XCTAssertEqual(pFromTOML.testDependencies, dependencies)
}
}
11 changes: 11 additions & 0 deletions Tests/dep/Fixtures/30_test_deps/App/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import PackageDescription

let package = Package(
name: "App",
dependencies: [
.Package(url: "../Foo", majorVersion: 1)
],
testDependencies: [
.Package(url: "../TestingLib", majorVersion: 1)
]
)
3 changes: 3 additions & 0 deletions Tests/dep/Fixtures/30_test_deps/App/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Foo

foo()
3 changes: 3 additions & 0 deletions Tests/dep/Fixtures/30_test_deps/Foo/Foo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public func foo() {
{}()
}
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions Tests/dep/Fixtures/30_test_deps/TestingLib/TestingLib.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public func testingLib() {
{}()
}
11 changes: 11 additions & 0 deletions Tests/dep/Fixtures/31_test_deps_in_children/App/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import PackageDescription

let package = Package(
name: "App",
dependencies: [
.Package(url: "../Foo", majorVersion: 1)
],
testDependencies: [
.Package(url: "../TestingLib", majorVersion: 1)
]
)
3 changes: 3 additions & 0 deletions Tests/dep/Fixtures/31_test_deps_in_children/App/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Foo

foo()
4 changes: 4 additions & 0 deletions Tests/dep/Fixtures/31_test_deps_in_children/Foo/Foo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public func foo() {
{}()
}

8 changes: 8 additions & 0 deletions Tests/dep/Fixtures/31_test_deps_in_children/Foo/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import PackageDescription

let package = Package(
name: "Foo",
testDependencies: [
.Package(url: "../TestingFooLib", majorVersion: 1)
]
)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public func testingFooLib() {
{}()
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public func testingLib() {
{}()
}
42 changes: 42 additions & 0 deletions Tests/dep/FunctionalBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class FunctionalBuildTests: XCTestCase, XCTestCaseProvider {
("testSymlinkedSourceDirectoryWorks", testSymlinkedSourceDirectoryWorks),
("testSymlinkedNestedSourceDirectoryWorks", testSymlinkedNestedSourceDirectoryWorks),
("testPassExactDependenciesToBuildCommand", testPassExactDependenciesToBuildCommand),
("testGetTestDeps", testGetTestDeps),
("testBuildTestDeps", testBuildTestDeps),
("testDontGetChildrenPrivateDeps",testDontGetChildrenPrivateDeps),
("testBuildChildrenPrivateDeps", testBuildChildrenPrivateDeps),
]
}

Expand Down Expand Up @@ -349,6 +353,44 @@ class FunctionalBuildTests: XCTestCase, XCTestCaseProvider {
}
}

// 30: Test Dependencies
func testGetTestDeps() {
fixture(name: "30_test_deps") { prefix in
let appPath = Path.join(prefix, "App")
XCTAssertNotNil(try? executeSwiftBuild(appPath))
XCTAssertTrue(Path.join(appPath, "Packages/TestingLib-1.2.3").isDirectory)
}
}

func testBuildTestDeps() {
let filesToVerify = ["Foo.a", "TestingLib.a"]
fixture(name: "30_test_deps") { prefix in
let appPath = Path.join(prefix, "App")
XCTAssertNotNil(try? executeSwiftBuild(appPath))
XCTAssertTrue(self.verifyFilesExist(filesToVerify, fixturePath: appPath))
}
}

// 31: Private Dependencies for a Package dependency
func testDontGetChildrenPrivateDeps() {
fixture(name: "31_test_deps_in_children") { prefix in
let appPath = Path.join(prefix, "App")
XCTAssertNotNil(try? executeSwiftBuild(appPath))
XCTAssertTrue(Path.join(appPath, "Packages/TestingLib-1.2.3").isDirectory)
XCTAssertFalse(Path.join(appPath, "Packages/PrivateFooLib-1.2.3").isDirectory)
}
}

func testBuildChildrenPrivateDeps() {
let filesToVerify = ["Foo.a", "TestingLib.a"]
fixture(name: "31_test_deps_in_children") { prefix in
let appPath = Path.join(prefix, "App")
XCTAssertNotNil(try? executeSwiftBuild(appPath))
XCTAssertTrue(self.verifyFilesExist(filesToVerify, fixturePath: appPath))
XCTAssertFalse(self.verifyFilesExist(["TestingFooLib.a"], fixturePath: appPath))
}
}

func test_exdeps() {
fixture(name: "102_mattts_dealer") { prefix in
let prefix = Path.join(prefix, "app")
Expand Down

0 comments on commit a63bc45

Please sign in to comment.