Skip to content

Commit 9904f9b

Browse files
[SR-14311] Error out when swift-api-extract failed to load module
Emit diagnostics and error out when swift-api-extract failed to load module.
1 parent dbea482 commit 9904f9b

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

test/APIJSON/Inputs/NativeDep.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void my_native_c ();

test/APIJSON/Inputs/module.modulemap

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework module NativeDep [extern_c] {
2+
umbrella header "NativeDep.h"
3+
export *
4+
}

test/APIJSON/non-swift-api.swift

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// REQUIRES: objc_interop, OS=macosx
2+
// RUN: %empty-directory(%t)
3+
// RUN: mkdir -p %t/NativeDep.framework/Headers %t/NativeDep.framework/Modules %t/cache
4+
// RUN: cp %S/Inputs/module.modulemap %t/NativeDep.framework/Modules
5+
// RUN: cp %S/Inputs/NativeDep.h %t/NativeDep.framework/Headers
6+
7+
// RUN: %target-swift-frontend %s -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+
9+
/// Check that both swiftmodule and swiftinterface can be used as input.
10+
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftmodule -module-name MyModule -module-cache-path %t/cache -F %t | %FileCheck %s
11+
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule -module-cache-path %t/cache -F %t | %FileCheck %s
12+
13+
/// Check that if a dependency is missing, error message is emitted and not crashed.
14+
// RUN: rm -rf %t/NativeDep.framework
15+
// RUN: not %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftmodule -module-name MyModule -module-cache-path %t/cache 2>&1 | %FileCheck %s --check-prefix=CHECK-ERROR
16+
17+
import NativeDep
18+
19+
public func callNative ()
20+
{
21+
my_native_c()
22+
}
23+
24+
// CHECK: "target": "x86_64-apple-macosx10.9",
25+
// CHECK-NEXT: "globals": [
26+
// CHECK-NEXT: {
27+
// CHECK-NEXT: "name": "_$s8MyModule10callNativeyyF",
28+
// CHECK-NEXT: "access": "public",
29+
30+
// CHECK-ERROR: error: missing required module 'NativeDep'

tools/driver/swift_api_extract_main.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class SwiftAPIExtractInvocation {
103103
}
104104
}
105105

106+
Invocation.getLangOptions().EnableModuleLoadingRemarks = true;
107+
106108
if (auto *A = ParsedArgs.getLastArg(OPT_sdk))
107109
Invocation.setSDKPath(A->getValue());
108110

@@ -207,6 +209,10 @@ class SwiftAPIExtractInvocation {
207209
return 1;
208210
}
209211

212+
// If there are errors emitted when loading module, exit with error.
213+
if (Instance.getASTContext().hadError())
214+
return 1;
215+
210216
if (OutputFilename == "-") {
211217
writeAPIJSONFile(M, llvm::outs(), PrettyPrint);
212218
return 0;

0 commit comments

Comments
 (0)