Skip to content
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

Find blocklist files from toolchain dir and feed them to compiler #1329

Merged
merged 2 commits into from
Apr 11, 2023
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
18 changes: 18 additions & 0 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
26 changes: 23 additions & 3 deletions Sources/SwiftOptions/Options.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
7 changes: 7 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
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