Skip to content

Commit 877a882

Browse files
authored
Merge pull request #814 from artemcm/FixASScanningTest
[Test Change] Use `Driver` to generate scanner invocation in dependency scanning test
2 parents 97c9ec7 + d2ed076 commit 877a882

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public extension Driver {
4040

4141
/// Generate a full command-line invocation to be used for the dependency scanning action
4242
/// on the target module.
43-
mutating private func dependencyScannerInvocationCommand()
43+
@_spi(Testing) public mutating func dependencyScannerInvocationCommand()
4444
throws -> ([TypedVirtualPath],[Job.ArgTemplate]) {
4545
// Aggregate the fast dependency scanner arguments
4646
var inputs: [TypedVirtualPath] = []

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -727,11 +727,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
727727

728728
/// Test the libSwiftScan dependency scanning.
729729
func testDependencyScanning() throws {
730-
#if os(macOS) && arch(arm64)
731-
// Temporarily disabled on Apple Silicon
732-
throw XCTSkip()
733-
#endif
734-
let (stdLibPath, shimsPath, toolchain, hostTriple) = try getDriverArtifactsForScanning()
730+
let (_, _, toolchain, hostTriple) = try getDriverArtifactsForScanning()
735731

736732
// The dependency oracle wraps an instance of libSwiftScan and ensures thread safety across
737733
// queries.
@@ -760,12 +756,22 @@ final class ExplicitModuleBuildTests: XCTestCase {
760756
let cHeadersPath : String = testInputsPath + "/ExplicitModuleBuilds/CHeaders"
761757
let swiftModuleInterfacesPath : String = testInputsPath + "/ExplicitModuleBuilds/Swift"
762758
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
763-
let scannerCommand = ["-scan-dependencies",
764-
"-I", cHeadersPath,
765-
"-I", swiftModuleInterfacesPath,
766-
"-I", stdLibPath.description,
767-
"-I", shimsPath.description,
768-
main.pathString] + sdkArgumentsForTesting
759+
var driver = try Driver(args: ["swiftc",
760+
"-I", cHeadersPath,
761+
"-I", swiftModuleInterfacesPath,
762+
"-experimental-explicit-module-build",
763+
"-working-directory", path.pathString,
764+
"-disable-clang-target",
765+
main.pathString] + sdkArgumentsForTesting,
766+
env: ProcessEnv.vars)
767+
let resolver = try ArgsResolver(fileSystem: localFileSystem)
768+
var scannerCommand = try driver.dependencyScannerInvocationCommand().1.map { try resolver.resolve($0) }
769+
// We generate full swiftc -frontend -scan-dependencies invocations in order to also be
770+
// able to launch them as standalone jobs. Frontend's argument parser won't recognize
771+
// -frontend when passed directly via libSwiftScan.
772+
if scannerCommand.first == "-frontend" {
773+
scannerCommand.removeFirst()
774+
}
769775

770776
// Here purely to dump diagnostic output in a reasonable fashion when things go wrong.
771777
let lock = NSLock()
@@ -815,7 +821,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
815821

816822
/// Test the libSwiftScan dependency scanning.
817823
func testDependencyScanReuseCache() throws {
818-
let (stdLibPath, shimsPath, toolchain, hostTriple) = try getDriverArtifactsForScanning()
824+
let (_, _, toolchain, hostTriple) = try getDriverArtifactsForScanning()
819825
try withTemporaryDirectory { path in
820826
let cacheSavePath = path.appending(component: "saved.moddepcache")
821827
let main = path.appending(component: "testDependencyScanning.swift")
@@ -830,13 +836,22 @@ final class ExplicitModuleBuildTests: XCTestCase {
830836
let cHeadersPath : String = testInputsPath + "/ExplicitModuleBuilds/CHeaders"
831837
let swiftModuleInterfacesPath : String = testInputsPath + "/ExplicitModuleBuilds/Swift"
832838
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
833-
let scannerCommand = ["-scan-dependencies",
834-
"-disable-implicit-concurrency-module-import",
835-
"-I", cHeadersPath,
836-
"-I", swiftModuleInterfacesPath,
837-
"-I", stdLibPath.description,
838-
"-I", shimsPath.description,
839-
main.pathString] + sdkArgumentsForTesting
839+
var driver = try Driver(args: ["swiftc",
840+
"-I", cHeadersPath,
841+
"-I", swiftModuleInterfacesPath,
842+
"-experimental-explicit-module-build",
843+
"-working-directory", path.pathString,
844+
"-disable-clang-target",
845+
main.pathString] + sdkArgumentsForTesting,
846+
env: ProcessEnv.vars)
847+
let resolver = try ArgsResolver(fileSystem: localFileSystem)
848+
var scannerCommand = try driver.dependencyScannerInvocationCommand().1.map { try resolver.resolve($0) }
849+
// We generate full swiftc -frontend -scan-dependencies invocations in order to also be
850+
// able to launch them as standalone jobs. Frontend's argument parser won't recognize
851+
// -frontend when passed directly via libSwiftScan.
852+
if scannerCommand.first == "-frontend" {
853+
scannerCommand.removeFirst()
854+
}
840855

841856
let scanLibPath = try Driver.getScanLibPath(of: toolchain,
842857
hostTriple: hostTriple,

0 commit comments

Comments
 (0)