Skip to content

Commit c68c123

Browse files
committed
ABI-checker: add an option to dump generated baselines into a directory. NFC
Using a directory instead of an exact file name for the generated baseline allows the tool to use target triple as file name, which is expected by the diagnostic phase.
1 parent ea142db commit c68c123

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

test/api-digester/compare-dump-abi.swift

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
// RUN: %empty-directory(%t.mod2)
33
// RUN: %empty-directory(%t.sdk)
44
// RUN: %empty-directory(%t.module-cache)
5-
// RUN: %swift -emit-module -o %t.mod1/cake.swiftmodule %S/Inputs/cake_baseline/cake.swift -parse-as-library -enable-library-evolution -I %S/Inputs/APINotesLeft %clang-importer-sdk-nosource -emit-module-source-info -emit-module-source-info-path %t.mod1/cake.swiftsourceinfo
5+
// RUN: %empty-directory(%t.baseline)
6+
// RUN: %empty-directory(%t.baseline/ABI)
7+
8+
// RUN: %swift -emit-module -o %t.mod1/cake.swiftmodule %S/Inputs/cake_baseline/cake.swift -parse-as-library -enable-library-evolution -I %S/Inputs/APINotesLeft %clang-importer-sdk-nosource -emit-module-source-info -emit-module-source-info-path %t.mod1/cake.swiftsourceinfo 2> %t.compiler-diags
69
// RUN: %swift -emit-module -o %t.mod2/cake.swiftmodule %S/Inputs/cake_current/cake.swift -parse-as-library -enable-library-evolution -I %S/Inputs/APINotesRight %clang-importer-sdk-nosource -emit-module-source-info -emit-module-source-info-path %t.mod2/cake.swiftsourceinfo
7-
// RUN: %api-digester -dump-sdk -module cake -o %t.dump1.json -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %t.mod1 -I %S/Inputs/APINotesLeft -abi
8-
// RUN: %api-digester -diagnose-sdk -print-module -baseline-path %t.dump1.json -module cake -I %t.mod2 -I %S/Inputs/APINotesLeft -module-cache-path %t.module-cache %clang-importer-sdk-nosource -abi -o %t.result
9-
// RUN: %clang -E -P -x c %S/Outputs/Cake-abi.txt -o - | sed '/^\s*$/d' > %t.abi.expected
10-
// RUN: %clang -E -P -x c %t.result -o - | sed '/^\s*$/d' > %t.abi.result.tmp
10+
// RUN: %api-digester -dump-sdk -module cake -output-dir %t.baseline -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %t.mod1 -I %S/Inputs/APINotesLeft -abi
11+
// RUN: %api-digester -diagnose-sdk -print-module -baseline-dir %t.baseline -module cake -I %t.mod2 -I %S/Inputs/APINotesLeft -module-cache-path %t.module-cache %clang-importer-sdk-nosource -abi -o %t.result
12+
// RUN: %clang -E -P -w -x c %S/Outputs/Cake-abi.txt -o - | sed '/^\s*$/d' > %t.abi.expected
13+
// RUN: %clang -E -P -w -x c %t.result -o - | sed '/^\s*$/d' > %t.abi.result.tmp
1114
// RUN: diff -u %t.abi.expected %t.abi.result.tmp
1215

1316
// A compiler-style diag to ensure we have source locations associated with breakages.

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

+30-3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ static llvm::cl::opt<std::string>
7979
OutputFile("o", llvm::cl::desc("Output file"),
8080
llvm::cl::cat(Category));
8181

82+
static llvm::cl::opt<std::string>
83+
OutputDir("output-dir", llvm::cl::desc("Directory path to where we dump the generated Json files"),
84+
llvm::cl::cat(Category));
85+
8286
static llvm::cl::opt<std::string>
8387
SDK("sdk", llvm::cl::desc("path to the SDK to build against"),
8488
llvm::cl::cat(Category));
@@ -2713,8 +2717,10 @@ static std::string getDefaultBaselinePath(const char *Main, StringRef Module,
27132717
return BaselinePath.str();
27142718
}
27152719

2716-
static std::string getCustomBaselinePath(llvm::Triple Triple) {
2720+
static std::string getCustomBaselinePath(llvm::Triple Triple, bool ABI) {
27172721
llvm::SmallString<128> BaselinePath(options::BaselineDirPath);
2722+
// Look for ABI or API baseline
2723+
llvm::sys::path::append(BaselinePath, ABI? "ABI": "API");
27182724
llvm::sys::path::append(BaselinePath, getBaselineFilename(Triple));
27192725
return BaselinePath.str();
27202726
}
@@ -2736,7 +2742,8 @@ static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) {
27362742
"Cannot find builtin baseline for more than one module");
27372743
std::string Path;
27382744
if (!options::BaselineDirPath.empty()) {
2739-
Path = getCustomBaselinePath(Invok.getLangOptions().Target);
2745+
Path = getCustomBaselinePath(Invok.getLangOptions().Target,
2746+
Ctx.checkingABI());
27402747
} else if (options::UseEmptyBaseline) {
27412748
Path = getEmptyBaselinePath(Main);
27422749
} else {
@@ -2755,6 +2762,24 @@ static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) {
27552762
return Collector.getSDKRoot();
27562763
}
27572764

2765+
static std::string getJsonOutputFilePath(llvm::Triple Triple, bool ABI) {
2766+
if (!options::OutputFile.empty())
2767+
return options::OutputFile;
2768+
if (!options::OutputDir.empty()) {
2769+
llvm::SmallString<128> OutputPath(options::OutputDir);
2770+
llvm::sys::path::append(OutputPath, ABI? "ABI": "API");
2771+
if (!llvm::sys::fs::exists(OutputPath.str())) {
2772+
llvm::errs() << "Baseline directory " << OutputPath.str()
2773+
<< " doesn't exist\n";
2774+
exit(1);
2775+
}
2776+
llvm::sys::path::append(OutputPath, getBaselineFilename(Triple));
2777+
return OutputPath.str();
2778+
}
2779+
llvm::errs() << "Unable to decide output file path\n";
2780+
exit(1);
2781+
}
2782+
27582783
int main(int argc, char *argv[]) {
27592784
PROGRAM_START(argc, argv);
27602785
INITIALIZE_LLVM();
@@ -2773,7 +2798,9 @@ int main(int argc, char *argv[]) {
27732798
switch (options::Action) {
27742799
case ActionType::DumpSDK:
27752800
return (prepareForDump(argv[0], InitInvok, Modules)) ? 1 :
2776-
dumpSDKContent(InitInvok, Modules, options::OutputFile, Opts);
2801+
dumpSDKContent(InitInvok, Modules,
2802+
getJsonOutputFilePath(InitInvok.getLangOptions().Target, Opts.ABI),
2803+
Opts);
27772804
case ActionType::MigratorGen:
27782805
case ActionType::DiagnoseSDKs: {
27792806
ComparisonInputMode Mode = checkComparisonInputMode();

0 commit comments

Comments
 (0)