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

Side by Side Diff: vpython/venv/venv.go

Issue 2918623003: [vpython] Verify environment, named installs. (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « vpython/venv/config.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package venv 5 package venv
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "encoding/json" 9 "encoding/json"
10 "io/ioutil" 10 "io/ioutil"
11 "os" 11 "os"
12 "os/exec" 12 "os/exec"
13 "path/filepath" 13 "path/filepath"
14 "strings" 14 "strings"
15 "time" 15 "time"
16 16
17 "github.com/danjacques/gofslock/fslock" 17 "github.com/danjacques/gofslock/fslock"
18 "github.com/golang/protobuf/proto" 18 "github.com/golang/protobuf/proto"
19 "golang.org/x/net/context" 19 "golang.org/x/net/context"
20 20
21 "github.com/luci/luci-go/vpython/api/vpython" 21 "github.com/luci/luci-go/vpython/api/vpython"
22 "github.com/luci/luci-go/vpython/python" 22 "github.com/luci/luci-go/vpython/python"
23 "github.com/luci/luci-go/vpython/spec"
23 "github.com/luci/luci-go/vpython/wheel" 24 "github.com/luci/luci-go/vpython/wheel"
24 25
25 "github.com/luci/luci-go/common/clock" 26 "github.com/luci/luci-go/common/clock"
26 "github.com/luci/luci-go/common/data/stringset" 27 "github.com/luci/luci-go/common/data/stringset"
27 "github.com/luci/luci-go/common/errors" 28 "github.com/luci/luci-go/common/errors"
28 "github.com/luci/luci-go/common/logging" 29 "github.com/luci/luci-go/common/logging"
29 "github.com/luci/luci-go/common/system/filesystem" 30 "github.com/luci/luci-go/common/system/filesystem"
30 ) 31 )
31 32
32 // EnvironmentVersion is an environment version string. It must advance each 33 // EnvironmentVersion is an environment version string. It must advance each
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 D("path", e.EnvironmentStampPath). 388 D("path", e.EnvironmentStampPath).
388 Err() 389 Err()
389 } 390 }
390 391
391 var environment vpython.Environment 392 var environment vpython.Environment
392 if err := proto.UnmarshalText(string(content), &environment); err != nil { 393 if err := proto.UnmarshalText(string(content), &environment); err != nil {
393 return errors.Annotate(err).Reason("failed to unmarshal vpython. Env stamp from: %(path)s"). 394 return errors.Annotate(err).Reason("failed to unmarshal vpython. Env stamp from: %(path)s").
394 D("path", e.EnvironmentStampPath). 395 D("path", e.EnvironmentStampPath).
395 Err() 396 Err()
396 } 397 }
398 if err := spec.NormalizeEnvironment(&environment); err != nil {
399 return errors.Annotate(err).Reason("failed to normalize stamp en vironment").Err()
400 }
401
402 // If we are configured with an environment, validate that it matches th e
403 // the environment that we just loaded.
404 //
405 // We only consider our environment-defining fields (Spec and Runtime).
406 //
407 // Note that both environments will have been normalized at this point, so
408 // comparison should be reliable.
409 if e.Environment != nil {
410 if !proto.Equal(e.Environment.Spec, environment.Spec) {
411 return errors.New("environment stamp specification does not match")
412 }
413 if !proto.Equal(e.Environment.Runtime, environment.Runtime) {
414 return errors.New("environment stamp runtime does not ma tch")
415 }
416 }
397 e.Environment = &environment 417 e.Environment = &environment
398 return nil 418 return nil
399 } 419 }
400 420
401 func (e *Env) assertComplete() error { 421 func (e *Env) assertComplete() error {
402 // Ensure that the environment has its completion flag. 422 // Ensure that the environment has its completion flag.
403 switch _, err := os.Stat(e.completeFlagPath); { 423 switch _, err := os.Stat(e.completeFlagPath); {
404 case filesystem.IsNotExist(err): 424 case filesystem.IsNotExist(err):
405 return ErrNotComplete 425 return ErrNotComplete
406 case err != nil: 426 case err != nil:
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 // panic, since the locking state can no longer be determined. 772 // panic, since the locking state can no longer be determined.
753 func mustReleaseLock(c context.Context, lock fslock.Handle, fn func() error) err or { 773 func mustReleaseLock(c context.Context, lock fslock.Handle, fn func() error) err or {
754 defer func() { 774 defer func() {
755 if err := lock.Unlock(); err != nil { 775 if err := lock.Unlock(); err != nil {
756 errors.Log(c, errors.Annotate(err).Reason("failed to rel ease lock").Err()) 776 errors.Log(c, errors.Annotate(err).Reason("failed to rel ease lock").Err())
757 panic(err) 777 panic(err)
758 } 778 }
759 }() 779 }()
760 return fn() 780 return fn()
761 } 781 }
OLDNEW
« no previous file with comments | « vpython/venv/config.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698