Freeze environment reading after saving deps
Any reads after the deps are saved won't show up as dependencies later. So panic if new environment variables are read after saving deps. Change-Id: Ia51deaf750804d3b99e69c001939a104c2d8c9f2
This commit is contained in:
@@ -48,8 +48,9 @@ type config struct {
|
|||||||
|
|
||||||
srcDir string // the path of the root source directory
|
srcDir string // the path of the root source directory
|
||||||
|
|
||||||
envLock sync.Mutex
|
envLock sync.Mutex
|
||||||
envDeps map[string]string
|
envDeps map[string]string
|
||||||
|
envFrozen bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type jsonConfigurable interface {
|
type jsonConfigurable interface {
|
||||||
@@ -178,6 +179,9 @@ func (c *config) Getenv(key string) string {
|
|||||||
var exists bool
|
var exists bool
|
||||||
c.envLock.Lock()
|
c.envLock.Lock()
|
||||||
if val, exists = c.envDeps[key]; !exists {
|
if val, exists = c.envDeps[key]; !exists {
|
||||||
|
if c.envFrozen {
|
||||||
|
panic("Cannot access new environment variables after envdeps are frozen")
|
||||||
|
}
|
||||||
val = os.Getenv(key)
|
val = os.Getenv(key)
|
||||||
c.envDeps[key] = val
|
c.envDeps[key] = val
|
||||||
}
|
}
|
||||||
@@ -186,6 +190,9 @@ func (c *config) Getenv(key string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *config) EnvDeps() map[string]string {
|
func (c *config) EnvDeps() map[string]string {
|
||||||
|
c.envLock.Lock()
|
||||||
|
c.envFrozen = true
|
||||||
|
c.envLock.Unlock()
|
||||||
return c.envDeps
|
return c.envDeps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user