Skip to content

ABI/API checker: teach the tool to diagnose against a builtin empty baseline #27021

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

Merged
merged 1 commit into from
Sep 4, 2019
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
1 change: 1 addition & 0 deletions test/api-digester/Outputs/color_vs_empty.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enum Color is a new API without @available attribute
7 changes: 7 additions & 0 deletions test/api-digester/compare-dump.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
// RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.result.tmp
// RUN: diff -u %t.expected %t.result.tmp

// Compare color against an empty baseline
// 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
// RUN: %api-digester -diagnose-sdk -o %t.result -empty-baseline -I %S/Inputs/APINotesLeft -I %t.mod1 %clang-importer-sdk-nosource -module color -abi
// RUN: %clang -E -P -x c %S/Outputs/color_vs_empty.txt -o - | sed '/^\s*$/d' > %t.expected
// RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.result.tmp
// RUN: diff -u %t.expected %t.result.tmp

// Run another module API checking without -enable-library-evolution
// 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
// 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
Expand Down
54 changes: 32 additions & 22 deletions tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ static llvm::cl::opt<std::string>
BaselineFilePath("baseline-path",
llvm::cl::desc("The path to the Json file that we should use as the baseline"),
llvm::cl::cat(Category));

static llvm::cl::opt<bool>
UseEmptyBaseline("empty-baseline",
llvm::cl::desc("Use empty baseline for diagnostics"),
llvm::cl::cat(Category));
} // namespace options

namespace {
Expand Down Expand Up @@ -2570,28 +2575,33 @@ static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) {
llvm::SmallString<128> BaselinePath(ExePath);
llvm::sys::path::remove_filename(BaselinePath); // Remove /swift-api-digester
llvm::sys::path::remove_filename(BaselinePath); // Remove /bin
llvm::sys::path::append(BaselinePath, "lib", "swift", "FrameworkABIBaseline",
Modules.begin()->getKey());
// Look for ABI or API baseline
if (Ctx.checkingABI())
llvm::sys::path::append(BaselinePath, "ABI");
else
llvm::sys::path::append(BaselinePath, "API");
// Look for deployment target specific baseline files.
auto Triple = Invok.getLangOptions().Target;
if (Triple.isMacCatalystEnvironment())
llvm::sys::path::append(BaselinePath, "iosmac.json");
else if (Triple.isMacOSX())
llvm::sys::path::append(BaselinePath, "macos.json");
else if (Triple.isiOS())
llvm::sys::path::append(BaselinePath, "iphoneos.json");
else if (Triple.isTvOS())
llvm::sys::path::append(BaselinePath, "appletvos.json");
else if (Triple.isWatchOS())
llvm::sys::path::append(BaselinePath, "watchos.json");
else {
llvm::errs() << "Unsupported triple target\n";
exit(1);
llvm::sys::path::append(BaselinePath, "lib", "swift", "FrameworkABIBaseline");
if (options::UseEmptyBaseline) {
// Use the empty baseline for comparison.
llvm::sys::path::append(BaselinePath, "nil.json");
} else {
llvm::sys::path::append(BaselinePath, Modules.begin()->getKey());
// Look for ABI or API baseline
if (Ctx.checkingABI())
llvm::sys::path::append(BaselinePath, "ABI");
else
llvm::sys::path::append(BaselinePath, "API");
// Look for deployment target specific baseline files.
auto Triple = Invok.getLangOptions().Target;
if (Triple.isMacCatalystEnvironment())
llvm::sys::path::append(BaselinePath, "iosmac.json");
else if (Triple.isMacOSX())
llvm::sys::path::append(BaselinePath, "macos.json");
else if (Triple.isiOS())
llvm::sys::path::append(BaselinePath, "iphoneos.json");
else if (Triple.isTvOS())
llvm::sys::path::append(BaselinePath, "appletvos.json");
else if (Triple.isWatchOS())
llvm::sys::path::append(BaselinePath, "watchos.json");
else {
llvm::errs() << "Unsupported triple target\n";
exit(1);
}
}
StringRef Path = BaselinePath.str();
if (!fs::exists(Path)) {
Expand Down
6 changes: 6 additions & 0 deletions utils/api_checker/FrameworkABIBaseline/nil.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"kind": "Root",
"name": "TopLevel",
"printedName": "TopLevel",
"json_format_version": 255
}