Skip to content

Commit 0de56de

Browse files
committed
[Traits] Encode all trait information for package dump
# Motivation We need to encode all trait related package manifest configuration so that it shows up in the `dump-package` output. # Modification This PR encodes the missing `traits` property of the manifest.
1 parent e858647 commit 0de56de

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Diff for: Sources/PackageModel/Manifest/Manifest.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ extension Manifest: Encodable {
524524
private enum CodingKeys: CodingKey {
525525
case name, path, url, version, targetMap, toolsVersion,
526526
pkgConfig, providers, cLanguageStandard, cxxLanguageStandard, swiftLanguageVersions,
527-
dependencies, products, targets, platforms, packageKind, revision,
527+
dependencies, products, targets, experimentalTraits, platforms, packageKind, revision,
528528
defaultLocalization
529529
}
530530

@@ -555,6 +555,7 @@ extension Manifest: Encodable {
555555
try container.encode(self.dependencies, forKey: .dependencies)
556556
try container.encode(self.products, forKey: .products)
557557
try container.encode(self.targets, forKey: .targets)
558+
try container.encode(self.traits, forKey: .experimentalTraits)
558559
try container.encode(self.platforms, forKey: .platforms)
559560
try container.encode(self.packageKind, forKey: .packageKind)
560561
}

Diff for: Sources/PackageModel/Manifest/TraitDescription.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public struct TraitDescription: Sendable, Hashable, ExpressibleByStringLiteral {
13+
public struct TraitDescription: Sendable, Hashable, Codable, ExpressibleByStringLiteral {
1414
/// The trait's canonical name.
1515
///
1616
/// This is used when enabling the trait or when referring to it from other modifiers in the manifest.

Diff for: Tests/FunctionalTests/TraitTests.swift

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import DriverSupport
1414
import SPMTestSupport
1515
import PackageModel
16+
import TSCBasic
1617
import XCTest
1718

1819
final class TraitTests: XCTestCase {
@@ -161,5 +162,17 @@ final class TraitTests: XCTestCase {
161162
""")
162163
}
163164
}
165+
166+
func testTraits_dumpPackage() async throws {
167+
try await fixture(name: "Traits") { fixturePath in
168+
let packageRoot = fixturePath.appending("Example")
169+
let (dumpOutput, _) = try await SwiftPM.Package.execute(["dump-package"], packagePath: packageRoot)
170+
let json = try JSON(bytes: ByteString(encodingAsUTF8: dumpOutput))
171+
guard case let .dictionary(contents) = json else { XCTFail("unexpected result"); return }
172+
guard case let .array(traits)? = contents["experimentalTraits"] else { XCTFail("unexpected result"); return }
173+
XCTAssertEqual(traits.count, 11)
174+
}
175+
}
176+
164177
}
165178
#endif

0 commit comments

Comments
 (0)