Skip to content

Commit

Permalink
Merge pull request #1379 from nkcsgexi/5.9-flag-blocklist
Browse files Browse the repository at this point in the history
[5.9] cherry-pick block list configuration changes
  • Loading branch information
nkcsgexi committed Jun 16, 2023
2 parents 28b1bf8 + 6e2bd8e commit 0b96083
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,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 @@ -262,6 +262,13 @@ extension Driver {
try commandLine.appendAll(.pluginPath, .loadPluginLibrary, from: &parsedOptions)
}

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
10 changes: 9 additions & 1 deletion Sources/SwiftOptions/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extension Option {
public static let BF: Option = Option("-BF", .joinedOrSeparate, attributes: [.noDriver, .argumentIsPath], helpText: "add a directory to the baseline framework search path")
public static let BIEQ: Option = Option("-BI=", .joined, alias: Option.BI, attributes: [.noDriver])
public static let BI: Option = Option("-BI", .joinedOrSeparate, attributes: [.noDriver, .argumentIsPath], helpText: "add a module for baseline input")
public static let blockListFile: Option = Option("-blocklist-file", .separate, attributes: [.frontend, .noDriver], metaVar: "<path>", helpText: "The path to a blocklist configuration file")
public static let breakageAllowlistPath: Option = Option("-breakage-allowlist-path", .joinedOrSeparate, attributes: [.noDriver, .argumentIsPath], helpText: "An allowlist of breakages to not complain about")
public static let bridgingHeaderDirectoryForPrint: Option = Option("-bridging-header-directory-for-print", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<path>", helpText: "Directory for bridging header to be printed in compatibility header")
public static let bsdk: Option = Option("-bsdk", .joinedOrSeparate, attributes: [.noDriver, .argumentIsPath], helpText: "path to the baseline SDK to import frameworks")
Expand Down Expand Up @@ -72,7 +73,7 @@ extension Option {
public static let CrossModuleOptimization: Option = Option("-cross-module-optimization", .flag, attributes: [.helpHidden, .frontend], helpText: "Perform cross-module optimization")
public static let crosscheckUnqualifiedLookup: Option = Option("-crosscheck-unqualified-lookup", .flag, attributes: [.frontend, .noDriver], helpText: "Compare legacy DeclContext- to ASTScope-based unqualified name lookup (for debugging)")
public static let cxxInteropGettersSettersAsProperties: Option = Option("-cxx-interop-getters-setters-as-properties", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Import getters and setters as computed properties in Swift")
public static let cxxInteroperabilityMode: Option = Option("-cxx-interoperability-mode=", .joined, attributes: [.frontend, .moduleInterface], helpText: "Enables C++ interoperability; requires compatbility version to be specified.")
public static let cxxInteroperabilityMode: Option = Option("-cxx-interoperability-mode=", .joined, attributes: [.frontend, .moduleInterface], helpText: "Enables C++ interoperability; pass 'default' to enable or 'off' to disable")
public static let c: Option = Option("-c", .flag, alias: Option.emitObject, attributes: [.frontend, .noInteractive], group: .modes)
public static let debugAssertAfterParse: Option = Option("-debug-assert-after-parse", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Force an assertion failure after parsing", group: .debugCrash)
public static let debugAssertImmediately: Option = Option("-debug-assert-immediately", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Force an assertion failure immediately", group: .debugCrash)
Expand Down Expand Up @@ -136,6 +137,7 @@ extension Option {
public static let disableConformanceAvailabilityErrors: Option = Option("-disable-conformance-availability-errors", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Diagnose conformance availability violations as warnings")
public static let disableConstraintSolverPerformanceHacks: Option = Option("-disable-constraint-solver-performance-hacks", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable all the hacks in the constraint solver")
public static let disableCrossImportOverlays: Option = Option("-disable-cross-import-overlays", .flag, attributes: [.frontend, .noDriver], helpText: "Do not automatically import declared cross-import overlays.")
public static let cxxInteropDisableRequirementAtImport: Option = Option("-disable-cxx-interop-requirement-at-import", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Do not require C++ interoperability to be enabled when importing a Swift module that enables C++ interoperability")
public static let disableDebuggerShadowCopies: Option = Option("-disable-debugger-shadow-copies", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Disable debugger shadow copies of local variables.This option is only useful for testing the compiler.")
public static let disableDeserializationRecovery: Option = Option("-disable-deserialization-recovery", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Don't attempt to recover from missing xrefs (etc) in swiftmodules")
public static let disableDeserializationSafety: Option = Option("-disable-deserialization-safety", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Don't avoid reading potentially unsafe decls in swiftmodules")
Expand Down Expand Up @@ -384,6 +386,8 @@ extension Option {
public static let enableOperatorDesignatedTypes: Option = Option("-enable-operator-designated-types", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Enable operator designated types")
public static let enableOssaCompleteLifetimes: Option = Option("-enable-ossa-complete-lifetimes", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Require linear OSSA lifetimes after SILGen")
public static let enableOssaModules: Option = Option("-enable-ossa-modules", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Always serialize SIL in ossa form. If this flag is not passed in, when optimizing ownership will be lowered before serializing SIL")
public static let enablePackMetadataStackPromotion: Option = Option("-enable-pack-metadata-stack-promotion=", .joined, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "true|false", helpText: "Whether to skip heapifying stack metadata packs when possible.")
public static let enablePackMetadataStackPromotionNoArg: Option = Option("-enable-pack-metadata-stack-promotion", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Skip heapifying stack metadata packs when possible.")
public static let enablePrivateImports: Option = Option("-enable-private-imports", .flag, attributes: [.helpHidden, .frontend, .noInteractive], helpText: "Allows this module's internal and private API to be accessed")
public static let enableRelativeProtocolWitnessTables: Option = Option("-enable-relative-protocol-witness-tables", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Enable relative protocol witness tables")
public static let enableRemoveDeprecatedCheck: Option = Option("-enable-remove-deprecated-check", .flag, attributes: [.noDriver], helpText: "Diagnosing removal of deprecated symbols")
Expand Down Expand Up @@ -812,6 +816,7 @@ extension Option {
Option.BF,
Option.BIEQ,
Option.BI,
Option.blockListFile,
Option.breakageAllowlistPath,
Option.bridgingHeaderDirectoryForPrint,
Option.bsdk,
Expand Down Expand Up @@ -904,6 +909,7 @@ extension Option {
Option.disableConformanceAvailabilityErrors,
Option.disableConstraintSolverPerformanceHacks,
Option.disableCrossImportOverlays,
Option.cxxInteropDisableRequirementAtImport,
Option.disableDebuggerShadowCopies,
Option.disableDeserializationRecovery,
Option.disableDeserializationSafety,
Expand Down Expand Up @@ -1152,6 +1158,8 @@ extension Option {
Option.enableOperatorDesignatedTypes,
Option.enableOssaCompleteLifetimes,
Option.enableOssaModules,
Option.enablePackMetadataStackPromotion,
Option.enablePackMetadataStackPromotionNoArg,
Option.enablePrivateImports,
Option.enableRelativeProtocolWitnessTables,
Option.enableRemoveDeprecatedCheck,
Expand Down
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 @@ -6940,6 +6940,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 0b96083

Please sign in to comment.