Skip to content

Commit 778532d

Browse files
committed
TBDGen: Don't emit pretty-printed API descriptor JSON by default.
Instead, use the `%validate-json` lit substitution to validate and format the API descriptor file before running it through FileCheck. This allows us to avoid needing to introduce a dedicated frontend option just to control whether the output of -emit-api-descriptor is pretty printed.
1 parent e91580b commit 778532d

File tree

7 files changed

+15
-11
lines changed

7 files changed

+15
-11
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -810,11 +810,10 @@ static bool writeTBDIfNeeded(CompilerInstance &Instance) {
810810
}
811811

812812
static bool writeAPIDescriptor(ModuleDecl *M, StringRef OutputPath,
813-
llvm::vfs::OutputBackend &Backend,
814-
bool PrettyPrinted) {
813+
llvm::vfs::OutputBackend &Backend) {
815814
return withOutputPath(M->getDiags(), Backend, OutputPath,
816815
[&](raw_ostream &OS) -> bool {
817-
writeAPIJSONFile(M, OS, PrettyPrinted);
816+
writeAPIJSONFile(M, OS, /*PrettyPrinted=*/false);
818817
return false;
819818
});
820819
}
@@ -834,9 +833,8 @@ static bool writeAPIDescriptorIfNeeded(CompilerInstance &Instance) {
834833
const std::string &APIDescriptorPath =
835834
Invocation.getAPIDescriptorPathForWholeModule();
836835

837-
// FIXME: Need a frontend flag for pretty printing
838836
return writeAPIDescriptor(Instance.getMainModule(), APIDescriptorPath,
839-
Instance.getOutputBackend(), true);
837+
Instance.getOutputBackend());
840838
}
841839

842840
static bool performCompileStepsPostSILGen(CompilerInstance &Instance,

test/APIJSON/apigen.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// RUN: %empty-directory(%t/ModuleCache)
44
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -typecheck -parse-as-library -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5
55
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule -module-cache-path %t/ModuleCache | %FileCheck %s --check-prefixes=CHECK,CHECK-EXTRACT
6-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -typecheck -parse-as-library -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5 -emit-api-descriptor-path - | %FileCheck %s --check-prefixes=CHECK,CHECK-EMIT
6+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -typecheck -parse-as-library -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5 -emit-api-descriptor-path %t/api.json
7+
// RUN: %validate-json %t/api.json | %FileCheck %s --check-prefixes=CHECK,CHECK-EMIT
78

89
import Foundation
910

test/APIJSON/extension.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// RUN: %empty-directory(%t/ModuleCache)
44
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -typecheck -parse-as-library -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5
55
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule -module-cache-path %t/ModuleCache | %FileCheck %s --check-prefixes=CHECK,CHECK-EXTRACT
6-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -typecheck -parse-as-library -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5 -emit-api-descriptor-path - | %FileCheck %s --check-prefixes=CHECK,CHECK-EMIT
6+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -typecheck -parse-as-library -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5 -emit-api-descriptor-path %t/api.json
7+
// RUN: %validate-json %t/api.json | %FileCheck %s --check-prefixes=CHECK,CHECK-EMIT
78

89
import Foundation
910

test/APIJSON/non-objc-class.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// RUN: %empty-directory(%t/ModuleCache)
44
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -typecheck -parse-as-library -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5
55
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule -module-cache-path %t/ModuleCache | %FileCheck %s -check-prefixes=CHECK,CHECK-EXTRACT
6-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -typecheck -parse-as-library -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5 -emit-api-descriptor-path - | %FileCheck %s --check-prefixes=CHECK,CHECK-EMIT
6+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -typecheck -parse-as-library -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5 -emit-api-descriptor-path %t/api.json
7+
// RUN: %validate-json %t/api.json | %FileCheck %s --check-prefixes=CHECK,CHECK-EMIT
78

89
import Foundation
910

test/APIJSON/non-swift-api.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
// RUN: cp %S/Inputs/NativeDep.h %t/NativeDep.framework/Headers
66

77
// RUN: %target-swift-frontend %s -parse-as-library -emit-module -emit-module-interface-path %t/MyModule.swiftinterface -emit-module-path %t/MyModule.swiftmodule -F %t -enable-library-evolution -module-cache-path %t/cache -module-name MyModule -swift-version 5
8-
// RUN: %target-swift-frontend %s -parse-as-library -emit-module -emit-module-interface-path %t/MyModule.swiftinterface -emit-module-path %t/MyModule.swiftmodule -F %t -enable-library-evolution -module-cache-path %t/cache -module-name MyModule -swift-version 5 -emit-api-descriptor-path - | %FileCheck %s
8+
// RUN: %target-swift-frontend %s -parse-as-library -emit-module -emit-module-interface-path %t/MyModule.swiftinterface -emit-module-path %t/MyModule.swiftmodule -F %t -enable-library-evolution -module-cache-path %t/cache -module-name MyModule -swift-version 5 -emit-api-descriptor-path %t/api.json
9+
// RUN: %validate-json %t/api.json | %FileCheck %s
910

1011
/// Check that both swiftmodule and swiftinterface can be used as input.
1112
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftmodule -module-name MyModule -module-cache-path %t/cache -F %t | %FileCheck %s

test/APIJSON/spi.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -parse-as-library -emit-module -emit-module-path %t/MyModule.swiftmodule -enable-library-evolution -module-name MyModule -swift-version 5
88
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftmodule -module-name MyModule -module-cache-path %t/ModuleCache | %FileCheck %s --check-prefixes=CHECK-SPI,CHECK-SPI-EXTRACT
9-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -parse-as-library -emit-module -emit-module-path %t/MyModule.swiftmodule -enable-library-evolution -module-name MyModule -swift-version 5 -emit-api-descriptor-path - | %FileCheck %s --check-prefixes=CHECK-SPI,CHECK-SPI-EMIT
9+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) %s -parse-as-library -emit-module -emit-module-path %t/MyModule.swiftmodule -enable-library-evolution -module-name MyModule -swift-version 5 -emit-api-descriptor-path %t/api.json
10+
// RUN: %validate-json %t/api.json | %FileCheck %s --check-prefixes=CHECK-SPI,CHECK-SPI-EMIT
1011

1112
import Foundation
1213

test/APIJSON/struct.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// RUN: %empty-directory(%t/ModuleCache)
44
// RUN: %target-swift-frontend %s -typecheck -parse-as-library -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5
55
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule -module-cache-path %t/ModuleCache | %FileCheck %s --check-prefixes=CHECK,CHECK-EXTRACT
6-
// RUN: %target-swift-frontend %s -typecheck -parse-as-library -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5 -emit-api-descriptor-path - | %FileCheck %s --check-prefixes=CHECK,CHECK-EMIT
6+
// RUN: %target-swift-frontend %s -typecheck -parse-as-library -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5 -emit-api-descriptor-path %t/api.json
7+
// RUN: %validate-json %t/api.json | %FileCheck %s --check-prefixes=CHECK,CHECK-EMIT
78

89
// Struct has no objc data.
910
@available(macOS 10.13, *)

0 commit comments

Comments
 (0)