Skip to content

Commit 57dfc6c

Browse files
committed
Get Android to parity with upstream driver and enable remaining tests
1 parent b754520 commit 57dfc6c

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()
@@ -2384,7 +2409,7 @@ final class SwiftDriverTests: XCTestCase {
23842409
let expectedDefaultContents: String
23852410
#if os(macOS)
23862411
expectedDefaultContents = "-apple-macosx"
2387-
#elseif os(Linux)
2412+
#elseif os(Linux) || os(Android)
23882413
expectedDefaultContents = "-unknown-linux"
23892414
#else
23902415
expectedDefaultContents = "-"
@@ -2670,7 +2695,7 @@ final class SwiftDriverTests: XCTestCase {
26702695

26712696
// FIXME: This will fail when run on macOS, because
26722697
// swift-autolink-extract is not present
2673-
#if os(Linux)
2698+
#if os(Linux) || os(Android)
26742699
do {
26752700
var driver = try Driver(args: ["swiftc", "-profile-generate", "-target", "x86_64-unknown-linux-gnu", "test.swift"])
26762701
let plannedJobs = try driver.planBuild().removingAutolinkExtractJobs()
@@ -3314,7 +3339,7 @@ final class SwiftDriverTests: XCTestCase {
33143339
serializer.writeDOT(to: &output)
33153340

33163341
let dynamicLinker = driver.targetTriple.isDarwin ? "ld" : "clang"
3317-
#if os(Linux)
3342+
#if os(Linux) || os(Android)
33183343
XCTAssertEqual(output,
33193344
"""
33203345
digraph Jobs {

0 commit comments

Comments
 (0)