Skip to content

Commit 17c5d4b

Browse files
committed
Add logic hashing platforms
1 parent 8d02aba commit 17c5d4b

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

Sources/SPMSelectiveTestingCore/Hasher/ModuleHasher.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ actor ModuleHasher: ModuleHashing {
2121
let contentHasher: ContentHashing
2222
let versionHasher: VersionHashing
2323
let sourceFileContentHasher: SourceFileContentHashing
24+
let platformHasher: PlatformHashing
2425

2526
init(
2627
modules: [IModule],
2728
contentHasher: ContentHashing = ContentHasher(),
2829
sourceFileContentHasher: SourceFileContentHashing = SourceFileContentHasher(),
29-
versionHasher: VersionHashing = VersionHasher()
30+
versionHasher: VersionHashing = VersionHasher(),
31+
platformHasher: PlatformHashing = PlatformHasher()
3032
) {
3133
self.modules = modules
3234
self.modulesDic = modules.dictionary
3335
self.contentHasher = contentHasher
3436
self.sourceFileContentHasher = sourceFileContentHasher
3537
self.versionHasher = versionHasher
38+
self.platformHasher = platformHasher
3639
}
3740

3841
func generateHash() async throws -> [ModuleName: MD5Hash] {
@@ -53,11 +56,13 @@ actor ModuleHasher: ModuleHashing {
5356
let sourcesHash = try await sourceFileContentHasher.hash(sources: module.sourceCodes)
5457
let version = versionHasher.hash(module: module)
5558
let dependenciesHash = try await hashDependencies(of: module)
59+
let platformHash = try platformHasher.hash(module: module)
5660

5761
var stringsToHash: [String] = [
5862
sourcesHash,
5963
module.name,
6064
version,
65+
platformHash
6166
]
6267

6368
stringsToHash += dependenciesHash
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Tuan Hoang Anh on 18/5/24.
6+
//
7+
8+
import Foundation
9+
10+
protocol PlatformHashing {
11+
func hash(module: IModule) throws -> MD5Hash
12+
}
13+
14+
struct PlatformHasher: PlatformHashing {
15+
let contentHasher: ContentHashing
16+
init(contentHasher: ContentHashing = ContentHasher()) {
17+
self.contentHasher = contentHasher
18+
}
19+
20+
func hash(module: IModule) throws -> MD5Hash {
21+
guard let localModule = module as? LocalModule else {
22+
return ""
23+
}
24+
25+
var hashes: [MD5Hash] = []
26+
for platform in localModule.platforms {
27+
let platformHash = try contentHasher.hash(platform.id)
28+
hashes.append(platformHash)
29+
}
30+
31+
let platformHash = try contentHasher.hash(hashes)
32+
return platformHash
33+
}
34+
}

Sources/SPMSelectiveTestingCore/ModuleResolver/LocalModuleResolver/DependenciesReader.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ final class DependenciesReader {
4545

4646
private struct DumpPackageResponse: Decodable {
4747
let rootPaths: [String]
48+
let platforms: [Platform]
4849
let targets: [Target]
4950

5051
struct Target: Decodable {
@@ -65,6 +66,7 @@ private struct DumpPackageResponse: Decodable {
6566
enum CodingKeys: String, CodingKey {
6667
case packageKind
6768
case targets
69+
case platforms
6870
}
6971

7072
enum PackageKindCodingKeys: String, CodingKey {
@@ -76,6 +78,7 @@ private struct DumpPackageResponse: Decodable {
7678
let rootPath = try container.nestedContainer(keyedBy: PackageKindCodingKeys.self, forKey: .packageKind)
7779
rootPaths = try rootPath.decode([String].self, forKey: .root)
7880
targets = try container.decode([Target].self, forKey: .targets)
81+
platforms = try container.decode([Platform].self, forKey: .platforms)
7982
}
8083
}
8184

@@ -92,7 +95,8 @@ extension DumpPackageResponse {
9295
root: rootPaths[0],
9396
path: target.path,
9497
sources: target.sources,
95-
exclude: target.exclude
98+
exclude: target.exclude,
99+
platforms: platforms
96100
)
97101
}
98102
}

Sources/SPMSelectiveTestingCore/ModuleResolver/Modules/LocalModule.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ enum TargetType : String, Codable {
1515
case macro
1616
}
1717

18+
struct Platform: Decodable {
19+
let platformName: String
20+
let version: String
21+
22+
var id: String {
23+
return "\(platformName)-\(version)"
24+
}
25+
}
26+
1827
public struct LocalModule: IModule {
1928
let name: String
2029
let type: TargetType
@@ -39,6 +48,7 @@ public struct LocalModule: IModule {
3948
/// The paths to source and resource files that you don't want to include in the target.
4049
/// Excluded paths are relative to the target path.
4150
let exclude: [String]
51+
let platforms: [Platform]
4252

4353
var isTest: Bool {
4454
type == .test

0 commit comments

Comments
 (0)