mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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.
This commit is contained in:
@@ -79,6 +79,10 @@ static llvm::cl::opt<std::string>
|
||||
OutputFile("o", llvm::cl::desc("Output file"),
|
||||
llvm::cl::cat(Category));
|
||||
|
||||
static llvm::cl::opt<std::string>
|
||||
OutputDir("output-dir", llvm::cl::desc("Directory path to where we dump the generated Json files"),
|
||||
llvm::cl::cat(Category));
|
||||
|
||||
static llvm::cl::opt<std::string>
|
||||
SDK("sdk", llvm::cl::desc("path to the SDK to build against"),
|
||||
llvm::cl::cat(Category));
|
||||
@@ -2713,8 +2717,10 @@ static std::string getDefaultBaselinePath(const char *Main, StringRef Module,
|
||||
return BaselinePath.str();
|
||||
}
|
||||
|
||||
static std::string getCustomBaselinePath(llvm::Triple Triple) {
|
||||
static std::string getCustomBaselinePath(llvm::Triple Triple, bool ABI) {
|
||||
llvm::SmallString<128> BaselinePath(options::BaselineDirPath);
|
||||
// Look for ABI or API baseline
|
||||
llvm::sys::path::append(BaselinePath, ABI? "ABI": "API");
|
||||
llvm::sys::path::append(BaselinePath, getBaselineFilename(Triple));
|
||||
return BaselinePath.str();
|
||||
}
|
||||
@@ -2736,7 +2742,8 @@ static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) {
|
||||
"Cannot find builtin baseline for more than one module");
|
||||
std::string Path;
|
||||
if (!options::BaselineDirPath.empty()) {
|
||||
Path = getCustomBaselinePath(Invok.getLangOptions().Target);
|
||||
Path = getCustomBaselinePath(Invok.getLangOptions().Target,
|
||||
Ctx.checkingABI());
|
||||
} else if (options::UseEmptyBaseline) {
|
||||
Path = getEmptyBaselinePath(Main);
|
||||
} else {
|
||||
@@ -2755,6 +2762,24 @@ static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) {
|
||||
return Collector.getSDKRoot();
|
||||
}
|
||||
|
||||
static std::string getJsonOutputFilePath(llvm::Triple Triple, bool ABI) {
|
||||
if (!options::OutputFile.empty())
|
||||
return options::OutputFile;
|
||||
if (!options::OutputDir.empty()) {
|
||||
llvm::SmallString<128> OutputPath(options::OutputDir);
|
||||
llvm::sys::path::append(OutputPath, ABI? "ABI": "API");
|
||||
if (!llvm::sys::fs::exists(OutputPath.str())) {
|
||||
llvm::errs() << "Baseline directory " << OutputPath.str()
|
||||
<< " doesn't exist\n";
|
||||
exit(1);
|
||||
}
|
||||
llvm::sys::path::append(OutputPath, getBaselineFilename(Triple));
|
||||
return OutputPath.str();
|
||||
}
|
||||
llvm::errs() << "Unable to decide output file path\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
PROGRAM_START(argc, argv);
|
||||
INITIALIZE_LLVM();
|
||||
@@ -2773,7 +2798,9 @@ int main(int argc, char *argv[]) {
|
||||
switch (options::Action) {
|
||||
case ActionType::DumpSDK:
|
||||
return (prepareForDump(argv[0], InitInvok, Modules)) ? 1 :
|
||||
dumpSDKContent(InitInvok, Modules, options::OutputFile, Opts);
|
||||
dumpSDKContent(InitInvok, Modules,
|
||||
getJsonOutputFilePath(InitInvok.getLangOptions().Target, Opts.ABI),
|
||||
Opts);
|
||||
case ActionType::MigratorGen:
|
||||
case ActionType::DiagnoseSDKs: {
|
||||
ComparisonInputMode Mode = checkComparisonInputMode();
|
||||
|
||||
Reference in New Issue
Block a user