File tree Expand file tree Collapse file tree 9 files changed +68
-6
lines changed Expand file tree Collapse file tree 9 files changed +68
-6
lines changed Original file line number Diff line number Diff line change @@ -404,6 +404,9 @@ class ClangImporter final : public ClangModuleLoader {
404
404
// / if we need to persist a PCH for later reuse.
405
405
bool canReadPCH (StringRef PCHFilename);
406
406
407
+ // / Reads the original source file name from PCH.
408
+ std::string getOriginalSourceFile (StringRef PCHFilename);
409
+
407
410
// / Makes a temporary replica of the ClangImporter's CompilerInstance, reads a
408
411
// / module map into the replica and emits a PCM file for one of the modules it
409
412
// / declares. Delegates to clang for everything except construction of the
Original file line number Diff line number Diff line change @@ -616,6 +616,9 @@ class CompilerInstance {
616
616
// / file.
617
617
SourceFile *getIDEInspectionFile () const ;
618
618
619
+ // / Retrieve the printing path for bridging header.
620
+ std::string getBridgingHeaderPath () const ;
621
+
619
622
private:
620
623
// / Set up the file system by loading and validating all VFS overlay YAML
621
624
// / files. If the process of validating VFS files failed, or the overlay
Original file line number Diff line number Diff line change @@ -913,6 +913,12 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
913
913
llvm_unreachable (" unhandled result" );
914
914
}
915
915
916
+ std::string ClangImporter::getOriginalSourceFile (StringRef PCHFilename) {
917
+ return clang::ASTReader::getOriginalSourceFile (
918
+ PCHFilename.str (), Impl.Instance ->getFileManager (),
919
+ Impl.Instance ->getPCHContainerReader (), Impl.Instance ->getDiagnostics ());
920
+ }
921
+
916
922
Optional<std::string>
917
923
ClangImporter::getPCHFilename (const ClangImporterOptions &ImporterOptions,
918
924
StringRef SwiftPCHHash, bool &isExplicit) {
Original file line number Diff line number Diff line change @@ -703,6 +703,26 @@ SourceFile *CompilerInstance::getIDEInspectionFile() const {
703
703
return evaluateOrDefault (eval, IDEInspectionFileRequest{mod}, nullptr );
704
704
}
705
705
706
+ static inline bool isPCHFilenameExtension (StringRef path) {
707
+ return llvm::sys::path::extension (path)
708
+ .endswith (file_types::getExtension (file_types::TY_PCH));
709
+ }
710
+
711
+ std::string CompilerInstance::getBridgingHeaderPath () const {
712
+ const FrontendOptions &opts = Invocation.getFrontendOptions ();
713
+ if (!isPCHFilenameExtension (opts.ImplicitObjCHeaderPath ))
714
+ return opts.ImplicitObjCHeaderPath ;
715
+
716
+ auto clangImporter =
717
+ static_cast <ClangImporter *>(getASTContext ().getClangModuleLoader ());
718
+
719
+ // No clang importer created. Report error?
720
+ if (!clangImporter)
721
+ return std::string ();
722
+
723
+ return clangImporter->getOriginalSourceFile (opts.ImplicitObjCHeaderPath );
724
+ }
725
+
706
726
bool CompilerInstance::setUpInputs () {
707
727
// Adds to InputSourceCodeBufferIDs, so may need to happen before the
708
728
// per-input setup.
Original file line number Diff line number Diff line change @@ -911,17 +911,14 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
911
911
912
912
if ((!Context.hadError () || opts.AllowModuleWithCompilerErrors ) &&
913
913
opts.InputsAndOutputs .hasClangHeaderOutputPath ()) {
914
- std::string BridgingHeaderPathForPrint;
915
- if (!opts. ImplicitObjCHeaderPath .empty ()) {
914
+ std::string BridgingHeaderPathForPrint = Instance. getBridgingHeaderPath () ;
915
+ if (!BridgingHeaderPathForPrint .empty ()) {
916
916
if (opts.BridgingHeaderDirForPrint .has_value ()) {
917
917
// User specified preferred directory for including, use that dir.
918
918
llvm::SmallString<32 > Buffer (*opts.BridgingHeaderDirForPrint );
919
919
llvm::sys::path::append (Buffer,
920
- llvm::sys::path::filename (opts. ImplicitObjCHeaderPath ));
920
+ llvm::sys::path::filename (BridgingHeaderPathForPrint ));
921
921
BridgingHeaderPathForPrint = (std::string)Buffer;
922
- } else {
923
- // By default, include the given bridging header path directly.
924
- BridgingHeaderPathForPrint = opts.ImplicitObjCHeaderPath ;
925
922
}
926
923
}
927
924
hadAnyError |= printAsClangHeaderIfNeeded (
Original file line number Diff line number Diff line change
1
+ @import Foundation;
2
+
3
+ @protocol TestProto
4
+ @property id strongProp;
5
+ @end
Original file line number Diff line number Diff line change
1
+ #import < Foundation.h>
2
+
3
+ @interface ObjCClass : NSObject
4
+
5
+ - (nullable id )swiftMethod ;
6
+
7
+ @end
8
+
Original file line number Diff line number Diff line change @@ -63,3 +63,8 @@ module objc_implementation {
63
63
header "objc_implementation/objc_implementation.h"
64
64
export *
65
65
}
66
+
67
+ module bridging_header {
68
+ header "bridging_header/bridging_header.h"
69
+ export *
70
+ }
Original file line number Diff line number Diff line change
1
+ // REQUIRES: objc_interop
2
+
3
+ // RUN: %empty-directory(%t)
4
+
5
+ // RUN: %target-swift-frontend(mock-sdk: -sdk %S/../Inputs/clang-importer-sdk -I %t) -emit-pch -o %t/bridging-header.pch %S/Inputs/bridging_header-Bridging-Header.h
6
+ // RUN: %target-swift-frontend(mock-sdk: -sdk %S/../Inputs/clang-importer-sdk -I %t) -emit-module -I %S/Inputs/custom-modules -import-objc-header %t/bridging-header.pch -import-underlying-module -o %t %s -disable-objc-attr-requires-foundation-module -emit-objc-header-path %t/bridging_header-Swift.h
7
+
8
+ // RUN: %FileCheck %s --input-file %t/bridging_header-Swift.h
9
+
10
+ // CHECK: bridging_header-Bridging-Header.h
11
+ // CHECK-NOT: bridging-header.pch
12
+
13
+ @objc class Test : NSObject , TestProto {
14
+ var strongProp : Any ?
15
+ }
You can’t perform that action at this time.
0 commit comments