| OLD | NEW |
| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 "github.com/luci/luci-go/vpython/python" | 22 "github.com/luci/luci-go/vpython/python" |
| 23 "github.com/luci/luci-go/vpython/wheel" | 23 "github.com/luci/luci-go/vpython/wheel" |
| 24 | 24 |
| 25 "github.com/luci/luci-go/common/clock" | 25 "github.com/luci/luci-go/common/clock" |
| 26 "github.com/luci/luci-go/common/data/stringset" | 26 "github.com/luci/luci-go/common/data/stringset" |
| 27 "github.com/luci/luci-go/common/errors" | 27 "github.com/luci/luci-go/common/errors" |
| 28 "github.com/luci/luci-go/common/logging" | 28 "github.com/luci/luci-go/common/logging" |
| 29 "github.com/luci/luci-go/common/system/filesystem" | 29 "github.com/luci/luci-go/common/system/filesystem" |
| 30 ) | 30 ) |
| 31 | 31 |
| 32 // EnvironmentVersion is an environment version string. It must advance each |
| 33 // time the layout of a VirtualEnv environment changes. |
| 34 const EnvironmentVersion = "v1" |
| 35 |
| 32 // ErrNotComplete is a sentinel error returned by AssertCompleteAndLoad to | 36 // ErrNotComplete is a sentinel error returned by AssertCompleteAndLoad to |
| 33 // indicate that the Environment is missing its completion flag. | 37 // indicate that the Environment is missing its completion flag. |
| 34 var ErrNotComplete = errors.New("environment is not complete") | 38 var ErrNotComplete = errors.New("environment is not complete") |
| 35 | 39 |
| 36 const ( | 40 const ( |
| 37 lockHeldDelay = 10 * time.Millisecond | 41 lockHeldDelay = 10 * time.Millisecond |
| 38 ) | 42 ) |
| 39 | 43 |
| 40 // blocker is an fslock.Blocker implementation that sleeps lockHeldDelay in | 44 // blocker is an fslock.Blocker implementation that sleeps lockHeldDelay in |
| 41 // between attempts. | 45 // between attempts. |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 "--find-links", pkgDir, | 613 "--find-links", pkgDir, |
| 610 "--requirement", reqPath) | 614 "--requirement", reqPath) |
| 611 attachOutputForLogging(c, logging.Debug, cmd) | 615 attachOutputForLogging(c, logging.Debug, cmd) |
| 612 if err := cmd.Run(); err != nil { | 616 if err := cmd.Run(); err != nil { |
| 613 return errors.Annotate(err).Reason("failed to install wheels").E
rr() | 617 return errors.Annotate(err).Reason("failed to install wheels").E
rr() |
| 614 } | 618 } |
| 615 return nil | 619 return nil |
| 616 } | 620 } |
| 617 | 621 |
| 618 func (e *Env) finalize(c context.Context) error { | 622 func (e *Env) finalize(c context.Context) error { |
| 619 // Uninstall "pip" and "wheel", preventing (easy) augmentation of the | |
| 620 // environment. | |
| 621 if !e.Config.testPreserveInstallationCapability { | |
| 622 cmd := e.Interpreter().IsolatedCommand(c, | |
| 623 "-m", "pip", | |
| 624 "uninstall", | |
| 625 "--quiet", | |
| 626 "--yes", | |
| 627 "pip", "wheel") | |
| 628 attachOutputForLogging(c, logging.Debug, cmd) | |
| 629 if err := cmd.Run(); err != nil { | |
| 630 return errors.Annotate(err).Reason("failed to install wh
eels").Err() | |
| 631 } | |
| 632 } | |
| 633 | |
| 634 // Change all files to read-only, except: | 623 // Change all files to read-only, except: |
| 635 // - Our root directory, which must be writable in order to update our | 624 // - Our root directory, which must be writable in order to update our |
| 636 // completion flag. | 625 // completion flag. |
| 637 // - Our environment stamp, which must be trivially re-writable. | 626 // - Our environment stamp, which must be trivially re-writable. |
| 638 if !e.Config.testLeaveReadWrite { | 627 if !e.Config.testLeaveReadWrite { |
| 639 err := filesystem.MakeReadOnly(e.Root, func(path string) bool { | 628 err := filesystem.MakeReadOnly(e.Root, func(path string) bool { |
| 640 switch path { | 629 switch path { |
| 641 case e.Root, e.completeFlagPath: | 630 case e.Root, e.completeFlagPath: |
| 642 return false | 631 return false |
| 643 default: | 632 default: |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 // panic, since the locking state can no longer be determined. | 740 // panic, since the locking state can no longer be determined. |
| 752 func mustReleaseLock(c context.Context, lock fslock.Handle, fn func() error) err
or { | 741 func mustReleaseLock(c context.Context, lock fslock.Handle, fn func() error) err
or { |
| 753 defer func() { | 742 defer func() { |
| 754 if err := lock.Unlock(); err != nil { | 743 if err := lock.Unlock(); err != nil { |
| 755 errors.Log(c, errors.Annotate(err).Reason("failed to rel
ease lock").Err()) | 744 errors.Log(c, errors.Annotate(err).Reason("failed to rel
ease lock").Err()) |
| 756 panic(err) | 745 panic(err) |
| 757 } | 746 } |
| 758 }() | 747 }() |
| 759 return fn() | 748 return fn() |
| 760 } | 749 } |
| OLD | NEW |