Commit b931916
authored
Cherry pick of #8852
Trait-guarded dependencies were still being considered during dependency
resolution, when they should be excluded if they aren't being used in
any other scenario. Additionally, enabled traits should be pre-computed
before entering the resolution stage in order to avoid possible race
conditions when navigating through the dependency graph nodes.
### Modifications:
Since we have the `--experimental-prune-unused-dependencies` feature
behind an experimental flag, we'll now consider an alternate path that
will prune trait-guarded package dependencies from the dependency graph
**_if and only if_** said dependency is not used in any other unguarded
context.
A dictionary wrapper titled `EnabledTraitsMap` is used to store the
enabled traits per package for the package graph and is stored as a
property within the `Workspace`, with some additional behaviour to
return a `["default"]` set of traits if the package has not yet been
stored in the dictionary, rather than returning `nil`.
Following this behaviour, when passing a set of traits to methods that
require them (e.g. for dependency computation, enabled trait
computation, etc.) we now require that it is not Optional, since the
checks done on a `nil` set of traits were redundant.
SwiftCommandState now also stores a `TraitConfiguration`, since we'll
want access to this across multiple `SwiftCommand`s, and it is
essentially a part of the state anyhow. `TraitOptions` is now included
in the `GlobalOptions` for `SwiftCommand`s to supplement this, so that
when a `SwiftCommandState` is created we will have access to the
user-passed enabled traits. These options, as entitled, are available
globally across all the swift package commands, so previous properties
that declared `TraitOptions` in these commands has been removed in
favour of using it straight from the `GlobalOptions`.
### Result:
Trait-guarded dependencies are excluded from dependency resolution, and
since traits are pre-computed there should no longer be an issue with
race conditions for traits in resolution as well.
1 parent 3fa5297 commit b931916
File tree
50 files changed
+758
-570
lines changed- Sources
- Commands
- PackageCommands
- Snippets/Cards
- Utilities
- CoreCommands
- PackageDescription
- PackageGraph
- Resolution
- PubGrub
- PackageModel
- Manifest
- SPMBuildCore/BuildSystem
- Workspace
- PackageContainer
- _InternalTestSupport
- swift-bootstrap
- Tests
- FunctionalTests
- PackageGraphPerformanceTests
- PackageGraphTests
- PackageModelTests
- WorkspaceTests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
50 files changed
+758
-570
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | 73 | | |
77 | 74 | | |
78 | 75 | | |
| |||
91 | 88 | | |
92 | 89 | | |
93 | 90 | | |
94 | | - | |
95 | 91 | | |
96 | 92 | | |
97 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
221 | 220 | | |
222 | 221 | | |
223 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
334 | | - | |
335 | 334 | | |
336 | 335 | | |
337 | 336 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | 34 | | |
39 | 35 | | |
40 | 36 | | |
| |||
50 | 46 | | |
51 | 47 | | |
52 | 48 | | |
53 | | - | |
| 49 | + | |
54 | 50 | | |
55 | 51 | | |
56 | | - | |
| 52 | + | |
57 | 53 | | |
58 | 54 | | |
59 | 55 | | |
| |||
64 | 60 | | |
65 | 61 | | |
66 | 62 | | |
67 | | - | |
| 63 | + | |
68 | 64 | | |
69 | 65 | | |
70 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | 113 | | |
118 | 114 | | |
119 | 115 | | |
| |||
144 | 140 | | |
145 | 141 | | |
146 | 142 | | |
147 | | - | |
148 | 143 | | |
149 | 144 | | |
150 | 145 | | |
| |||
194 | 189 | | |
195 | 190 | | |
196 | 191 | | |
197 | | - | |
198 | 192 | | |
199 | 193 | | |
200 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | 91 | | |
96 | 92 | | |
97 | 93 | | |
| |||
139 | 135 | | |
140 | 136 | | |
141 | 137 | | |
142 | | - | |
143 | 138 | | |
144 | 139 | | |
145 | 140 | | |
| |||
161 | 156 | | |
162 | 157 | | |
163 | 158 | | |
164 | | - | |
165 | 159 | | |
166 | 160 | | |
167 | 161 | | |
| |||
217 | 211 | | |
218 | 212 | | |
219 | 213 | | |
220 | | - | |
221 | 214 | | |
222 | | - | |
| 215 | + | |
| 216 | + | |
223 | 217 | | |
224 | 218 | | |
225 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | 223 | | |
227 | 224 | | |
228 | 225 | | |
| |||
659 | 656 | | |
660 | 657 | | |
661 | 658 | | |
662 | | - | |
| 659 | + | |
663 | 660 | | |
664 | 661 | | |
665 | 662 | | |
| |||
741 | 738 | | |
742 | 739 | | |
743 | 740 | | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | 741 | | |
748 | 742 | | |
749 | 743 | | |
| |||
850 | 844 | | |
851 | 845 | | |
852 | 846 | | |
853 | | - | |
| 847 | + | |
854 | 848 | | |
855 | 849 | | |
856 | 850 | | |
| |||
1561 | 1555 | | |
1562 | 1556 | | |
1563 | 1557 | | |
1564 | | - | |
1565 | 1558 | | |
1566 | 1559 | | |
1567 | 1560 | | |
| |||
0 commit comments