Skip to content

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bripeticca
Copy link
Contributor

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.

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.
@bripeticca
Copy link
Contributor Author

@swift-ci please test

Copy link
Member

@FranzBusch FranzBusch left a 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?

@bripeticca
Copy link
Contributor Author

@swift-ci please test

@bripeticca
Copy link
Contributor Author

@swift-ci please test windows

Copy link
Contributor

@bkhouri bkhouri left a 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 {
Copy link
Contributor

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;
Copy link
Contributor

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 {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants