@@ -547,7 +547,8 @@ public final class SwiftTargetBuildDescription {
547
547
args += [ " -color-diagnostics " ]
548
548
}
549
549
550
- args += try self . cxxInteroperabilityModeArguments ( allowDuplicate: false )
550
+ args += try self . cxxInteroperabilityModeArguments (
551
+ propagateFromCurrentModuleOtherSwiftFlags: false )
551
552
552
553
// Add arguments from declared build settings.
553
554
args += try self . buildSettingsFlags ( )
@@ -630,63 +631,63 @@ public final class SwiftTargetBuildDescription {
630
631
/// this module.
631
632
public func symbolGraphExtractArguments( ) throws -> [ String ] {
632
633
var args = [ String] ( )
633
- args += try self . cxxInteroperabilityModeArguments ( allowDuplicate: true )
634
+ args += try self . cxxInteroperabilityModeArguments (
635
+ propagateFromCurrentModuleOtherSwiftFlags: true )
634
636
return args
635
637
}
636
638
639
+ // FIXME: this function should operation on a strongly typed buildSetting
640
+ // Move logic from PackageBuilder here.
637
641
/// Determines the arguments needed for cxx interop for this module.
638
- ///
639
- /// If the current module or any of its linked dependencies requires cxx
640
- /// interop, cxx interop will be enabled on the current module.
641
642
func cxxInteroperabilityModeArguments(
642
643
// FIXME: Remove argument
643
644
// This argument is added as a stop gap to support generating arguments
644
- // for tools which currently dont leverage "OTHER_SWIFT_FLAGS". In the
645
- // fullness of time, this function should operate on a strongly typed
646
- // "interopMode" property of SwiftTargetBuildDescription. Instead of
645
+ // for tools which currently don't leverage "OTHER_SWIFT_FLAGS". In the
646
+ // fullness of time this function should operate on a strongly typed
647
+ // "interopMode" property of SwiftTargetBuildDescription instead of
647
648
// digging through "OTHER_SWIFT_FLAGS" manually.
648
- allowDuplicate : Bool
649
+ propagateFromCurrentModuleOtherSwiftFlags : Bool
649
650
) throws -> [ String ] {
650
- func _cxxInteroperabilityMode( for module: ResolvedModule ) -> String ? {
651
+ func cxxInteroperabilityModeAndStandard(
652
+ for module: ResolvedModule
653
+ ) -> [ String ] ? {
651
654
let scope = self . buildParameters. createScope ( for: module)
652
655
let flags = scope. evaluate ( . OTHER_SWIFT_FLAGS)
653
- return flags. first { $0. hasPrefix ( " -cxx-interoperability-mode= " ) }
656
+ let mode = flags. first { $0. hasPrefix ( " -cxx-interoperability-mode= " ) }
657
+ guard let mode else { return nil }
658
+ // FIXME: Use a stored self.cxxLanguageStandard property
659
+ // It definitely should _never_ reach back into the manifest
660
+ if let cxxStandard = self . package . manifest. cxxLanguageStandard {
661
+ return [ mode, " -Xcc " , " -std= \( cxxStandard) " ]
662
+ } else {
663
+ return [ mode]
664
+ }
654
665
}
655
666
656
- // Look for cxx interop mode in the current module, if set exit early,
657
- // the flag is already present.
658
- var cxxInteroperabilityMode : String ?
659
- if let mode = _cxxInteroperabilityMode ( for: self . target) {
660
- if allowDuplicate {
661
- cxxInteroperabilityMode = mode
667
+ if propagateFromCurrentModuleOtherSwiftFlags {
668
+ // Look for cxx interop mode in the current module, if set exit early,
669
+ // the flag is already present.
670
+ if let args = cxxInteroperabilityModeAndStandard ( for: self . target) {
671
+ return args
662
672
}
663
673
}
664
674
675
+ // Implicitly propagate cxx interop flags for generated test targets.
665
676
// If the current module doesn't have cxx interop mode set, search
666
677
// through the module's dependencies looking for the a module that
667
678
// enables cxx interop and copy it's flag.
668
- if cxxInteroperabilityMode == nil {
679
+ switch self . testTargetRole {
680
+ case . discovery, . entryPoint:
669
681
for module in try self . target. recursiveTargetDependencies ( ) {
670
- if let mode = _cxxInteroperabilityMode ( for: module) {
671
- cxxInteroperabilityMode = mode
672
- break
682
+ if let args = cxxInteroperabilityModeAndStandard ( for: module) {
683
+ return args
673
684
}
674
685
}
686
+ default : break
675
687
}
676
-
677
- var args = [ String] ( )
678
- if let cxxInteroperabilityMode {
679
- // FIXME: this should reference a local cxxLanguageStandard property
680
- // It definitely should _never_ reach back into the manifest
681
- args = [ cxxInteroperabilityMode]
682
- if let cxxStandard = self . package . manifest. cxxLanguageStandard {
683
- args += [ " -Xcc " , " -std= \( cxxStandard) " ]
684
- }
685
- }
686
- return args
688
+ return [ ]
687
689
}
688
690
689
-
690
691
/// When `scanInvocation` argument is set to `true`, omit the side-effect producing arguments
691
692
/// such as emitting a module or supplementary outputs.
692
693
public func emitCommandLine( scanInvocation: Bool = false ) throws -> [ String ] {
0 commit comments