Skip to content

Commit

Permalink
Find blocklist files from toolchain dir and feed them to compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
nkcsgexi committed Apr 11, 2023
1 parent 7954acc commit 41dc240
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Sources/SwiftDriver/Driver/Driver.swift
Expand Up @@ -432,6 +432,24 @@ public struct Driver {
return supportedFrontendFeatures.contains(feature.rawValue)
}

@_spi(Testing)
public static func findBlocklists(RelativeTo execDir: AbsolutePath) throws -> [AbsolutePath] {
// Expect to find all blocklists in such dir:
// .../XcodeDefault.xctoolchain/usr/local/lib/swift/blocklists
var results: [AbsolutePath] = []
let blockListDir = execDir.parentDirectory
.appending(components: "local", "lib", "swift", "blocklists")
if (localFileSystem.exists(blockListDir)) {
try localFileSystem.getDirectoryContents(blockListDir).forEach {
let currentFile = AbsolutePath(blockListDir, try VirtualPath(path: $0).relativePath!)
if currentFile.extension == "yml" || currentFile.extension == "yaml" {
results.append(currentFile)
}
}
}
return results
}

/// Handler for emitting diagnostics to stderr.
public static let stderrDiagnosticsHandler: DiagnosticsEngine.DiagnosticsHandler = { diagnostic in
stdErrQueue.sync {
Expand Down
7 changes: 7 additions & 0 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Expand Up @@ -269,6 +269,13 @@ extension Driver {
commandLine.appendPath(localPluginPath)
}

if isFrontendArgSupported(.blockListFile) {
try Driver.findBlocklists(RelativeTo: try toolchain.executableDir).forEach {
commandLine.appendFlag(.blockListFile)
commandLine.appendPath($0)
}
}

// Pass down -user-module-version if we are working with a compiler that
// supports it.
if let ver = parsedOptions.getLastArgument(.userModuleVersion)?.asSingle,
Expand Down
@@ -0,0 +1 @@
---
@@ -0,0 +1 @@
---
@@ -0,0 +1 @@
---
7 changes: 7 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Expand Up @@ -6822,6 +6822,13 @@ final class SwiftDriverTests: XCTestCase {
#endif
}

func testFindingBlockLists() throws {
let execDir = testInputsPath.appending(components: "Dummy.xctoolchain", "usr", "bin")
let list = try Driver.findBlocklists(RelativeTo: execDir)
XCTAssertEqual(list.count, 2)
XCTAssertTrue(list.allSatisfy { $0.extension! == "yml" || $0.extension! == "yaml"})
}

func testToolSearching() throws {
#if os(Windows)
let PATH = "Path"
Expand Down

0 comments on commit 41dc240

Please sign in to comment.