@@ -31,7 +31,7 @@ import (
31
31
//
32
32
// actionID/[.../]contentID
33
33
//
34
- // where the actionID and contentID are prepared by hashToString below.
34
+ // where the actionID and contentID are prepared by buildid.HashToString below.
35
35
// and are found by looking for the first or last slash.
36
36
// Usually the buildID is simply actionID/contentID, but see below for an
37
37
// exception.
@@ -108,31 +108,6 @@ func contentID(buildID string) string {
108
108
return buildID [strings .LastIndex (buildID , buildIDSeparator )+ 1 :]
109
109
}
110
110
111
- // hashToString converts the hash h to a string to be recorded
112
- // in package archives and binaries as part of the build ID.
113
- // We use the first 120 bits of the hash (5 chunks of 24 bits each) and encode
114
- // it in base64, resulting in a 20-byte string. Because this is only used for
115
- // detecting the need to rebuild installed files (not for lookups
116
- // in the object file cache), 120 bits are sufficient to drive the
117
- // probability of a false "do not need to rebuild" decision to effectively zero.
118
- // We embed two different hashes in archives and four in binaries,
119
- // so cutting to 20 bytes is a significant savings when build IDs are displayed.
120
- // (20*4+3 = 83 bytes compared to 64*4+3 = 259 bytes for the
121
- // more straightforward option of printing the entire h in base64).
122
- func hashToString (h [cache .HashSize ]byte ) string {
123
- const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
124
- const chunks = 5
125
- var dst [chunks * 4 ]byte
126
- for i := 0 ; i < chunks ; i ++ {
127
- v := uint32 (h [3 * i ])<< 16 | uint32 (h [3 * i + 1 ])<< 8 | uint32 (h [3 * i + 2 ])
128
- dst [4 * i + 0 ] = b64 [(v >> 18 )& 0x3F ]
129
- dst [4 * i + 1 ] = b64 [(v >> 12 )& 0x3F ]
130
- dst [4 * i + 2 ] = b64 [(v >> 6 )& 0x3F ]
131
- dst [4 * i + 3 ] = b64 [v & 0x3F ]
132
- }
133
- return string (dst [:])
134
- }
135
-
136
111
// toolID returns the unique ID to use for the current copy of the
137
112
// named tool (asm, compile, cover, link).
138
113
//
@@ -404,7 +379,7 @@ func (b *Builder) fileHash(file string) string {
404
379
if err != nil {
405
380
return ""
406
381
}
407
- return hashToString (sum )
382
+ return buildid . HashToString (sum )
408
383
}
409
384
410
385
// useCache tries to satisfy the action a, which has action ID actionHash,
@@ -427,7 +402,7 @@ func (b *Builder) useCache(a *Action, actionHash cache.ActionID, target string)
427
402
// the actionID half; if it also appeared in the input that would be like an
428
403
// engineered 120-bit partial SHA256 collision.
429
404
a .actionID = actionHash
430
- actionID := hashToString (actionHash )
405
+ actionID := buildid . HashToString (actionHash )
431
406
if a .json != nil {
432
407
a .json .ActionID = actionID
433
408
}
@@ -480,7 +455,7 @@ func (b *Builder) useCache(a *Action, actionHash cache.ActionID, target string)
480
455
// build IDs of completed actions.
481
456
oldBuildID := a .buildID
482
457
a .buildID = id [1 ] + buildIDSeparator + id [2 ]
483
- linkID := hashToString (b .linkActionID (a .triggers [0 ]))
458
+ linkID := buildid . HashToString (b .linkActionID (a .triggers [0 ]))
484
459
if id [0 ] == linkID {
485
460
// Best effort attempt to display output from the compile and link steps.
486
461
// If it doesn't work, it doesn't work: reusing the cached binary is more
@@ -654,7 +629,7 @@ func (b *Builder) updateBuildID(a *Action, target string, rewrite bool) error {
654
629
if err != nil {
655
630
return err
656
631
}
657
- newID := a .buildID [:strings .LastIndex (a .buildID , buildIDSeparator )] + buildIDSeparator + hashToString (hash )
632
+ newID := a .buildID [:strings .LastIndex (a .buildID , buildIDSeparator )] + buildIDSeparator + buildid . HashToString (hash )
658
633
if len (newID ) != len (a .buildID ) {
659
634
return fmt .Errorf ("internal error: build ID length mismatch %q vs %q" , a .buildID , newID )
660
635
}
0 commit comments