mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #65985 from cachemeifyoucan/eng/PR-109411245
[ObjcHeader] Fix objc header generation when pch is explicited passed
This commit is contained in:
@@ -404,6 +404,9 @@ public:
|
|||||||
/// if we need to persist a PCH for later reuse.
|
/// if we need to persist a PCH for later reuse.
|
||||||
bool canReadPCH(StringRef PCHFilename);
|
bool canReadPCH(StringRef PCHFilename);
|
||||||
|
|
||||||
|
/// Reads the original source file name from PCH.
|
||||||
|
std::string getOriginalSourceFile(StringRef PCHFilename);
|
||||||
|
|
||||||
/// Makes a temporary replica of the ClangImporter's CompilerInstance, reads a
|
/// Makes a temporary replica of the ClangImporter's CompilerInstance, reads a
|
||||||
/// module map into the replica and emits a PCM file for one of the modules it
|
/// module map into the replica and emits a PCM file for one of the modules it
|
||||||
/// declares. Delegates to clang for everything except construction of the
|
/// declares. Delegates to clang for everything except construction of the
|
||||||
|
|||||||
@@ -667,6 +667,9 @@ public:
|
|||||||
/// file.
|
/// file.
|
||||||
SourceFile *getIDEInspectionFile() const;
|
SourceFile *getIDEInspectionFile() const;
|
||||||
|
|
||||||
|
/// Retrieve the printing path for bridging header.
|
||||||
|
std::string getBridgingHeaderPath() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Set up the file system by loading and validating all VFS overlay YAML
|
/// Set up the file system by loading and validating all VFS overlay YAML
|
||||||
/// files. If the process of validating VFS files failed, or the overlay
|
/// files. If the process of validating VFS files failed, or the overlay
|
||||||
|
|||||||
@@ -920,6 +920,12 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
|
|||||||
llvm_unreachable("unhandled result");
|
llvm_unreachable("unhandled result");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ClangImporter::getOriginalSourceFile(StringRef PCHFilename) {
|
||||||
|
return clang::ASTReader::getOriginalSourceFile(
|
||||||
|
PCHFilename.str(), Impl.Instance->getFileManager(),
|
||||||
|
Impl.Instance->getPCHContainerReader(), Impl.Instance->getDiagnostics());
|
||||||
|
}
|
||||||
|
|
||||||
Optional<std::string>
|
Optional<std::string>
|
||||||
ClangImporter::getPCHFilename(const ClangImporterOptions &ImporterOptions,
|
ClangImporter::getPCHFilename(const ClangImporterOptions &ImporterOptions,
|
||||||
StringRef SwiftPCHHash, bool &isExplicit) {
|
StringRef SwiftPCHHash, bool &isExplicit) {
|
||||||
|
|||||||
@@ -818,6 +818,26 @@ SourceFile *CompilerInstance::getIDEInspectionFile() const {
|
|||||||
return evaluateOrDefault(eval, IDEInspectionFileRequest{mod}, nullptr);
|
return evaluateOrDefault(eval, IDEInspectionFileRequest{mod}, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool isPCHFilenameExtension(StringRef path) {
|
||||||
|
return llvm::sys::path::extension(path)
|
||||||
|
.endswith(file_types::getExtension(file_types::TY_PCH));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CompilerInstance::getBridgingHeaderPath() const {
|
||||||
|
const FrontendOptions &opts = Invocation.getFrontendOptions();
|
||||||
|
if (!isPCHFilenameExtension(opts.ImplicitObjCHeaderPath))
|
||||||
|
return opts.ImplicitObjCHeaderPath;
|
||||||
|
|
||||||
|
auto clangImporter =
|
||||||
|
static_cast<ClangImporter *>(getASTContext().getClangModuleLoader());
|
||||||
|
|
||||||
|
// No clang importer created. Report error?
|
||||||
|
if (!clangImporter)
|
||||||
|
return std::string();
|
||||||
|
|
||||||
|
return clangImporter->getOriginalSourceFile(opts.ImplicitObjCHeaderPath);
|
||||||
|
}
|
||||||
|
|
||||||
bool CompilerInstance::setUpInputs() {
|
bool CompilerInstance::setUpInputs() {
|
||||||
// Adds to InputSourceCodeBufferIDs, so may need to happen before the
|
// Adds to InputSourceCodeBufferIDs, so may need to happen before the
|
||||||
// per-input setup.
|
// per-input setup.
|
||||||
|
|||||||
@@ -912,17 +912,14 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
|
|||||||
|
|
||||||
if ((!Context.hadError() || opts.AllowModuleWithCompilerErrors) &&
|
if ((!Context.hadError() || opts.AllowModuleWithCompilerErrors) &&
|
||||||
opts.InputsAndOutputs.hasClangHeaderOutputPath()) {
|
opts.InputsAndOutputs.hasClangHeaderOutputPath()) {
|
||||||
std::string BridgingHeaderPathForPrint;
|
std::string BridgingHeaderPathForPrint = Instance.getBridgingHeaderPath();
|
||||||
if (!opts.ImplicitObjCHeaderPath.empty()) {
|
if (!BridgingHeaderPathForPrint.empty()) {
|
||||||
if (opts.BridgingHeaderDirForPrint.has_value()) {
|
if (opts.BridgingHeaderDirForPrint.has_value()) {
|
||||||
// User specified preferred directory for including, use that dir.
|
// User specified preferred directory for including, use that dir.
|
||||||
llvm::SmallString<32> Buffer(*opts.BridgingHeaderDirForPrint);
|
llvm::SmallString<32> Buffer(*opts.BridgingHeaderDirForPrint);
|
||||||
llvm::sys::path::append(Buffer,
|
llvm::sys::path::append(Buffer,
|
||||||
llvm::sys::path::filename(opts.ImplicitObjCHeaderPath));
|
llvm::sys::path::filename(BridgingHeaderPathForPrint));
|
||||||
BridgingHeaderPathForPrint = (std::string)Buffer;
|
BridgingHeaderPathForPrint = (std::string)Buffer;
|
||||||
} else {
|
|
||||||
// By default, include the given bridging header path directly.
|
|
||||||
BridgingHeaderPathForPrint = opts.ImplicitObjCHeaderPath;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hadAnyError |= printAsClangHeaderIfNeeded(
|
hadAnyError |= printAsClangHeaderIfNeeded(
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
@import Foundation;
|
||||||
|
|
||||||
|
@protocol TestProto
|
||||||
|
@property id strongProp;
|
||||||
|
@end
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#import <Foundation.h>
|
||||||
|
|
||||||
|
@interface ObjCClass : NSObject
|
||||||
|
|
||||||
|
- (nullable id)swiftMethod;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@@ -63,3 +63,8 @@ module objc_implementation {
|
|||||||
header "objc_implementation/objc_implementation.h"
|
header "objc_implementation/objc_implementation.h"
|
||||||
export *
|
export *
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module bridging_header {
|
||||||
|
header "bridging_header/bridging_header.h"
|
||||||
|
export *
|
||||||
|
}
|
||||||
|
|||||||
15
test/PrintAsObjC/bridging_header.swift
Normal file
15
test/PrintAsObjC/bridging_header.swift
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
// REQUIRES: objc_interop
|
||||||
|
|
||||||
|
// RUN: %empty-directory(%t)
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// RUN: %FileCheck %s --input-file %t/bridging_header-Swift.h
|
||||||
|
|
||||||
|
// CHECK: bridging_header-Bridging-Header.h
|
||||||
|
// CHECK-NOT: bridging-header.pch
|
||||||
|
|
||||||
|
@objc class Test : NSObject, TestProto {
|
||||||
|
var strongProp: Any?
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user