Skip to content

Commit af9fce4

Browse files
authored
Merge pull request #1329 from nkcsgexi/block-list-paths
Find blocklist files from toolchain dir and feed them to compiler
2 parents 82ef3e2 + 41dc240 commit af9fce4

File tree

7 files changed

+58
-3
lines changed

7 files changed

+58
-3
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,24 @@ public struct Driver {
432432
return supportedFrontendFeatures.contains(feature.rawValue)
433433
}
434434

435+
@_spi(Testing)
436+
public static func findBlocklists(RelativeTo execDir: AbsolutePath) throws -> [AbsolutePath] {
437+
// Expect to find all blocklists in such dir:
438+
// .../XcodeDefault.xctoolchain/usr/local/lib/swift/blocklists
439+
var results: [AbsolutePath] = []
440+
let blockListDir = execDir.parentDirectory
441+
.appending(components: "local", "lib", "swift", "blocklists")
442+
if (localFileSystem.exists(blockListDir)) {
443+
try localFileSystem.getDirectoryContents(blockListDir).forEach {
444+
let currentFile = AbsolutePath(blockListDir, try VirtualPath(path: $0).relativePath!)
445+
if currentFile.extension == "yml" || currentFile.extension == "yaml" {
446+
results.append(currentFile)
447+
}
448+
}
449+
}
450+
return results
451+
}
452+
435453
/// Handler for emitting diagnostics to stderr.
436454
public static let stderrDiagnosticsHandler: DiagnosticsEngine.DiagnosticsHandler = { diagnostic in
437455
stdErrQueue.sync {

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ extension Driver {
269269
commandLine.appendPath(localPluginPath)
270270
}
271271

272+
if isFrontendArgSupported(.blockListFile) {
273+
try Driver.findBlocklists(RelativeTo: try toolchain.executableDir).forEach {
274+
commandLine.appendFlag(.blockListFile)
275+
commandLine.appendPath($0)
276+
}
277+
}
278+
272279
// Pass down -user-module-version if we are working with a compiler that
273280
// supports it.
274281
if let ver = parsedOptions.getLastArgument(.userModuleVersion)?.asSingle,

Sources/SwiftOptions/Options.swift

Lines changed: 23 additions & 3 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6822,6 +6822,13 @@ final class SwiftDriverTests: XCTestCase {
68226822
#endif
68236823
}
68246824

6825+
func testFindingBlockLists() throws {
6826+
let execDir = testInputsPath.appending(components: "Dummy.xctoolchain", "usr", "bin")
6827+
let list = try Driver.findBlocklists(RelativeTo: execDir)
6828+
XCTAssertEqual(list.count, 2)
6829+
XCTAssertTrue(list.allSatisfy { $0.extension! == "yml" || $0.extension! == "yaml"})
6830+
}
6831+
68256832
func testToolSearching() throws {
68266833
#if os(Windows)
68276834
let PATH = "Path"

0 commit comments

Comments
 (0)