Skip to content

Commit 1820d94

Browse files
committed
Use external dependency to decide -iquote vs -I
1 parent 79e86ed commit 1820d94

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

Sources/Build/Command.compile(ClangModule).swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import POSIX
1515
//FIXME: Incremental builds
1616

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

2020
let wd = Path.join(prefix, "\(module.c99name).build")
2121
let mkdir = Command.createDirectory(wd)
@@ -36,14 +36,9 @@ extension Command {
3636
//transitive closure of the target being built allowing the use of `#include "..."`
3737
//add `-I` argument to the include directory of every target outside the package in the
3838
//transitive closure of the target being built allowing the use of `#include <...>`
39-
//FIXME: To detect external deps we're checking if their path's parent.parent directory
40-
//is `Packages` as external deps will get copied to `Packages` dir. There should be a
41-
//better way to do this.
42-
if dep.path.parentDirectory.parentDirectory.basename == "Packages" {
43-
includeFlag = "-I"
44-
} else {
45-
includeFlag = "-iquote"
46-
}
39+
40+
includeFlag = externalModules.contains(dep) ? "-I" : "-iquote"
41+
print("\(includeFlag) \(dep.path)")
4742
args += [includeFlag, dep.path]
4843
args += ["-l\(dep.c99name)"] //FIXME: giving path to other module's -fmodule-map-file is not linking that module
4944
}

Sources/Build/describe().swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Utility
1818
/**
1919
- Returns: path to generated YAML for consumption by the llbuild based swift-build-tool
2020
*/
21-
public func describe(prefix: String, _ conf: Configuration, _ modules: [Module], _ products: [Product], Xcc: [String], Xld: [String], Xswiftc: [String]) throws -> String {
21+
public func describe(prefix: String, _ conf: Configuration, _ modules: [Module], _ externalModules: Set<Module> , _ products: [Product], Xcc: [String], Xld: [String], Xswiftc: [String]) throws -> String {
2222

2323
guard modules.count > 0 else {
2424
throw Error.NoModules
@@ -50,7 +50,7 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
5050
}
5151
}
5252

53-
let (compile, mkdir) = Command.compile(clangModule: module, configuration: conf, prefix: prefix)
53+
let (compile, mkdir) = Command.compile(clangModule: module, externalModules: externalModules, configuration: conf, prefix: prefix)
5454
commands.append(compile)
5555
commands.append(mkdir)
5656
targets.main.cmds.append(compile)

Sources/swift-build/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ do {
6868
let dirs = try directories()
6969
let (rootPackage, externalPackages) = try fetch(dirs.root)
7070
let (modules, externalModules, products) = try transmute(rootPackage, externalPackages: externalPackages)
71-
let yaml = try describe(dirs.build, conf, modules, products, Xcc: opts.Xcc, Xld: opts.Xld, Xswiftc: opts.Xswiftc)
71+
let yaml = try describe(dirs.build, conf, modules, Set<Module>(externalModules), products, Xcc: opts.Xcc, Xld: opts.Xld, Xswiftc: opts.Xswiftc)
7272
try build(YAMLPath: yaml, target: "default")
7373

7474
case .Init(let initMode):

Tests/Build/DescribeTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import XCTest
1414
final class DescribeTests: XCTestCase {
1515
func testDescribingNoModulesThrows() {
1616
do {
17-
let _ = try describe("foo", .Debug, [], [], Xcc: [], Xld: [], Xswiftc: [])
17+
let _ = try describe("foo", .Debug, [], [], [], Xcc: [], Xld: [], Xswiftc: [])
1818
XCTFail("This call should throw")
1919
} catch Build.Error.NoModules {
2020
XCTAssert(true, "This error should be throw")

0 commit comments

Comments
 (0)