Skip to content

Commit 580a281

Browse files
committed
[Clang importer] Enable API notes alongside header/frameworks.
Enable newly-introduced Clang functionality to load API notes stored alongside the headers for a module or, for a framework, in an APINotes subdirectory within the framework. Fixes rdar://problem/28455644.
1 parent e717571 commit 580a281

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

lib/ClangImporter/ClangImporter.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,13 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
474474

475475
const std::string &moduleCachePath = importerOpts.ModuleCachePath;
476476

477-
// Set the module cache path.
477+
// Set the module and API notes cache paths to the same location.
478478
if (!moduleCachePath.empty()) {
479479
invocationArgStrs.push_back("-fmodules-cache-path=");
480480
invocationArgStrs.back().append(moduleCachePath);
481+
482+
invocationArgStrs.push_back("-fapinotes-cache-path=");
483+
invocationArgStrs.back().append(moduleCachePath);
481484
}
482485

483486
if (importerOpts.DetailedPreprocessingRecord) {
@@ -562,6 +565,9 @@ addCommonInvocationArguments(std::vector<std::string> &invocationArgStrs,
562565
invocationArgStrs.push_back(extraArg);
563566
}
564567

568+
// Enable API notes alongside headers/in frameworks.
569+
invocationArgStrs.push_back("-fapinotes-modules");
570+
565571
// Add API notes paths.
566572
for (const auto &searchPath : searchPathOpts.ImportSearchPaths) {
567573
invocationArgStrs.push_back("-iapinotes-modules");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Name: APINotesFrameworkTest
2+
Functions:
3+
- Name: jumpToLocation
4+
SwiftName: 'jumpTo(x:y:z:)'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void jumpToLocation(int, int, int);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework module APINotesFrameworkTest {
2+
umbrella header "APINotesFrameworkTest.h"
3+
export *
4+
}

test/APINotes/basic.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// RUN: %target-parse-verify-swift -I %S/Inputs/custom-modules
1+
// RUN: %target-parse-verify-swift -I %S/Inputs/custom-modules -F %S/Inputs/custom-frameworks
22
import APINotesTest
3+
import APINotesFrameworkTest
34

45
func testSwiftName() {
56
moveTo(x: 0, y: 0, z: 0)
@@ -17,4 +18,8 @@ func testSwiftName() {
1718
let rect2: RectStruct // expected-error{{'RectStruct' has been renamed to 'Rect'}}
1819

1920
let d: Double = __will_be_private
21+
22+
// From APINotesFrameworkTest.
23+
jumpTo(x: 0, y: 0, z: 0)
24+
jumpTo(0, 0, 0) // expected-error{{missing argument labels 'x:y:z:' in call}}
2025
}

tools/driver/api_notes.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int apinotes_main(ArrayRef<const char *> Args) {
123123
llvm::raw_fd_ostream os(OutputFilename, EC,
124124
llvm::sys::fs::OpenFlags::F_None);
125125

126-
if (api_notes::compileAPINotes(input, os, targetOS))
126+
if (api_notes::compileAPINotes(input, /*sourceFile=*/nullptr, os, targetOS))
127127
return 1;
128128

129129
os.flush();

0 commit comments

Comments
 (0)