mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Add support for textual imports to -emit-objc-header
Currently headers produced with `-emit-objc-header` / `-emit-objc-header-path` produce headers that include modular imports. If the consumer wishes to operate without modules enabled, these headers cannot be used. This patch introduces a new flag (`-emit-clang-header-nonmodular-includes`) that when enabled attempts to argument each modular import included in such a header with a set of equivalent textual imports.
This commit is contained in:
@@ -69,6 +69,8 @@
|
||||
#include "swift/Subsystems.h"
|
||||
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
|
||||
|
||||
#include "clang/Lex/Preprocessor.h"
|
||||
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
@@ -164,17 +166,17 @@ static bool writeSIL(SILModule &SM, const PrimarySpecificPaths &PSPs,
|
||||
/// \returns true if there were any errors
|
||||
///
|
||||
/// \see swift::printAsClangHeader
|
||||
static bool printAsClangHeaderIfNeeded(StringRef outputPath, ModuleDecl *M,
|
||||
StringRef bridgingHeader,
|
||||
const FrontendOptions &frontendOpts,
|
||||
const IRGenOptions &irGenOpts) {
|
||||
static bool printAsClangHeaderIfNeeded(
|
||||
StringRef outputPath, ModuleDecl *M, StringRef bridgingHeader,
|
||||
const FrontendOptions &frontendOpts, const IRGenOptions &irGenOpts,
|
||||
clang::HeaderSearch &clangHeaderSearchInfo) {
|
||||
if (outputPath.empty())
|
||||
return false;
|
||||
return withOutputFile(M->getDiags(), outputPath,
|
||||
[&](raw_ostream &out) -> bool {
|
||||
return printAsClangHeader(out, M, bridgingHeader,
|
||||
frontendOpts, irGenOpts);
|
||||
});
|
||||
return withOutputFile(
|
||||
M->getDiags(), outputPath, [&](raw_ostream &out) -> bool {
|
||||
return printAsClangHeader(out, M, bridgingHeader, frontendOpts,
|
||||
irGenOpts, clangHeaderSearchInfo);
|
||||
});
|
||||
}
|
||||
|
||||
/// Prints the stable module interface for \p M to \p outputPath.
|
||||
@@ -925,7 +927,10 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
|
||||
hadAnyError |= printAsClangHeaderIfNeeded(
|
||||
Invocation.getClangHeaderOutputPathForAtMostOnePrimary(),
|
||||
Instance.getMainModule(), BridgingHeaderPathForPrint, opts,
|
||||
Invocation.getIRGenOptions());
|
||||
Invocation.getIRGenOptions(),
|
||||
Context.getClangModuleLoader()
|
||||
->getClangPreprocessor()
|
||||
.getHeaderSearchInfo());
|
||||
}
|
||||
|
||||
// Only want the header if there's been any errors, ie. there's not much
|
||||
|
||||
Reference in New Issue
Block a user