本文整理汇总了Golang中v/io/x/lib/envvar.Vars.Set方法的典型用法代码示例。如果您正苦于以下问题:Golang Vars.Set方法的具体用法?Golang Vars.Set怎么用?Golang Vars.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类v/io/x/lib/envvar.Vars
的用法示例。
在下文中一共展示了Vars.Set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ExpandEnv
// ExpandEnv expands all instances of the JIRI_ROOT variable in the supplied
// environment with the root from jirix.
func ExpandEnv(x *X, env *envvar.Vars) {
e := env.ToMap()
rootEnv := "${" + RootEnv + "}"
for k, v := range e {
n := strings.Replace(v, rootEnv, x.Root, -1)
if n != v {
env.Set(k, n)
}
}
}
示例2: setNaclEnv
// setNaclEnv sets the environment variables used for nacl
// cross-compilation.
func setNaclEnv(ctx *tool.Context, env *envvar.Vars, root string) error {
env.Set("GOARCH", "amd64p32")
env.Set("GOOS", "nacl")
// Add the path to nacl cross-compiler to the PATH.
path := env.GetTokens("PATH", ":")
path = append([]string{
filepath.Join(root, "third_party", "repos", "go_ppapi", "bin"),
}, path...)
env.SetTokens("PATH", path, ":")
return nil
}
示例3: MergeEnv
// MergeEnv merges vars with the variables in env taking care to concatenate
// values as per the concat and ignore parameters similarly to SetEnvFromProfiles.
func MergeEnv(concat map[string]string, ignore map[string]bool, env *envvar.Vars, vars ...[]string) {
for _, ev := range vars {
for _, tmp := range ev {
k, v := envvar.SplitKeyValue(tmp)
if ignore[k] {
continue
}
if sep := concat[k]; len(sep) > 0 {
ov := env.GetTokens(k, sep)
nv := envvar.SplitTokens(v, sep)
env.SetTokens(k, append(ov, nv...), " ")
continue
}
env.Set(k, v)
}
}
}
示例4: MergeEnv
// MergeEnv merges environment variables in base with those
// in vars according to the suppled policies.
func MergeEnv(policies map[string]MergePolicy, base *envvar.Vars, vars ...[]string) {
// Remove any variables that have the IgnoreBase policy.
for k, _ := range base.ToMap() {
switch policies[k].Action {
case Ignore, IgnoreBaseAndAppend, IgnoreBaseAndPrepend, IgnoreBaseAndUseFirst, IgnoreBaseAndUseLast:
base.Delete(k)
}
}
for _, ev := range vars {
for _, tmp := range ev {
k, v := envvar.SplitKeyValue(tmp)
policy := policies[k]
action := policy.Action
switch policy.Action {
case IgnoreBaseAndAppend:
action = Append
case IgnoreBaseAndPrepend:
action = Prepend
case IgnoreBaseAndUseLast:
action = Last
case IgnoreBaseAndUseFirst:
action = First
}
switch action {
case Ignore, IgnoreProfiles:
continue
case Append, Prepend:
sep := policy.Separator
ov := base.GetTokens(k, sep)
nv := envvar.SplitTokens(v, sep)
if action == Append {
base.SetTokens(k, append(ov, nv...), sep)
} else {
base.SetTokens(k, append(nv, ov...), sep)
}
case First:
if !base.Contains(k) {
base.Set(k, v)
}
case Last:
base.Set(k, v)
}
}
}
}
示例5: setAndroidEnv
// setAndroidEnv sets the environment variables used for android
// cross-compilation.
func setAndroidEnv(ctx *tool.Context, env *envvar.Vars, root string) error {
// Compile using Android Go 1.5 (installed via
// 'jiri profile install android').
androidGoDir := filepath.Join(root, "third_party", "android", "go")
// Set Go-specific environment variables.
env.Set("GOARCH", "arm")
env.Set("GOARM", "7")
env.Set("GOOS", "android")
env.Set("GOROOT", androidGoDir)
// Update PATH.
if _, err := ctx.Run().Stat(androidGoDir); err != nil {
return fmt.Errorf("Couldn't find android Go installation directory %s: did you run \"jiri profile install android\"?", androidGoDir)
}
path := env.GetTokens("PATH", ":")
path = append([]string{filepath.Join(androidGoDir, "bin")}, path...)
env.SetTokens("PATH", path, ":")
return nil
}
示例6: setArmEnv
// setArmEnv sets the environment variables used for arm cross-compilation.
func setArmEnv(ctx *tool.Context, env *envvar.Vars, root string) error {
// Set Go specific environment variables.
env.Set("GOARCH", "arm")
env.Set("GOARM", "6")
env.Set("GOOS", "linux")
// Add the paths to arm cross-compilation tools to the PATH.
path := env.GetTokens("PATH", ":")
path = append([]string{
filepath.Join(root, "third_party", "cout", "xgcc", "cross_arm"),
filepath.Join(root, "third_party", "repos", "go_arm", "bin"),
}, path...)
env.SetTokens("PATH", path, ":")
return nil
}