@@ -79,6 +79,10 @@ static llvm::cl::opt<std::string>
7979OutputFile (" 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+
8286static llvm::cl::opt<std::string>
8387SDK (" 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 ().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 ().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+
27582783int 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