コード例 #1
0
ファイル: reader.go プロジェクト: vanadium/go.jiri
// MergeEnvFromProfiles merges the embedded environment with the environment
// variables stored in the requested profiles. The profiles are those read from
// the manifest. It will also expand all instances of ${JIRI_ROOT} in the
// returned environment.
func (rd *Reader) MergeEnvFromProfiles(policies map[string]MergePolicy, target profiles.Target, profileNames ...string) {
	envs := [][]string{}
	for _, name := range profileNames {
		installer, profile := profiles.SplitProfileName(name)
		e := rd.pdb.EnvFromProfile(installer, profile, target)
		if e == nil {
			continue
		}
		envs = append(envs, e)
	}
	MergeEnv(policies, rd.Vars, envs...)
	jiri.ExpandEnv(rd.jirix, rd.Vars)
}
コード例 #2
0
func RunMojoShell(mojoUrl, configFile string, configAliases map[string]string, argsFor map[string][]string, target profiles.Target) *exec.Cmd {
	// ensure the profiles are loaded
	jirix, err := jiri.NewX(cmdline.EnvFromOS())
	if err != nil {
		panic(err)
	}
	rd, err := profilesreader.NewReader(jirix, profilesreader.UseProfiles, filepath.Join(jirix.Root, ".jiri_root", "profile_db"))
	if err != nil {
		panic(err)
	}

	envslice := rd.EnvFromProfile(mojoProfileName(), target)
	env := envvar.VarsFromSlice(envslice)
	jiri.ExpandEnv(jirix, env)
	var mojoDevtools, mojoShell, mojoServices string
	for _, e := range env.ToSlice() {
		parts := strings.SplitN(e, "=", 2)
		switch parts[0] {
		case "MOJO_DEVTOOLS":
			mojoDevtools = parts[1]
		case "MOJO_SHELL":
			mojoShell = parts[1]
		case "MOJO_SERVICES":
			mojoServices = parts[1]
		}
	}
	args := []string{
		mojoUrl,
		"--config-file", configFile,
		"--shell-path", mojoShell,
		"--enable-multiprocess"}
	if target.OS() == "android" {
		args = append(args, "--android")
		args = append(args, "--origin", mojoServices)
	}
	for alias, value := range configAliases {
		args = append(args, "--config-alias", fmt.Sprintf("%s=%s", alias, value))
	}
	for key, value := range argsFor {
		args = append(args, fmt.Sprintf("--args-for=%s %s", key, strings.Join(value, " ")))
	}
	return exec.Command(filepath.Join(mojoDevtools, "mojo_run"), args...)
}