@@ -244,6 +244,11 @@ BaselineFilePath("baseline-path",
244
244
llvm::cl::desc (" The path to the Json file that we should use as the baseline" ),
245
245
llvm::cl::cat(Category));
246
246
247
+ static llvm::cl::opt<std::string>
248
+ BaselineDirPath (" baseline-dir" ,
249
+ llvm::cl::desc (" The path to a directory containing baseline files: macos.json, iphoneos.json, appletvos.json, watchos.json, and iosmac.json" ),
250
+ llvm::cl::cat(Category));
251
+
247
252
static llvm::cl::opt<bool >
248
253
UseEmptyBaseline (" empty-baseline" ,
249
254
llvm::cl::desc (" Use empty baseline for diagnostics" ),
@@ -2662,6 +2667,58 @@ static ComparisonInputMode checkComparisonInputMode() {
2662
2667
return ComparisonInputMode::BaselineJson;
2663
2668
}
2664
2669
2670
+ static std::string getDefaultBaselineDir (const char *Main) {
2671
+ llvm::SmallString<128 > BaselineDir;
2672
+ // The path of the swift-api-digester executable.
2673
+ std::string ExePath = llvm::sys::fs::getMainExecutable (Main,
2674
+ reinterpret_cast <void *>(&anchorForGetMainExecutable));
2675
+ BaselineDir.append (ExePath);
2676
+ llvm::sys::path::remove_filename (BaselineDir); // Remove /swift-api-digester
2677
+ llvm::sys::path::remove_filename (BaselineDir); // Remove /bin
2678
+ llvm::sys::path::append (BaselineDir, " lib" , " swift" , " FrameworkABIBaseline" );
2679
+ return BaselineDir.str ();
2680
+ }
2681
+
2682
+ static std::string getEmptyBaselinePath (const char *Main) {
2683
+ llvm::SmallString<128 > BaselinePath (getDefaultBaselineDir (Main));
2684
+ llvm::sys::path::append (BaselinePath, " nil.json" );
2685
+ return BaselinePath.str ();
2686
+ }
2687
+
2688
+ static StringRef getBaselineFilename (llvm::Triple Triple) {
2689
+ if (Triple.isMacCatalystEnvironment ())
2690
+ return " iosmac.json" ;
2691
+ else if (Triple.isMacOSX ())
2692
+ return " macos.json" ;
2693
+ else if (Triple.isiOS ())
2694
+ return " iphoneos.json" ;
2695
+ else if (Triple.isTvOS ())
2696
+ return " appletvos.json" ;
2697
+ else if (Triple.isWatchOS ())
2698
+ return " watchos.json" ;
2699
+ else {
2700
+ llvm::errs () << " Unsupported triple target\n " ;
2701
+ exit (1 );
2702
+ }
2703
+ }
2704
+
2705
+ static std::string getDefaultBaselinePath (const char *Main, StringRef Module,
2706
+ llvm::Triple Triple,
2707
+ bool ABI) {
2708
+ llvm::SmallString<128 > BaselinePath (getDefaultBaselineDir (Main));
2709
+ llvm::sys::path::append (BaselinePath, Module);
2710
+ // Look for ABI or API baseline
2711
+ llvm::sys::path::append (BaselinePath, ABI? " ABI" : " API" );
2712
+ llvm::sys::path::append (BaselinePath, getBaselineFilename (Triple));
2713
+ return BaselinePath.str ();
2714
+ }
2715
+
2716
+ static std::string getCustomBaselinePath (llvm::Triple Triple) {
2717
+ llvm::SmallString<128 > BaselinePath (options::BaselineDirPath);
2718
+ llvm::sys::path::append (BaselinePath, getBaselineFilename (Triple));
2719
+ return BaselinePath.str ();
2720
+ }
2721
+
2665
2722
static SDKNodeRoot *getBaselineFromJson (const char *Main, SDKContext &Ctx) {
2666
2723
SwiftDeclCollector Collector (Ctx);
2667
2724
// If the baseline path has been given, honor that.
@@ -2677,41 +2734,16 @@ static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) {
2677
2734
2678
2735
assert (Modules.size () == 1 &&
2679
2736
" Cannot find builtin baseline for more than one module" );
2680
- // The path of the swift-api-digester executable.
2681
- std::string ExePath = llvm::sys::fs::getMainExecutable (Main,
2682
- reinterpret_cast <void *>(&anchorForGetMainExecutable));
2683
- llvm::SmallString<128 > BaselinePath (ExePath);
2684
- llvm::sys::path::remove_filename (BaselinePath); // Remove /swift-api-digester
2685
- llvm::sys::path::remove_filename (BaselinePath); // Remove /bin
2686
- llvm::sys::path::append (BaselinePath, " lib" , " swift" , " FrameworkABIBaseline" );
2687
- if (options::UseEmptyBaseline) {
2688
- // Use the empty baseline for comparison.
2689
- llvm::sys::path::append (BaselinePath, " nil.json" );
2737
+ std::string Path;
2738
+ if (!options::BaselineDirPath.empty ()) {
2739
+ Path = getCustomBaselinePath (Invok.getLangOptions ().Target );
2740
+ } else if (options::UseEmptyBaseline) {
2741
+ Path = getEmptyBaselinePath (Main);
2690
2742
} else {
2691
- llvm::sys::path::append (BaselinePath, Modules.begin ()->getKey ());
2692
- // Look for ABI or API baseline
2693
- if (Ctx.checkingABI ())
2694
- llvm::sys::path::append (BaselinePath, " ABI" );
2695
- else
2696
- llvm::sys::path::append (BaselinePath, " API" );
2697
- // Look for deployment target specific baseline files.
2698
- auto Triple = Invok.getLangOptions ().Target ;
2699
- if (Triple.isMacCatalystEnvironment ())
2700
- llvm::sys::path::append (BaselinePath, " iosmac.json" );
2701
- else if (Triple.isMacOSX ())
2702
- llvm::sys::path::append (BaselinePath, " macos.json" );
2703
- else if (Triple.isiOS ())
2704
- llvm::sys::path::append (BaselinePath, " iphoneos.json" );
2705
- else if (Triple.isTvOS ())
2706
- llvm::sys::path::append (BaselinePath, " appletvos.json" );
2707
- else if (Triple.isWatchOS ())
2708
- llvm::sys::path::append (BaselinePath, " watchos.json" );
2709
- else {
2710
- llvm::errs () << " Unsupported triple target\n " ;
2711
- exit (1 );
2712
- }
2743
+ Path = getDefaultBaselinePath (Main, Modules.begin ()->getKey (),
2744
+ Invok.getLangOptions ().Target ,
2745
+ Ctx.checkingABI ());
2713
2746
}
2714
- StringRef Path = BaselinePath.str ();
2715
2747
if (!fs::exists (Path)) {
2716
2748
llvm::errs () << " Baseline at " << Path << " does not exist\n " ;
2717
2749
exit (1 );
0 commit comments