-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix for .when(traits:) condition not working for multiple traits #9015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The culprit here is the fact that we were essentially doing an AND boolean check across all the traits in the target dependency condition, when we should be doing an OR boolean check. If at least one trait is enabled in the list of traits in the target dependency condition, then the target dependecy should be considered enabled as well.
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! Can we add to our trait fixtures this setup as well where a single dependency is guarded by two traits?
@swift-ci please test |
@swift-ci please test windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments for your consideration.
|
||
return traitsToEnable.isEmpty || isEnabled | ||
} | ||
/// Determines whether a given package dependency is used by this manifest given a set of enabled traits. | ||
public func isPackageDependencyUsed(_ dependency: PackageDependency, enabledTraits: Set<String>/* = ["default"]*/) throws -> Bool { | ||
public func isPackageDependencyUsed(_ dependency: PackageDependency, enabledTraits: Set<String>) throws -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: can we write some automated tests that would validate this function in isolation. This would allow us to validate various scenarios, include fault injection et al. If we are unable to control the test the was we want, we can rework the function to make it testable.
@@ -449,15 +449,18 @@ extension Manifest { | |||
|
|||
let traitsToEnable = self.traitGuardedTargetDependencies(for: target)[dependency] ?? [] | |||
|
|||
let isEnabled = try traitsToEnable.allSatisfy { try self.isTraitEnabled( | |||
// Check if any of the traits guarding this dependency is enabled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: can we write some automated tests that would validate this function in isolation. This would allow us to validate various scenarios, include fault injection et al. If we are unable to control the test the was we want, we can rework the function to make it testable.
// We expect no warnings to be produced. Specifically no unused dependency warnings. | ||
let unusedDependencyRegex = try Regex("warning: '.*': dependency '.*' is not used by any target") | ||
|
||
for traits in traitCombinations { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider adding this as a test parameterization.
Have a look at #9012 that combines BuildSystem
and BuildConfiguration
into a single array, allow us to send a second array as argument.
Here's that introduces the getBuildData(...)
function and here's an application
The culprit here is the fact that we were essentially doing an AND boolean check across all the traits in the target dependency condition, when we should be doing an OR boolean check.
If at least one trait is enabled in the list of traits in the target dependency condition, then the target dependecy should be considered enabled as well.