Skip to content

Commit c65aff0

Browse files
committed
review feedback 2
1 parent 9e5cfa2 commit c65aff0

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,8 @@ public final class SwiftTargetBuildDescription {
547547
args += ["-color-diagnostics"]
548548
}
549549

550-
args += try self.cxxInteroperabilityModeArguments(allowDuplicate: false)
550+
args += try self.cxxInteroperabilityModeArguments(
551+
propagateFromCurrentModuleOtherSwiftFlags: false)
551552

552553
// Add arguments from declared build settings.
553554
args += try self.buildSettingsFlags()
@@ -630,63 +631,63 @@ public final class SwiftTargetBuildDescription {
630631
/// this module.
631632
public func symbolGraphExtractArguments() throws -> [String] {
632633
var args = [String]()
633-
args += try self.cxxInteroperabilityModeArguments(allowDuplicate: true)
634+
args += try self.cxxInteroperabilityModeArguments(
635+
propagateFromCurrentModuleOtherSwiftFlags: true)
634636
return args
635637
}
636638

639+
// FIXME: this function should operation on a strongly typed buildSetting
640+
// Move logic from PackageBuilder here.
637641
/// 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.
641642
func cxxInteroperabilityModeArguments(
642643
// FIXME: Remove argument
643644
// 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
647648
// digging through "OTHER_SWIFT_FLAGS" manually.
648-
allowDuplicate: Bool
649+
propagateFromCurrentModuleOtherSwiftFlags: Bool
649650
) throws -> [String] {
650-
func _cxxInteroperabilityMode(for module: ResolvedModule) -> String? {
651+
func cxxInteroperabilityModeAndStandard(
652+
for module: ResolvedModule
653+
) -> [String]? {
651654
let scope = self.buildParameters.createScope(for: module)
652655
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+
}
654665
}
655666

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
662672
}
663673
}
664674

675+
// Implicitly propagate cxx interop flags for generated test targets.
665676
// If the current module doesn't have cxx interop mode set, search
666677
// through the module's dependencies looking for the a module that
667678
// enables cxx interop and copy it's flag.
668-
if cxxInteroperabilityMode == nil {
679+
switch self.testTargetRole {
680+
case .discovery, .entryPoint:
669681
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
673684
}
674685
}
686+
default: break
675687
}
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 []
687689
}
688690

689-
690691
/// When `scanInvocation` argument is set to `true`, omit the side-effect producing arguments
691692
/// such as emitting a module or supplementary outputs.
692693
public func emitCommandLine(scanInvocation: Bool = false) throws -> [String] {

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,8 +1951,7 @@ final class BuildPlanTests: XCTestCase {
19511951
)
19521952
XCTAssertNoDiagnostics(observability.diagnostics)
19531953

1954-
let plan = try BuildPlan(
1955-
buildParameters: mockBuildParameters(),
1954+
let plan = try mockBuildPlan(
19561955
graph: graph,
19571956
fileSystem: fs,
19581957
observabilityScope: observability.topScope

0 commit comments

Comments
 (0)