Merge pull request #40923 from hyp/emit-cxx-interface-option

[interop] add an option to emit C++ header interface for a module
This commit is contained in:
Alex Lorenz
2022-01-20 07:16:53 -08:00
committed by GitHub
16 changed files with 183 additions and 30 deletions

View File

@@ -186,6 +186,22 @@ static bool printAsObjCIfNeeded(StringRef outputPath, ModuleDecl *M,
});
}
/// Prints the C++ "generated header" interface for \p M to \p
/// outputPath.
///
/// ...unless \p outputPath is empty, in which case it does nothing.
///
/// \returns true if there were any errors
///
/// \see swift::printAsCxx
static bool printAsCxxIfNeeded(StringRef outputPath, ModuleDecl *M) {
if (outputPath.empty())
return false;
return withOutputFile(
M->getDiags(), outputPath,
[&](raw_ostream &os) -> bool { return printAsCXX(os, M); });
}
/// Prints the stable module interface for \p M to \p outputPath.
///
/// ...unless \p outputPath is empty, in which case it does nothing.
@@ -826,6 +842,12 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
Invocation.getObjCHeaderOutputPathForAtMostOnePrimary(),
Instance.getMainModule(), BridgingHeaderPathForPrint);
}
if ((!Context.hadError() || opts.AllowModuleWithCompilerErrors) &&
opts.InputsAndOutputs.hasCxxHeaderOutputPath()) {
hadAnyError |= printAsCxxIfNeeded(
Invocation.getCxxHeaderOutputPathForAtMostOnePrimary(),
Instance.getMainModule());
}
// Only want the header if there's been any errors, ie. there's not much
// point outputting a swiftinterface for an invalid module