@@ -18,7 +18,7 @@ import SPMBuildCore
18
18
19
19
import struct TSCBasic. ByteString
20
20
import protocol TSCBasic. HashAlgorithm
21
-
21
+ import struct TSCBasic . SHA256
22
22
import enum TSCUtility. Diagnostics
23
23
24
24
extension Workspace {
@@ -537,20 +537,35 @@ extension Workspace {
537
537
return result. get ( )
538
538
}
539
539
540
- public func checksum( forBinaryArtifactAt path: AbsolutePath ) throws -> String {
540
+ package static func checksum(
541
+ forBinaryArtifactAt path: AbsolutePath ,
542
+ hashAlgorithm: HashAlgorithm = SHA256 ( ) ,
543
+ archiver: ( any Archiver ) ? = nil ,
544
+ fileSystem: any FileSystem
545
+ ) throws -> String {
546
+ let archiver = archiver ?? UniversalArchiver ( fileSystem)
541
547
// Validate the path has a supported extension.
542
- guard let pathExtension = path. extension , self . archiver. supportedExtensions . contains ( pathExtension ) else {
543
- let supportedExtensionList = self . archiver. supportedExtensions. joined ( separator: " , " )
548
+ guard let lastPathComponent = path. components . last , archiver. isFileSupported ( lastPathComponent ) else {
549
+ let supportedExtensionList = archiver. supportedExtensions. joined ( separator: " , " )
544
550
throw StringError ( " unexpected file type; supported extensions are: \( supportedExtensionList) " )
545
551
}
546
552
547
553
// Ensure that the path with the accepted extension is a file.
548
- guard self . fileSystem. isFile ( path) else {
554
+ guard fileSystem. isFile ( path) else {
549
555
throw StringError ( " file not found at path: \( path. pathString) " )
550
556
}
551
557
552
- let contents = try self . fileSystem. readFileContents ( path)
553
- return self . checksumAlgorithm. hash ( contents) . hexadecimalRepresentation
558
+ let contents = try fileSystem. readFileContents ( path)
559
+ return hashAlgorithm. hash ( contents) . hexadecimalRepresentation
560
+ }
561
+
562
+ public func checksum( forBinaryArtifactAt path: AbsolutePath ) throws -> String {
563
+ try Self . checksum (
564
+ forBinaryArtifactAt: path,
565
+ hashAlgorithm: self . checksumAlgorithm,
566
+ archiver: self . archiver,
567
+ fileSystem: self . fileSystem
568
+ )
554
569
}
555
570
556
571
public func cancel( deadline: DispatchTime ) throws {
0 commit comments