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 @@ -403,6 +403,9 @@ class ClangImporter final : public ClangModuleLoader {
403
403
// / if we need to persist a PCH for later reuse.
404
404
bool canReadPCH (StringRef PCHFilename);
405
405
406
+ // / Reads the original source file name from PCH.
407
+ std::string getOriginalSourceFile (StringRef PCHFilename);
408
+
406
409
// / Makes a temporary replica of the ClangImporter's CompilerInstance, reads a
407
410
// / module map into the replica and emits a PCM file for one of the modules it
408
411
// / declares. Delegates to clang for everything except construction of the
Original file line number Diff line number Diff line change @@ -667,6 +667,9 @@ class CompilerInstance {
667
667
// / file.
668
668
SourceFile *getIDEInspectionFile () const ;
669
669
670
+ // / Retrieve the printing path for bridging header.
671
+ std::string getBridgingHeaderPath () const ;
672
+
670
673
private:
671
674
// / Set up the file system by loading and validating all VFS overlay YAML
672
675
// / files. If the process of validating VFS files failed, or the overlay
Original file line number Diff line number Diff line change @@ -915,6 +915,12 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
915
915
llvm_unreachable (" unhandled result" );
916
916
}
917
917
918
+ std::string ClangImporter::getOriginalSourceFile (StringRef PCHFilename) {
919
+ return clang::ASTReader::getOriginalSourceFile (
920
+ PCHFilename.str (), Impl.Instance ->getFileManager (),
921
+ Impl.Instance ->getPCHContainerReader (), Impl.Instance ->getDiagnostics ());
922
+ }
923
+
918
924
Optional<std::string>
919
925
ClangImporter::getPCHFilename (const ClangImporterOptions &ImporterOptions,
920
926
StringRef SwiftPCHHash, bool &isExplicit) {
Original file line number Diff line number Diff line change @@ -818,6 +818,26 @@ SourceFile *CompilerInstance::getIDEInspectionFile() const {
818
818
return evaluateOrDefault (eval, IDEInspectionFileRequest{mod}, nullptr );
819
819
}
820
820
821
+ static inline bool isPCHFilenameExtension (StringRef path) {
822
+ return llvm::sys::path::extension (path)
823
+ .endswith (file_types::getExtension (file_types::TY_PCH));
824
+ }
825
+
826
+ std::string CompilerInstance::getBridgingHeaderPath () const {
827
+ const FrontendOptions &opts = Invocation.getFrontendOptions ();
828
+ if (!isPCHFilenameExtension (opts.ImplicitObjCHeaderPath ))
829
+ return opts.ImplicitObjCHeaderPath ;
830
+
831
+ auto clangImporter =
832
+ static_cast <ClangImporter *>(getASTContext ().getClangModuleLoader ());
833
+
834
+ // No clang importer created. Report error?
835
+ if (!clangImporter)
836
+ return std::string ();
837
+
838
+ return clangImporter->getOriginalSourceFile (opts.ImplicitObjCHeaderPath );
839
+ }
840
+
821
841
bool CompilerInstance::setUpInputs () {
822
842
// Adds to InputSourceCodeBufferIDs, so may need to happen before the
823
843
// per-input setup.
Original file line number Diff line number Diff line change @@ -912,17 +912,14 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
912
912
913
913
if ((!Context.hadError () || opts.AllowModuleWithCompilerErrors ) &&
914
914
opts.InputsAndOutputs .hasClangHeaderOutputPath ()) {
915
- std::string BridgingHeaderPathForPrint;
916
- if (!opts. ImplicitObjCHeaderPath .empty ()) {
915
+ std::string BridgingHeaderPathForPrint = Instance. getBridgingHeaderPath () ;
916
+ if (!BridgingHeaderPathForPrint .empty ()) {
917
917
if (opts.BridgingHeaderDirForPrint .has_value ()) {
918
918
// User specified preferred directory for including, use that dir.
919
919
llvm::SmallString<32 > Buffer (*opts.BridgingHeaderDirForPrint );
920
920
llvm::sys::path::append (Buffer,
921
- llvm::sys::path::filename (opts. ImplicitObjCHeaderPath ));
921
+ llvm::sys::path::filename (BridgingHeaderPathForPrint ));
922
922
BridgingHeaderPathForPrint = (std::string)Buffer;
923
- } else {
924
- // By default, include the given bridging header path directly.
925
- BridgingHeaderPathForPrint = opts.ImplicitObjCHeaderPath ;
926
923
}
927
924
}
928
925
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