Skip to content

Commit 6153130

Browse files
committed
Add ignorable private flag to driver to match changes in frontend
Resolves rdar://107638447
1 parent 0dfb2b7 commit 6153130

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,27 @@ import struct TSCBasic.RelativePath
2323
import var TSCBasic.localFileSystem
2424
import var TSCBasic.stderrStream
2525

26-
func getModuleFlags(_ path: VirtualPath, _ ignorable: Bool) throws -> [String] {
26+
enum InterfaceFlagKind {
27+
case regular, ignorable, ignorablePrivate
28+
29+
var string: String {
30+
switch self {
31+
case .regular:
32+
return "swift-module-flags"
33+
case .ignorable:
34+
return "swift-module-flags-ignorable"
35+
case .ignorablePrivate:
36+
return "swift-module-flags-ignorable-private"
37+
}
38+
}
39+
}
40+
41+
func getModuleFlags(_ path: VirtualPath,
42+
_ flagKind: InterfaceFlagKind) throws -> [String] {
2743
let data = try localFileSystem.readFileContents(path).cString
2844
let myStrings = data.components(separatedBy: .newlines)
29-
let prefix = ignorable ? "// swift-module-flags-ignorable: " : "// swift-module-flags: "
45+
46+
let prefix = "// " + flagKind.string + ": "
3047
if let argLine = myStrings.first(where: { $0.hasPrefix(prefix) }) {
3148
return argLine.dropFirst(prefix.count).components(separatedBy: " ")
3249
}
@@ -35,8 +52,9 @@ func getModuleFlags(_ path: VirtualPath, _ ignorable: Bool) throws -> [String] {
3552

3653
@_spi(Testing) public func getAllModuleFlags(_ path: VirtualPath) throws -> [String] {
3754
var allFlags: [String] = []
38-
allFlags.append(contentsOf: try getModuleFlags(path, true))
39-
allFlags.append(contentsOf: try getModuleFlags(path, false))
55+
allFlags.append(contentsOf: try getModuleFlags(path, .regular))
56+
allFlags.append(contentsOf: try getModuleFlags(path, .ignorable))
57+
allFlags.append(contentsOf: try getModuleFlags(path, .ignorablePrivate))
4058
return allFlags;
4159
}
4260

Sources/makeOptions/makeOptions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ enum SwiftFlags {
6464
SwiftAPIDigesterOption = (1 << 17),
6565
NewDriverOnlyOption = (1 << 18),
6666
ModuleInterfaceOptionIgnorable = (1 << 19),
67+
ModuleInterfaceOptionIgnorablePrivate = (1 << 20),
6768
};
6869

6970
static std::set<std::string> swiftKeywords = { "internal", "static" };

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6419,6 +6419,21 @@ final class SwiftDriverTests: XCTestCase {
64196419
}
64206420
}
64216421

6422+
func testExtractPackageName() throws {
6423+
try withTemporaryFile { file in
6424+
try localFileSystem.writeFileContents(file.path) {
6425+
$0 <<< "// swift-module-flags: -target arm64e-apple-macos12.0" <<< "\n"
6426+
$0 <<< "// swift-module-flags-ignorable: -library-level api"
6427+
$0 <<< "// swift-module-flags-ignorable-private: -package-name myPkg"
6428+
}
6429+
let flags = try getAllModuleFlags(VirtualPath.absolute(file.path))
6430+
let idx = flags.firstIndex(of: "-package-name")
6431+
XCTAssertNotNil(idx)
6432+
XCTAssert(idx! + 1 < flags.count)
6433+
XCTAssertEqual(flags[idx! + 1], "myPkg")
6434+
}
6435+
}
6436+
64226437
func testExtractLibraryLevel() throws {
64236438
try withTemporaryFile { file in
64246439
try localFileSystem.writeFileContents(file.path) { $0 <<< "// swift-module-flags: -library-level api" }

0 commit comments

Comments
 (0)