Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Unified Diff: vpython/spec/spec.go

Issue 2905943002: [vpython] Incorporate interpreter path/hash. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « vpython/python/python_test.go ('k') | vpython/spec/spec_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vpython/spec/spec.go
diff --git a/vpython/spec/spec.go b/vpython/spec/spec.go
index c0446f738c94022b6676c6b01254e83d654f3d44..6a52115145436d37fc06d14bb82ad53f5c3767cc 100644
--- a/vpython/spec/spec.go
+++ b/vpython/spec/spec.go
@@ -43,16 +43,21 @@ func Normalize(spec *vpython.Spec, defaultVENVPackage *vpython.Spec_Package) err
return nil
}
-// Hash hashes the contents of the supplied "spec" and returns the result as
-// a hex-encoded string.
+// Hash hashes the contents of the supplied "spec" and "rt" and returns the
+// result as a hex-encoded string.
//
// If not empty, the contents of extra are prefixed to hash string. This can
// be used to factor additional influences into the spec hash.
-func Hash(spec *vpython.Spec, extra string) string {
- data, err := proto.Marshal(spec)
- if err != nil {
- panic(fmt.Errorf("failed to marshal proto: %v", err))
+func Hash(spec *vpython.Spec, rt *vpython.Runtime, extra string) string {
+ mustMarshal := func(msg proto.Message) []byte {
+ data, err := proto.Marshal(msg)
+ if err != nil {
+ panic(fmt.Errorf("failed to marshal proto: %v", err))
+ }
+ return data
}
+ specData := mustMarshal(spec)
+ rtData := mustMarshal(rt)
mustWrite := func(v int, err error) {
if err != nil {
@@ -65,7 +70,9 @@ func Hash(spec *vpython.Spec, extra string) string {
mustWrite(fmt.Fprintf(hash, "%s:", extra))
}
mustWrite(fmt.Fprintf(hash, "%s:", vpython.Version))
- mustWrite(hash.Write(data))
+ mustWrite(hash.Write(specData))
+ mustWrite(hash.Write([]byte(":")))
+ mustWrite(hash.Write(rtData))
return hex.EncodeToString(hash.Sum(nil))
}
« no previous file with comments | « vpython/python/python_test.go ('k') | vpython/spec/spec_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698