Skip to content

Commit 1a32db9

Browse files
authored
Merge pull request swiftlang#30366 from nkcsgexi/59110975
PrintAsObjC: allow users to specify bridging header relative path for printing
2 parents 1d95b83 + df0493c commit 1a32db9

File tree

6 files changed

+46
-2
lines changed

6 files changed

+46
-2
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ class FrontendOptions {
266266
/// Should we enable the dependency verifier for all primary files known to this frontend?
267267
bool EnableIncrementalDependencyVerifier = false;
268268

269+
/// The directory path we should use when print #include for the bridging header.
270+
/// By default, we include ImplicitObjCHeaderPath directly.
271+
llvm::Optional<std::string> BridgingHeaderDirForPrint;
272+
269273
/// The different modes for validating TBD against the LLVM IR.
270274
enum class TBDValidationMode {
271275
Default, ///< Do the default validation for the current platform.

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,4 +687,8 @@ def disable_type_layouts : Flag<["-"], "disable-type-layout">,
687687

688688
def disable_interface_lockfile : Flag<["-"], "disable-interface-lock">,
689689
HelpText<"Don't lock interface file when building module">;
690+
691+
def bridging_header_directory_for_print: Separate<["-"], "bridging-header-directory-for-print">, MetaVarName<"<path>">,
692+
HelpText<"Directory for bridging header to be printed in compatibility header">;
693+
690694
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ bool ArgsToFrontendOptionsConverter::convert(
6363
if (const Arg *A = Args.getLastArg(OPT_prebuilt_module_cache_path)) {
6464
Opts.PrebuiltModuleCachePath = A->getValue();
6565
}
66-
66+
if (const Arg *A = Args.getLastArg(OPT_bridging_header_directory_for_print)) {
67+
Opts.BridgingHeaderDirForPrint = A->getValue();
68+
}
6769
Opts.IndexSystemModules |= Args.hasArg(OPT_index_system_modules);
6870

6971
Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil);

lib/FrontendTool/FrontendTool.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,9 +1174,22 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
11741174
bool hadAnyError = false;
11751175

11761176
if (opts.InputsAndOutputs.hasObjCHeaderOutputPath()) {
1177+
std::string BridgingHeaderPathForPrint;
1178+
if (!opts.ImplicitObjCHeaderPath.empty()) {
1179+
if (opts.BridgingHeaderDirForPrint.hasValue()) {
1180+
// User specified preferred directory for including, use that dir.
1181+
llvm::SmallString<32> Buffer(*opts.BridgingHeaderDirForPrint);
1182+
llvm::sys::path::append(Buffer,
1183+
llvm::sys::path::filename(opts.ImplicitObjCHeaderPath));
1184+
BridgingHeaderPathForPrint = Buffer.str();
1185+
} else {
1186+
// By default, include the given bridging header path directly.
1187+
BridgingHeaderPathForPrint = opts.ImplicitObjCHeaderPath;
1188+
}
1189+
}
11771190
hadAnyError |= printAsObjCIfNeeded(
11781191
Invocation.getObjCHeaderOutputPathForAtMostOnePrimary(),
1179-
Instance.getMainModule(), opts.ImplicitObjCHeaderPath, moduleIsPublic);
1192+
Instance.getMainModule(), BridgingHeaderPathForPrint, moduleIsPublic);
11801193
}
11811194

11821195
if (opts.InputsAndOutputs.hasModuleInterfaceOutputPath()) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import Foundation;
2+
3+
@interface UIColor : NSObject
4+
- (UIColor *)colorWithAlphaComponent:(CGFloat)alpha;
5+
- (UIColor *)resolvedColorWithTraitCollection:(CGFloat)traitCollection;
6+
@end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// REQUIRES: objc_interop
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse-as-library %s -typecheck -emit-objc-header-path %t/emit.h -disable-objc-attr-requires-foundation-module -import-objc-header %S/Inputs/CoreGraphics-Bridging-Header.h -import-underlying-module -module-name CoreGraphics -bridging-header-directory-for-print ""
5+
// RUN: %FileCheck -check-prefix=CHECK-DEFAULT %s < %t/emit.h
6+
7+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse-as-library %s -typecheck -emit-objc-header-path %t/emit.h -disable-objc-attr-requires-foundation-module -import-objc-header %S/Inputs/CoreGraphics-Bridging-Header.h -import-underlying-module -module-name CoreGraphics -bridging-header-directory-for-print "Headers/PrivateHeaders/"
8+
// RUN: %FileCheck -check-prefix=CHECK-DIR %s < %t/emit.h
9+
10+
@objc public class X: UIColor {
11+
@objc public func draw(_: UIColor) { }
12+
}
13+
14+
// CHECK-DEFAULT: #import "CoreGraphics-Bridging-Header.h"
15+
// CHECK-DIR: #import "Headers/PrivateHeaders/CoreGraphics-Bridging-Header.h"

0 commit comments

Comments
 (0)