diff --git a/Sources/SwiftDriver/Driver/Driver.swift b/Sources/SwiftDriver/Driver/Driver.swift index 75f853507..1bfe8c180 100644 --- a/Sources/SwiftDriver/Driver/Driver.swift +++ b/Sources/SwiftDriver/Driver/Driver.swift @@ -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 { diff --git a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift index 5eca363ba..39a2b51d9 100644 --- a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift +++ b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift @@ -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, diff --git a/Sources/SwiftOptions/Options.swift b/Sources/SwiftOptions/Options.swift index 762f2bfb0..6354da666 100644 --- a/Sources/SwiftOptions/Options.swift +++ b/Sources/SwiftOptions/Options.swift @@ -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: "", 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: "", 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") @@ -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) @@ -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") @@ -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") @@ -812,6 +816,7 @@ extension Option { Option.BF, Option.BIEQ, Option.BI, + Option.blockListFile, Option.breakageAllowlistPath, Option.bridgingHeaderDirectoryForPrint, Option.bsdk, @@ -904,6 +909,7 @@ extension Option { Option.disableConformanceAvailabilityErrors, Option.disableConstraintSolverPerformanceHacks, Option.disableCrossImportOverlays, + Option.cxxInteropDisableRequirementAtImport, Option.disableDebuggerShadowCopies, Option.disableDeserializationRecovery, Option.disableDeserializationSafety, @@ -1152,6 +1158,8 @@ extension Option { Option.enableOperatorDesignatedTypes, Option.enableOssaCompleteLifetimes, Option.enableOssaModules, + Option.enablePackMetadataStackPromotion, + Option.enablePackMetadataStackPromotionNoArg, Option.enablePrivateImports, Option.enableRelativeProtocolWitnessTables, Option.enableRemoveDeprecatedCheck, diff --git a/TestInputs/Dummy.xctoolchain/usr/local/lib/swift/blocklists/block-list1.yml b/TestInputs/Dummy.xctoolchain/usr/local/lib/swift/blocklists/block-list1.yml new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/TestInputs/Dummy.xctoolchain/usr/local/lib/swift/blocklists/block-list1.yml @@ -0,0 +1 @@ +--- diff --git a/TestInputs/Dummy.xctoolchain/usr/local/lib/swift/blocklists/block-list2.yaml b/TestInputs/Dummy.xctoolchain/usr/local/lib/swift/blocklists/block-list2.yaml new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/TestInputs/Dummy.xctoolchain/usr/local/lib/swift/blocklists/block-list2.yaml @@ -0,0 +1 @@ +--- diff --git a/TestInputs/Dummy.xctoolchain/usr/local/lib/swift/blocklists/block-list3.txt b/TestInputs/Dummy.xctoolchain/usr/local/lib/swift/blocklists/block-list3.txt new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/TestInputs/Dummy.xctoolchain/usr/local/lib/swift/blocklists/block-list3.txt @@ -0,0 +1 @@ +--- diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index d4b29e2f3..1998bd7c5 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -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"