Skip to content

Add support for empty source packages #149

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 2 commits into from
Mar 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import PackageDescription

let package = Package(
name: "EmptyWithDependency",
dependencies: [
.Package(url: "../FooLib2", majorVersion: 1),
])
15 changes: 13 additions & 2 deletions Sources/Transmute/transmute().swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@

import PackageType
import Utility
import func libc.exit

public func transmute(packages: [Package]) throws -> ([Module], [Product]) {
public func transmute(packages: [Package], rootdir: String) throws -> ([Module], [Product]) {

var products: [Product] = []
var map: [Package: [Module]] = [:]

for package in packages {
let modules = try package.modules()

let modules: [Module]
do {
modules = try package.modules()
} catch Package.ModuleError.NoModules(let pkg) where pkg.path == rootdir {
//Ignore and print warning if root package doesn't contain any sources
print("warning: root package '\(pkg)' does not contain any sources")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to handle warning in similar way to errors.
That way we could hold warnings in one place and make them statically typed, by using enums.
Also we could use different text color for warnings as well.
But maybe it's out of the scope for that PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agreed. I was actually thinking to do that but thought it'd be too much for this PR. I would love to take a shot at that in a sep. PR

if packages.count == 1 { exit(0) } //Exit now if there is no more packages
modules = []
}

let testModules = try package.testModules()
products += try package.products(modules, tests: testModules)

Expand Down
2 changes: 1 addition & 1 deletion Sources/swift-build/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ do {
case .Build(let conf):
let dirs = try directories()
let packages = try fetch(dirs.root)
let (modules, products) = try transmute(packages)
let (modules, products) = try transmute(packages, rootdir: dirs.root)
let yaml = try describe(dirs.build, conf, modules, products, Xcc: opts.Xcc, Xld: opts.Xld, Xswiftc: opts.Xswiftc)
try build(YAMLPath: yaml, target: "default")

Expand Down
7 changes: 0 additions & 7 deletions Tests/Functional/TestInvalidLayouts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ import func POSIX.unlink

class InvalidLayoutsTestCase: XCTestCase {

func testNoTargets() {
fixture(name: "InvalidLayouts/NoTargets") { prefix in
XCTAssertFileExists(prefix, "Package.swift")
XCTAssertBuildFails(prefix)
}
}

func testMultipleRoots() {
fixture(name: "InvalidLayouts/MultipleRoots1") { prefix in
XCTAssertBuildFails(prefix)
Expand Down
19 changes: 19 additions & 0 deletions Tests/Functional/TestMiscellaneous.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ class MiscellaneousTestCase: XCTestCase {
}
}

func testPackageWithNoSources() {

// Tests a package with no source files

fixture(name: "Miscellaneous/Empty") { prefix in
XCTAssertBuilds(prefix)
}
}

func testPackageWithNoSourcesButDependency() {

// Tests a package with no source files but dependency, dependency should build.

fixture(name: "Miscellaneous/ExactDependencies") { prefix in
XCTAssertBuilds(prefix, "EmptyWithDependency")
XCTAssertFileExists(prefix, "EmptyWithDependency/.build/debug/FooLib2.swiftmodule")
}
}

func testManifestExcludes1() {

// Tests exclude syntax where no target customization is specified
Expand Down
3 changes: 2 additions & 1 deletion Tests/Functional/TestValidLayouts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ extension DependencyResolutionTestCase {
extension InvalidLayoutsTestCase {
static var allTests : [(String, InvalidLayoutsTestCase -> () throws -> Void)] {
return [
("testNoTargets", testNoTargets),
("testMultipleRoots", testMultipleRoots),
("testInvalidLayout1", testInvalidLayout1),
("testInvalidLayout2", testInvalidLayout2),
Expand All @@ -160,6 +159,8 @@ extension MiscellaneousTestCase {
static var allTests : [(String, MiscellaneousTestCase -> () throws -> Void)] {
return [
("testPrintsSelectedDependencyVersion", testPrintsSelectedDependencyVersion),
("testPackageWithNoSources", testPackageWithNoSources),
("testPackageWithNoSourcesButDependency", testPackageWithNoSourcesButDependency),
("testManifestExcludes1", testManifestExcludes1),
("testManifestExcludes2", testManifestExcludes2),
("testManifestExcludes3", testManifestExcludes3),
Expand Down
4 changes: 2 additions & 2 deletions Tests/Transmute/ModuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ extension ModuleTests {
let prefix = Path.join(prefix, "App")
let manifest = try Manifest(path: prefix, baseURL: prefix)
let packages = try get(manifest)
let (modules, _) = try transmute(packages)
let (modules, _) = try transmute(packages, rootdir: prefix)

XCTAssertEqual(modules.count, 3)
XCTAssertEqual(recursiveDependencies(modules).count, 3)
Expand All @@ -212,7 +212,7 @@ extension ModuleTests {
let prefix = Path.join(prefix, "App")
let manifest = try Manifest(path: prefix, baseURL: prefix)
let packages = try get(manifest)
let (modules, _) = try transmute(packages)
let (modules, _) = try transmute(packages, rootdir: prefix)

XCTAssertEqual(modules.count, 2)
XCTAssertTrue(modules.first is CModule)
Expand Down