| 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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 } | 509 } |
| 510 | 510 |
| 511 // Identify the virtualenv directory: will have "virtualenv-" prefix. | 511 // Identify the virtualenv directory: will have "virtualenv-" prefix. |
| 512 matches, err := filepath.Glob(filepath.Join(pkgDir, "virtualenv-*")) | 512 matches, err := filepath.Glob(filepath.Join(pkgDir, "virtualenv-*")) |
| 513 if err != nil { | 513 if err != nil { |
| 514 return errors.Annotate(err).Reason("failed to glob for 'virtuale
nv-' directory").Err() | 514 return errors.Annotate(err).Reason("failed to glob for 'virtuale
nv-' directory").Err() |
| 515 } | 515 } |
| 516 if len(matches) == 0 { | 516 if len(matches) == 0 { |
| 517 return errors.Reason("no 'virtualenv-' directory provided by pac
kage").Err() | 517 return errors.Reason("no 'virtualenv-' directory provided by pac
kage").Err() |
| 518 } | 518 } |
| 519 venvDir := matches[0] |
| 519 | 520 |
| 520 logging.Debugf(c, "Creating VirtualEnv at: %s", e.Root) | 521 logging.Debugf(c, "Creating VirtualEnv at: %s", e.Root) |
| 521 cmd := e.Config.systemInterpreter().IsolatedCommand(c, | 522 cmd := e.Config.systemInterpreter().IsolatedCommand(c, |
| 522 "virtualenv.py", | 523 "virtualenv.py", |
| 523 "--no-download", | 524 "--no-download", |
| 524 e.Root) | 525 e.Root) |
| 525 » cmd.Dir = matches[0] | 526 » cmd.Dir = venvDir |
| 526 attachOutputForLogging(c, logging.Debug, cmd) | 527 attachOutputForLogging(c, logging.Debug, cmd) |
| 527 if err := cmd.Run(); err != nil { | 528 if err := cmd.Run(); err != nil { |
| 528 return errors.Annotate(err).Reason("failed to create VirtualEnv"
).Err() | 529 return errors.Annotate(err).Reason("failed to create VirtualEnv"
).Err() |
| 530 } |
| 531 |
| 532 logging.Debugf(c, "Making VirtualEnv relocatable at: %s", e.Root) |
| 533 cmd = e.Interpreter().IsolatedCommand(c, |
| 534 "virtualenv.py", |
| 535 "--relocatable", |
| 536 e.Root) |
| 537 cmd.Dir = venvDir |
| 538 attachOutputForLogging(c, logging.Debug, cmd) |
| 539 if err := cmd.Run(); err != nil { |
| 540 return errors.Annotate(err).Reason("failed to create VirtualEnv"
).Err() |
| 529 } | 541 } |
| 530 | 542 |
| 531 return nil | 543 return nil |
| 532 } | 544 } |
| 533 | 545 |
| 534 // getPEP425Tags calls Python's pip.pep425tags package to retrieve the tags. | 546 // getPEP425Tags calls Python's pip.pep425tags package to retrieve the tags. |
| 535 // | 547 // |
| 536 // This must be run while "pip" is installed in the VirtualEnv. | 548 // This must be run while "pip" is installed in the VirtualEnv. |
| 537 func (e *Env) getPEP425Tags(c context.Context) ([]*vpython.Pep425Tag, error) { | 549 func (e *Env) getPEP425Tags(c context.Context) ([]*vpython.Pep425Tag, error) { |
| 538 // This script will return a list of 3-entry lists: | 550 // This script will return a list of 3-entry lists: |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 // panic, since the locking state can no longer be determined. | 752 // panic, since the locking state can no longer be determined. |
| 741 func mustReleaseLock(c context.Context, lock fslock.Handle, fn func() error) err
or { | 753 func mustReleaseLock(c context.Context, lock fslock.Handle, fn func() error) err
or { |
| 742 defer func() { | 754 defer func() { |
| 743 if err := lock.Unlock(); err != nil { | 755 if err := lock.Unlock(); err != nil { |
| 744 errors.Log(c, errors.Annotate(err).Reason("failed to rel
ease lock").Err()) | 756 errors.Log(c, errors.Annotate(err).Reason("failed to rel
ease lock").Err()) |
| 745 panic(err) | 757 panic(err) |
| 746 } | 758 } |
| 747 }() | 759 }() |
| 748 return fn() | 760 return fn() |
| 749 } | 761 } |
| OLD | NEW |