Skip to content

Propagate -vfsoverlay from driver to frontend. #108

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
May 22, 2020
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
1 change: 1 addition & 0 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ extension Driver {

try commandLine.appendAll(.I, from: &parsedOptions)
try commandLine.appendAll(.F, .Fsystem, from: &parsedOptions)
try commandLine.appendAll(.vfsoverlay, from: &parsedOptions)

try commandLine.appendLast(.AssertConfig, from: &parsedOptions)
try commandLine.appendLast(.autolinkForceLoad, from: &parsedOptions)
Expand Down
43 changes: 43 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,26 @@ final class SwiftDriverTests: XCTestCase {
}
}
}

func testVFSOverlay() throws {
do {
var driver = try Driver(args: ["swiftc", "-c", "-vfsoverlay", "overlay.yaml", "foo.swift"])
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs.count, 1)
XCTAssertEqual(plannedJobs[0].kind, .compile)
XCTAssert(plannedJobs[0].commandLine.contains(subsequence: [.flag("-vfsoverlay"), .path(.relative(RelativePath("overlay.yaml")))]))
}

// Verify that the overlays are passed to the frontend in the same order.
do {
var driver = try Driver(args: ["swiftc", "-c", "-vfsoverlay", "overlay1.yaml", "-vfsoverlay", "overlay2.yaml", "-vfsoverlay", "overlay3.yaml", "foo.swift"])
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs.count, 1)
XCTAssertEqual(plannedJobs[0].kind, .compile)
print(plannedJobs[0].commandLine)
XCTAssert(plannedJobs[0].commandLine.contains(subsequence: [.flag("-vfsoverlay"), .path(.relative(RelativePath("overlay1.yaml"))), .flag("-vfsoverlay"), .path(.relative(RelativePath("overlay2.yaml"))), .flag("-vfsoverlay"), .path(.relative(RelativePath("overlay3.yaml")))]))
}
}
}

func assertString(
Expand All @@ -2231,3 +2251,26 @@ func assertString(
\(message.isEmpty ? "" : ": " + message)
""", file: file, line: line)
}

fileprivate extension Array where Element: Equatable {
/// Returns true if the receiver contains the given elements as a subsequence
/// (i.e., all elements are present, contiguous, and in the same order).
///
/// A naïve implementation has been used here rather than a more efficient
/// general purpose substring search algorithm since the arrays being tested
/// are relatively small.
func contains<Elements: Collection>(
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this a lot! There are quite a few tests currently that this would improve.

subsequence: Elements
) -> Bool where Elements.Element == Element {
precondition(!subsequence.isEmpty, "Subsequence may not be empty")

let subsequenceCount = subsequence.count
for index in 0..<(self.count - subsequence.count) {
let subsequenceEnd = index + subsequenceCount
if self[index..<subsequenceEnd].elementsEqual(subsequence) {
return true
}
}
return false
}
}