Skip to content

Improve external dependency discovery logic #195

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 3 commits into from
Apr 1, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import PackageDescription

let package = Package(
name: "Bar",
dependencies: [
.Package(url: "../Foo", majorVersion: 1)
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <Foo/Foo.h>

void cool() {
foo();
}

Choose a reason for hiding this comment

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

Very minor thing but this is missing a line break at the end of the file :)

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module SeaLover {
header "Sea/Sea.h"
link "SeaLover"
export *
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Foo

foo()
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void foo() {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void foo();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Foo {
header "Foo/Foo.h"
link "Foo"
export *
}
12 changes: 3 additions & 9 deletions Sources/Build/Command.compile(ClangModule).swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import POSIX
//FIXME: Incremental builds

extension Command {
static func compile(clangModule module: ClangModule, configuration conf: Configuration, prefix: String) -> (Command, Command) {
static func compile(clangModule module: ClangModule, externalModules: Set<Module>, configuration conf: Configuration, prefix: String) -> (Command, Command) {

let wd = Path.join(prefix, "\(module.c99name).build")
let mkdir = Command.createDirectory(wd)
Expand All @@ -36,14 +36,8 @@ extension Command {
//transitive closure of the target being built allowing the use of `#include "..."`
//add `-I` argument to the include directory of every target outside the package in the
//transitive closure of the target being built allowing the use of `#include <...>`
//FIXME: To detect external deps we're checking if their path's parent.parent directory
//is `Packages` as external deps will get copied to `Packages` dir. There should be a
//better way to do this.
if dep.path.parentDirectory.parentDirectory.basename == "Packages" {
includeFlag = "-I"
} else {
includeFlag = "-iquote"
}

includeFlag = externalModules.contains(dep) ? "-I" : "-iquote"
args += [includeFlag, dep.path]
args += ["-l\(dep.c99name)"] //FIXME: giving path to other module's -fmodule-map-file is not linking that module
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Build/describe().swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Utility
/**
- Returns: path to generated YAML for consumption by the llbuild based swift-build-tool
*/
public func describe(prefix: String, _ conf: Configuration, _ modules: [Module], _ products: [Product], Xcc: [String], Xld: [String], Xswiftc: [String]) throws -> String {
public func describe(prefix: String, _ conf: Configuration, _ modules: [Module], _ externalModules: Set<Module> , _ products: [Product], Xcc: [String], Xld: [String], Xswiftc: [String]) throws -> String {

guard modules.count > 0 else {
throw Error.NoModules
Expand Down Expand Up @@ -50,7 +50,7 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
}
}

let (compile, mkdir) = Command.compile(clangModule: module, configuration: conf, prefix: prefix)
let (compile, mkdir) = Command.compile(clangModule: module, externalModules: externalModules, configuration: conf, prefix: prefix)
commands.append(compile)
commands.append(mkdir)
targets.main.cmds.append(compile)
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 @@ -68,7 +68,7 @@ do {
let dirs = try directories()
let (rootPackage, externalPackages) = try fetch(dirs.root)
let (modules, externalModules, products) = try transmute(rootPackage, externalPackages: externalPackages)
let yaml = try describe(dirs.build, conf, modules, products, Xcc: opts.Xcc, Xld: opts.Xld, Xswiftc: opts.Xswiftc)
let yaml = try describe(dirs.build, conf, modules, Set<Module>(externalModules), products, Xcc: opts.Xcc, Xld: opts.Xld, Xswiftc: opts.Xswiftc)
try build(YAMLPath: yaml, target: "default")

case .Init(let initMode):
Expand Down
4 changes: 2 additions & 2 deletions Sources/swift-build/xp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import Build
import POSIX

#if os(Linux)
public func describe(prefix: String, _ conf: Configuration, _ modules: [Module], _ products: [Product], Xcc: [String], Xld: [String], Xswiftc: [String]) throws -> String {
public func describe(prefix: String, _ conf: Configuration, _ modules: [Module], _ externalModules: Set<Module>, _ products: [Product], Xcc: [String], Xld: [String], Xswiftc: [String]) throws -> String {
do {
return try Build.describe(prefix, conf, modules, products, Xcc: Xcc, Xld: Xld, Xswiftc: Xswiftc)
return try Build.describe(prefix, conf, modules, externalModules, products, Xcc: Xcc, Xld: Xld, Xswiftc: Xswiftc)
} catch {

// it is a common error on Linux for clang++ to not be installed, but
Expand Down
2 changes: 1 addition & 1 deletion Tests/Build/DescribeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XCTest
final class DescribeTests: XCTestCase {
func testDescribingNoModulesThrows() {
do {
let _ = try describe("foo", .Debug, [], [], Xcc: [], Xld: [], Xswiftc: [])
let _ = try describe("foo", .Debug, [], [], [], Xcc: [], Xld: [], Xswiftc: [])
XCTFail("This call should throw")
} catch Build.Error.NoModules {
XCTAssert(true, "This error should be throw")
Expand Down
9 changes: 9 additions & 0 deletions Tests/Functional/TestClangModules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ class TestClangModulesTestCase: XCTestCase {
XCTAssertEqual(output, "hello 5")
}
}

func testCUsingCDep2() {
//The C dependency "Foo" has different layout
fixture(name: "DependencyResolution/External/CUsingCDep2") { prefix in
XCTAssertBuilds(prefix, "Bar")
XCTAssertFileExists(prefix, "Bar/.build/debug/libFoo.so")
XCTAssertDirectoryExists(prefix, "Bar/Packages/Foo-1.2.3")
}
}
}


Expand Down