Skip to content

Commit 8280358

Browse files
authored
Merge pull request #27021 from nkcsgexi/compare-empty-baselines
ABI/API checker: teach the tool to diagnose against a builtin empty baseline
2 parents c8a4125 + d8b611d commit 8280358

File tree

4 files changed

+46
-22
lines changed

4 files changed

+46
-22
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enum Color is a new API without @available attribute

test/api-digester/compare-dump.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
// RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.result.tmp
1313
// RUN: diff -u %t.expected %t.result.tmp
1414

15+
// Compare color against an empty baseline
16+
// RUN: %swift -emit-module -o %t.mod1/color.swiftmodule %S/Inputs/cake_baseline/color.swift -parse-as-library -enable-library-evolution -I %S/Inputs/APINotesLeft %clang-importer-sdk-nosource -module-name color
17+
// RUN: %api-digester -diagnose-sdk -o %t.result -empty-baseline -I %S/Inputs/APINotesLeft -I %t.mod1 %clang-importer-sdk-nosource -module color -abi
18+
// RUN: %clang -E -P -x c %S/Outputs/color_vs_empty.txt -o - | sed '/^\s*$/d' > %t.expected
19+
// RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.result.tmp
20+
// RUN: diff -u %t.expected %t.result.tmp
21+
1522
// Run another module API checking without -enable-library-evolution
1623
// RUN: %swift -emit-module -o %t.mod1/color.swiftmodule %S/Inputs/cake_baseline/color.swift -parse-as-library -I %S/Inputs/APINotesLeft %clang-importer-sdk-nosource -module-name color
1724
// RUN: %swift -emit-module -o %t.mod2/color.swiftmodule %S/Inputs/cake_current/color.swift -parse-as-library -I %S/Inputs/APINotesRight %clang-importer-sdk-nosource -module-name color

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ static llvm::cl::opt<std::string>
239239
BaselineFilePath("baseline-path",
240240
llvm::cl::desc("The path to the Json file that we should use as the baseline"),
241241
llvm::cl::cat(Category));
242+
243+
static llvm::cl::opt<bool>
244+
UseEmptyBaseline("empty-baseline",
245+
llvm::cl::desc("Use empty baseline for diagnostics"),
246+
llvm::cl::cat(Category));
242247
} // namespace options
243248

244249
namespace {
@@ -2570,28 +2575,33 @@ static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) {
25702575
llvm::SmallString<128> BaselinePath(ExePath);
25712576
llvm::sys::path::remove_filename(BaselinePath); // Remove /swift-api-digester
25722577
llvm::sys::path::remove_filename(BaselinePath); // Remove /bin
2573-
llvm::sys::path::append(BaselinePath, "lib", "swift", "FrameworkABIBaseline",
2574-
Modules.begin()->getKey());
2575-
// Look for ABI or API baseline
2576-
if (Ctx.checkingABI())
2577-
llvm::sys::path::append(BaselinePath, "ABI");
2578-
else
2579-
llvm::sys::path::append(BaselinePath, "API");
2580-
// Look for deployment target specific baseline files.
2581-
auto Triple = Invok.getLangOptions().Target;
2582-
if (Triple.isMacCatalystEnvironment())
2583-
llvm::sys::path::append(BaselinePath, "iosmac.json");
2584-
else if (Triple.isMacOSX())
2585-
llvm::sys::path::append(BaselinePath, "macos.json");
2586-
else if (Triple.isiOS())
2587-
llvm::sys::path::append(BaselinePath, "iphoneos.json");
2588-
else if (Triple.isTvOS())
2589-
llvm::sys::path::append(BaselinePath, "appletvos.json");
2590-
else if (Triple.isWatchOS())
2591-
llvm::sys::path::append(BaselinePath, "watchos.json");
2592-
else {
2593-
llvm::errs() << "Unsupported triple target\n";
2594-
exit(1);
2578+
llvm::sys::path::append(BaselinePath, "lib", "swift", "FrameworkABIBaseline");
2579+
if (options::UseEmptyBaseline) {
2580+
// Use the empty baseline for comparison.
2581+
llvm::sys::path::append(BaselinePath, "nil.json");
2582+
} else {
2583+
llvm::sys::path::append(BaselinePath, Modules.begin()->getKey());
2584+
// Look for ABI or API baseline
2585+
if (Ctx.checkingABI())
2586+
llvm::sys::path::append(BaselinePath, "ABI");
2587+
else
2588+
llvm::sys::path::append(BaselinePath, "API");
2589+
// Look for deployment target specific baseline files.
2590+
auto Triple = Invok.getLangOptions().Target;
2591+
if (Triple.isMacCatalystEnvironment())
2592+
llvm::sys::path::append(BaselinePath, "iosmac.json");
2593+
else if (Triple.isMacOSX())
2594+
llvm::sys::path::append(BaselinePath, "macos.json");
2595+
else if (Triple.isiOS())
2596+
llvm::sys::path::append(BaselinePath, "iphoneos.json");
2597+
else if (Triple.isTvOS())
2598+
llvm::sys::path::append(BaselinePath, "appletvos.json");
2599+
else if (Triple.isWatchOS())
2600+
llvm::sys::path::append(BaselinePath, "watchos.json");
2601+
else {
2602+
llvm::errs() << "Unsupported triple target\n";
2603+
exit(1);
2604+
}
25952605
}
25962606
StringRef Path = BaselinePath.str();
25972607
if (!fs::exists(Path)) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"kind": "Root",
3+
"name": "TopLevel",
4+
"printedName": "TopLevel",
5+
"json_format_version": 255
6+
}

0 commit comments

Comments
 (0)