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
Allow libSwiftPM clients additional flexibility in the manifest source generation (#3782)
Allow clients of the code that can generate manifest source generation to provide a tools version header comment, a list of imports, and custom handling for product types (falling back on default behavior if they don't provide a custom source code fragment for the product). Also makes SourceCodeFragment available to clients and adds documentation code for it.
Copy file name to clipboardExpand all lines: Sources/PackageModel/ManifestSourceGeneration.swift
+89-42Lines changed: 89 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,6 @@
8
8
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9
9
*/
10
10
11
-
import TSCBasic
12
-
import TSCUtility
13
11
import Foundation
14
12
15
13
@@ -22,25 +20,51 @@ extension Manifest {
22
20
23
21
/// Generates and returns a string containing the contents of the manifest
24
22
/// in canonical declarative form.
25
-
publicvargeneratedManifestFileContents:String{
26
-
/// Only write out the major and minor (not patch) versions of the
27
-
/// tools version, since the patch version doesn't change semantics.
28
-
/// We leave out the spacer if the tools version doesn't support it.
23
+
///
24
+
/// - Parameters:
25
+
/// - toolsVersionHeaderComment: Optional string to add to the `swift-tools-version` header (it will be ignored).
26
+
/// - additionalImportModuleNames: Names of any modules to import besides PackageDescription (would commonly contain custom product type definitions).
27
+
/// - customProductTypeSourceGenerator: Closure that will be called once for each custom product type in the manifest; it should return a SourceCodeFragment for the product type.
28
+
///
29
+
/// Returns: a string containing the full source code for the manifest.
/// Constructs and returns a SourceCodeFragment that represents the instantiation of a custom product type with the specified identifer and having the given serialized parameters (the contents of whom are a private matter between the serialized form in PackageDescription and the client). The generated source code should, if evaluated as a part of a package manifest, result in the same serialized parameters.
Copy file name to clipboardExpand all lines: Tests/WorkspaceTests/ManifestSourceGenerationTests.swift
+97-3Lines changed: 97 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -18,8 +18,15 @@ import XCTest
18
18
19
19
classManifestSourceGenerationTests:XCTestCase{
20
20
21
-
/// Private function that writes the contents of a package manifest to a temporary package directory and then loads it, then serializes the loaded manifest back out again and loads it once again, after which it compares that no information was lost.
/// Private function that writes the contents of a package manifest to a temporary package directory and then loads it, then serializes the loaded manifest back out again and loads it once again, after which it compares that no information was lost. Return the source of the newly generated manifest.
22
+
@discardableResult
23
+
privatefunc testManifestWritingRoundTrip(
24
+
manifestContents:String,
25
+
toolsVersion:ToolsVersion,
26
+
toolsVersionHeaderComment:String?=.none,
27
+
additionalImportModuleNames:[String]=[],
28
+
fs:FileSystem= localFileSystem
29
+
)throws->String{
23
30
trywithTemporaryDirectory{ packageDir in
24
31
// Write the original manifest file contents, and load it.
0 commit comments