Skip to content

Get Android to parity with upstream driver and enable remaining tests #720

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 1 commit into from
Jul 2, 2021
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
3 changes: 2 additions & 1 deletion Sources/SwiftDriver/Toolchains/GenericUnixToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import TSCBasic
targetTriple: Triple,
isShared: Bool
) throws -> String {
return "libclang_rt.\(sanitizer.libraryName)-\(targetTriple.archName).a"
let environment = (targetTriple.environment == .android) ? "-android" : ""
return "libclang_rt.\(sanitizer.libraryName)-\(targetTriple.archName)\(environment).a"
Copy link
Member Author

Choose a reason for hiding this comment

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

}
}
37 changes: 31 additions & 6 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1689,13 +1689,13 @@ final class SwiftDriverTests: XCTestCase {
}

func testSanitizerArgs() throws {
// FIXME: This doesn't work on Linux.
#if os(macOS)
let commonArgs = [
"swiftc", "foo.swift", "bar.swift",
"-emit-executable", "-target", "x86_64-apple-macosx10.9",
"-module-name", "Test"
]
// FIXME: This doesn't work on Linux.
#if os(macOS)
do {
// address sanitizer
var driver = try Driver(args: commonArgs + ["-sanitize=address"])
Expand Down Expand Up @@ -1808,6 +1808,31 @@ final class SwiftDriverTests: XCTestCase {
}
#endif
Copy link
Member Author

Choose a reason for hiding this comment

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

These linux tests above are disabled on linux, mistake or deliberate decision?

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like they are enabled, only on Linux?

Copy link
Member Author

Choose a reason for hiding this comment

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

See the enclosing #if os(macOS) conditional compile at the top of this test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see. Hmm :/

#endif

// FIXME: This test will fail when not run on Android, because the driver uses
// the existence of the runtime support libraries to determine if
// a sanitizer is supported. Until we allow cross-compiling with
// sanitizers, this test is disabled outside Android.
#if os(Android)
do {
var driver = try Driver(
args: commonArgs + [
"-target", "aarch64-unknown-linux-android", "-sanitize=address"
]
)
let plannedJobs = try driver.planBuild()

XCTAssertEqual(plannedJobs.count, 4)

let compileJob = plannedJobs[0]
let compileCmd = compileJob.commandLine
XCTAssertTrue(compileCmd.contains(.flag("-sanitize=address")))

let linkJob = plannedJobs[3]
let linkCmd = linkJob.commandLine
XCTAssertTrue(linkCmd.contains(.flag("-fsanitize=address")))
}
#endif
}

func testSanitizerCoverageArgs() throws {
Expand Down Expand Up @@ -2202,7 +2227,7 @@ final class SwiftDriverTests: XCTestCase {
func testModuleWrapJob() throws {
// FIXME: These tests will fail when run on macOS, because
// swift-autolink-extract is not present
#if os(Linux)
#if os(Linux) || os(Android)
do {
var driver = try Driver(args: ["swiftc", "-target", "x86_64-unknown-linux-gnu", "-g", "foo.swift"])
let plannedJobs = try driver.planBuild()
Expand Down Expand Up @@ -2384,7 +2409,7 @@ final class SwiftDriverTests: XCTestCase {
let expectedDefaultContents: String
#if os(macOS)
expectedDefaultContents = "-apple-macosx"
#elseif os(Linux)
#elseif os(Linux) || os(Android)
expectedDefaultContents = "-unknown-linux"
#else
expectedDefaultContents = "-"
Expand Down Expand Up @@ -2670,7 +2695,7 @@ final class SwiftDriverTests: XCTestCase {

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

let dynamicLinker = driver.targetTriple.isDarwin ? "ld" : "clang"
#if os(Linux)
#if os(Linux) || os(Android)
XCTAssertEqual(output,
"""
digraph Jobs {
Expand Down