Skip to content

Commit eb17e10

Browse files
authored
Merge pull request #720 from buttaface/droid
Get Android to parity with upstream driver and enable remaining tests
2 parents 67d804c + 57dfc6c commit eb17e10

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

Sources/SwiftDriver/Toolchains/GenericUnixToolchain.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ import TSCBasic
105105
targetTriple: Triple,
106106
isShared: Bool
107107
) throws -> String {
108-
return "libclang_rt.\(sanitizer.libraryName)-\(targetTriple.archName).a"
108+
let environment = (targetTriple.environment == .android) ? "-android" : ""
109+
return "libclang_rt.\(sanitizer.libraryName)-\(targetTriple.archName)\(environment).a"
109110
}
110111
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,13 +1689,13 @@ final class SwiftDriverTests: XCTestCase {
16891689
}
16901690

16911691
func testSanitizerArgs() throws {
1692-
// FIXME: This doesn't work on Linux.
1693-
#if os(macOS)
16941692
let commonArgs = [
16951693
"swiftc", "foo.swift", "bar.swift",
16961694
"-emit-executable", "-target", "x86_64-apple-macosx10.9",
16971695
"-module-name", "Test"
16981696
]
1697+
// FIXME: This doesn't work on Linux.
1698+
#if os(macOS)
16991699
do {
17001700
// address sanitizer
17011701
var driver = try Driver(args: commonArgs + ["-sanitize=address"])
@@ -1808,6 +1808,31 @@ final class SwiftDriverTests: XCTestCase {
18081808
}
18091809
#endif
18101810
#endif
1811+
1812+
// FIXME: This test will fail when not run on Android, because the driver uses
1813+
// the existence of the runtime support libraries to determine if
1814+
// a sanitizer is supported. Until we allow cross-compiling with
1815+
// sanitizers, this test is disabled outside Android.
1816+
#if os(Android)
1817+
do {
1818+
var driver = try Driver(
1819+
args: commonArgs + [
1820+
"-target", "aarch64-unknown-linux-android", "-sanitize=address"
1821+
]
1822+
)
1823+
let plannedJobs = try driver.planBuild()
1824+
1825+
XCTAssertEqual(plannedJobs.count, 4)
1826+
1827+
let compileJob = plannedJobs[0]
1828+
let compileCmd = compileJob.commandLine
1829+
XCTAssertTrue(compileCmd.contains(.flag("-sanitize=address")))
1830+
1831+
let linkJob = plannedJobs[3]
1832+
let linkCmd = linkJob.commandLine
1833+
XCTAssertTrue(linkCmd.contains(.flag("-fsanitize=address")))
1834+
}
1835+
#endif
18111836
}
18121837

18131838
func testSanitizerCoverageArgs() throws {
@@ -2202,7 +2227,7 @@ final class SwiftDriverTests: XCTestCase {
22022227
func testModuleWrapJob() throws {
22032228
// FIXME: These tests will fail when run on macOS, because
22042229
// swift-autolink-extract is not present
2205-
#if os(Linux)
2230+
#if os(Linux) || os(Android)
22062231
do {
22072232
var driver = try Driver(args: ["swiftc", "-target", "x86_64-unknown-linux-gnu", "-g", "foo.swift"])
22082233
let plannedJobs = try driver.planBuild()
@@ -2389,7 +2414,7 @@ final class SwiftDriverTests: XCTestCase {
23892414
let expectedDefaultContents: String
23902415
#if os(macOS)
23912416
expectedDefaultContents = "-apple-macosx"
2392-
#elseif os(Linux)
2417+
#elseif os(Linux) || os(Android)
23932418
expectedDefaultContents = "-unknown-linux"
23942419
#else
23952420
expectedDefaultContents = "-"
@@ -2678,7 +2703,7 @@ final class SwiftDriverTests: XCTestCase {
26782703

26792704
// FIXME: This will fail when run on macOS, because
26802705
// swift-autolink-extract is not present
2681-
#if os(Linux)
2706+
#if os(Linux) || os(Android)
26822707
do {
26832708
var driver = try Driver(args: ["swiftc", "-profile-generate", "-target", "x86_64-unknown-linux-gnu", "test.swift"])
26842709
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
@@ -3322,7 +3347,7 @@ final class SwiftDriverTests: XCTestCase {
33223347
serializer.writeDOT(to: &output)
33233348

33243349
let dynamicLinker = driver.targetTriple.isDarwin ? "ld" : "clang"
3325-
#if os(Linux)
3350+
#if os(Linux) || os(Android)
33263351
XCTAssertEqual(output,
33273352
"""
33283353
digraph Jobs {

0 commit comments

Comments
 (0)