You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
New technique for resolving module name conflicts to module alias docs (#8983)
Conflicts can arise due to duplicate module names within a package
graph. Module aliases themselves if they are not globally unique can
introduce further conflicts. The documentation for the module aliases
feature can describe a technique for the naming that can help to reduce
the likelihood of further collisions by recommending the use of the
package identifier as a qualifier to the alias. As other packages in the
graph encounter the collision, this system can help for there to be a
broader agreement on the new name, which should lessen the cases where
module alias chaining is needed.
Update the correct ModuleAliases.md file so that the changes will be
shown in the new documentation system.
Copy file name to clipboardExpand all lines: Sources/PackageManagerDocs/Documentation.docc/ModuleAliasing.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,16 +33,16 @@ Module aliases are defined as a dictionary parameter in a target's dependencies
33
33
.product(
34
34
name: "Utils",
35
35
package: "MyPackage",
36
-
moduleAliases: ["Utils":"MyUtils"]
36
+
moduleAliases: ["Utils":"MyPackageUtils"]
37
37
)
38
38
]
39
39
)
40
40
]
41
41
```
42
42
43
-
This will rename the `Utils` module in the `MyPackage` package to the new user-defined unique name, in this case `MyUtils`; the name of the binary will be `MyUtils.swiftmodule`. No source or manifest changes are required by the dependency package.
43
+
This will rename the `Utils` module in the `MyPackage` package to the new user-defined unique name, in this case `MyPackageUtils`; the name of the binary will be `MyPackageUtils.swiftmodule`. No source or manifest changes are required by the dependency package.
44
44
45
-
To use the aliased module, your root package needs to reference the the new name, i.e. `import MyUtils`.
45
+
To use the aliased module your root package can use the new unique name, i.e. `import MyPackageUtils`, and make it clear that it is importing the utilities module from `MyPackage`.
46
46
47
47
Consider the following example to go over how module aliasing can be used in more detail.
48
48
@@ -107,17 +107,17 @@ Package manifest `App`
107
107
package: "swift-draw"),
108
108
.product(name: "Utils",
109
109
package: "swift-game",
110
-
moduleAliases: ["Utils": "GameUtils"]),
110
+
moduleAliases: ["Utils": "SwiftGameUtils"]),
111
111
])
112
112
]
113
113
```
114
114
115
-
This will rename the `Utils` module in package `swift-game` as `GameUtils`; the name of the binary will be `GameUtils.swiftmodule`.
115
+
This will rename the `Utils` module in package `swift-game` as `SwiftGameUtils`; the name of the binary will be `SwiftGameUtils.swiftmodule`.
116
116
117
-
To use the aliased module, `App`needs to reference the the new name, i.e. `import GameUtils`. Its existing `import Utils` statement will continue to reference the `Utils` module from package `swift-draw`, as expected.
117
+
To use the aliased module, `App`can reference the new package-qualified name, i.e. `import SwiftGameUtils`. Its existing `import Utils` statement will continue to reference the `Utils` module from package `swift-draw`, as expected.
118
118
119
119
Note that the dependency product names are duplicate, i.e. both have the same name `Utils`, which is by default not allowed.
120
-
However, this is allowed when module aliasing is used as long as no multiple files with the same product name are created.
120
+
However, this is allowed when module aliasing is used as long as no files with the same product name are created.
121
121
This means they must all be automatic library types, or at most one of them can be a static library, dylib, an executable, or any other type that creates a file or a directory with the product name.
122
122
123
123
###### Transitive Logging modules
@@ -138,25 +138,25 @@ Package manifest `App`
138
138
package: "swift-draw"),
139
139
.product(name: "Utils",
140
140
package: "swift-game",
141
-
moduleAliases: ["Utils": "GameUtils"]),
141
+
moduleAliases: ["Utils": "SwiftGameUtils"]),
142
142
// Logging module aliasing:
143
143
.product(name: "Logging",
144
144
package: "swift-draw"),
145
145
.product(name: "Game",
146
146
package: "swift-game",
147
-
moduleAliases: ["Logging": "GameLogging"]),
147
+
moduleAliases: ["Logging": "SwiftGameLogging"]),
148
148
])
149
149
]
150
150
```
151
151
152
-
The `Logging` module from `swift-game` is renamed as `GameLogging`, and all the references to `Logging` in source files of `Game` are compiled as `GameLogging`. Similar to before, no source or manifest changes are required by the `swift-game` package.
152
+
The `Logging` module from `swift-game` is renamed as `SwiftGameLogging`, and all the references to `Logging` in source files of `Game` are compiled as `SwiftGameLogging`. Similar to before, no source or manifest changes are required by the `swift-game` package.
153
153
154
154
If more aliases need to be defined, they can be added with a comma delimiter, per below.
If module alias values defined upstream are conflicting downstream, they can be overridden by chaining; add an entry to the `moduleAliases` parameter downstream using the conflicting alias value as a key and provide a unique value.
162
+
If module alias values defined upstream are conflicting downstream, they can be overridden by chaining; add an entry to the `moduleAliases` parameter downstream using the conflicting alias value as a key and provide a unique value. Since the package identifier is unique to the package, using it as the prefix for the new module alias as a convention should help to prevent more collisions since it can be a generally agreed unique name for the module.
0 commit comments