Skip to content
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

[Traits] Encode all trait information for package dump #7701

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/PackageModel/Manifest/Manifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ extension Manifest: Encodable {
private enum CodingKeys: CodingKey {
case name, path, url, version, targetMap, toolsVersion,
pkgConfig, providers, cLanguageStandard, cxxLanguageStandard, swiftLanguageVersions,
dependencies, products, targets, platforms, packageKind, revision,
dependencies, products, targets, experimentalTraits, platforms, packageKind, revision,
defaultLocalization
}

Expand Down Expand Up @@ -555,6 +555,7 @@ extension Manifest: Encodable {
try container.encode(self.dependencies, forKey: .dependencies)
try container.encode(self.products, forKey: .products)
try container.encode(self.targets, forKey: .targets)
try container.encode(self.traits, forKey: .experimentalTraits)
try container.encode(self.platforms, forKey: .platforms)
try container.encode(self.packageKind, forKey: .packageKind)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageModel/Manifest/TraitDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

public struct TraitDescription: Sendable, Hashable, ExpressibleByStringLiteral {
public struct TraitDescription: Sendable, Hashable, Codable, ExpressibleByStringLiteral {
/// The trait's canonical name.
///
/// This is used when enabling the trait or when referring to it from other modifiers in the manifest.
Expand Down
13 changes: 13 additions & 0 deletions Tests/FunctionalTests/TraitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import DriverSupport
import SPMTestSupport
import PackageModel
import TSCBasic
import XCTest

final class TraitTests: XCTestCase {
Expand Down Expand Up @@ -161,5 +162,17 @@ final class TraitTests: XCTestCase {
""")
}
}

func testTraits_dumpPackage() async throws {
try await fixture(name: "Traits") { fixturePath in
let packageRoot = fixturePath.appending("Example")
let (dumpOutput, _) = try await SwiftPM.Package.execute(["dump-package"], packagePath: packageRoot)
let json = try JSON(bytes: ByteString(encodingAsUTF8: dumpOutput))
guard case let .dictionary(contents) = json else { XCTFail("unexpected result"); return }
guard case let .array(traits)? = contents["experimentalTraits"] else { XCTFail("unexpected result"); return }
XCTAssertEqual(traits.count, 11)
}
}

}
#endif