mirror of
https://code.tvl.fyi/depot.git:/tools/nixery.git
synced 2025-03-15 06:01:51 +00:00
feat(server): Introduce function to hash contents of a layer
This creates a cache key which can be used to check if a layer has already been built.
This commit is contained in:
parent
c26dc1d9d7
commit
59f8925e05
|
@ -103,9 +103,12 @@
|
||||||
package layers
|
package layers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha1"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"gonum.org/v1/gonum/graph/flow"
|
"gonum.org/v1/gonum/graph/flow"
|
||||||
"gonum.org/v1/gonum/graph/simple"
|
"gonum.org/v1/gonum/graph/simple"
|
||||||
|
@ -141,6 +144,13 @@ type Layer struct {
|
||||||
mergeRating uint64
|
mergeRating uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hash the contents of a layer to create a deterministic identifier that can be
|
||||||
|
// used for caching.
|
||||||
|
func (l *Layer) Hash() string {
|
||||||
|
sum := sha1.Sum([]byte(strings.Join(l.Contents, ":")))
|
||||||
|
return fmt.Sprintf("%x", sum)
|
||||||
|
}
|
||||||
|
|
||||||
func (a Layer) merge(b Layer) Layer {
|
func (a Layer) merge(b Layer) Layer {
|
||||||
a.Contents = append(a.Contents, b.Contents...)
|
a.Contents = append(a.Contents, b.Contents...)
|
||||||
a.mergeRating += b.mergeRating
|
a.mergeRating += b.mergeRating
|
||||||
|
@ -272,6 +282,9 @@ func groupLayer(dt *flow.DominatorTree, root *closure) Layer {
|
||||||
children = append(children, dt.DominatedBy(child.ID())...)
|
children = append(children, dt.DominatedBy(child.ID())...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Contents are sorted to ensure that hashing is consistent
|
||||||
|
sort.Strings(contents)
|
||||||
|
|
||||||
return Layer{
|
return Layer{
|
||||||
Contents: contents,
|
Contents: contents,
|
||||||
// TODO(tazjin): The point of this is to factor in
|
// TODO(tazjin): The point of this is to factor in
|
||||||
|
|
Loading…
Reference in New Issue
Block a user