Example #1
0
func installImpl(jirix *jiri.X, cl *installFlagValues, args []string) error {
	mgrs, db, err := availableProfileManagers(jirix, cl.dbPath, args)
	if err != nil {
		return err
	}
	cl.target.UseCommandLineEnv()
	newMgrs := []profileManager{}
	for _, mgr := range mgrs {
		name := mgr.mgrName()
		if !cl.force {
			installer, profile := profiles.SplitProfileName(name)
			if p := db.LookupProfileTarget(installer, profile, cl.target); p != nil {
				fmt.Fprintf(jirix.Stdout(), "%v %v is already installed as %v\n", name, cl.target, p)
				continue
			}
		}
		newMgrs = append(newMgrs, mgr)
	}
	root := jiri.NewRelPath(cl.root).Join(profileInstaller)
	for _, mgr := range newMgrs {
		if err := mgr.install(jirix, cl, root); err != nil {
			return err
		}
	}
	return writeDB(jirix, db, profileInstaller, cl.dbPath)
}
Example #2
0
func TestQualifiedNames(t *testing.T) {
	for i, c := range []struct{ i, p, e string }{
		{"a", "b", "a:b"},
		{"a", ":b", "a:b"},
		{"a", "", "a:"},
		{"", "b", "b"},
		{"", "", ""},
	} {
		if got, want := profiles.QualifiedProfileName(c.i, c.p), c.e; got != want {
			t.Errorf("%d: got %v, want %v", i, got, want)
		}
	}
	for i, c := range []struct{ q, i, p string }{
		{"aa:bb", "aa", "bb"},
		{":bb", "", "bb"},
		{"bb", "", "bb"},
		{"", "", ""},
		{":bb", "", "bb"},
	} {
		gi, gp := profiles.SplitProfileName(c.q)
		if got, want := gi, c.i; got != want {
			t.Errorf("%d: got %v, want %v", i, got, want)
		}
		if got, want := gp, c.p; got != want {
			t.Errorf("%d: got %v, want %v", i, got, want)
		}
	}

	if got, want := profiles.QualifiedProfileName("new", "old:bar"), "new:bar"; got != want {
		t.Errorf("got %v, want %v", got, want)
	}

}
Example #3
0
func newProfileManager(name string, db *profiles.DB) profileManager {
	installer, profile := profiles.SplitProfileName(name)
	installer = strings.TrimSpace(installer)
	if len(installer) == 0 || installer == profileInstaller {
		return &inproc{installer, profile, name, db}
	}
	return &subcommand{installer, profile, name, db}
}
Example #4
0
// ValidateRequestProfilesAndTarget checks that the supplied slice of profiles
// names is supported (including the 'jiri' profile) and that each has
// the specified target installed taking account if running using profiles
// at all or if using old-style profiles.
func (rd *Reader) ValidateRequestedProfilesAndTarget(profileNames []string, target profiles.Target) error {
	if rd.SkippingProfiles() {
		return nil
	}
	for _, name := range profileNames {
		installer, profile := profiles.SplitProfileName(name)
		if rd.pdb.LookupProfileTarget(installer, profile, target) == nil {
			return fmt.Errorf("%q for %q is not available or not installed, use the \"list\" command to see the installed/available profiles.", target, name)
		}
	}
	return nil
}
Example #5
0
// 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)
}
Example #6
0
func fmtInfo(jirix *jiri.X, infoFmt string, rd *profilesreader.Reader, profile *profiles.Profile, target *profiles.Target) (string, error) {
	// Populate an instance listInfo
	info := &listInfo{}
	name := profile.Name()
	installer, _ := profiles.SplitProfileName(name)
	info.SchemaVersion = rd.SchemaVersion()
	info.DBPath = rd.Path()
	if target != nil {
		info.Target.InstallationDir = jiri.NewRelPath(target.InstallationDir).Abs(jirix)
		info.Target.CommandLineEnv = target.CommandLineEnv().Vars
		info.Target.Env = target.Env.Vars
		clenv := ""
		if len(info.Target.CommandLineEnv) > 0 {
			clenv = fmt.Sprintf(" --env=\"%s\" ", strings.Join(info.Target.CommandLineEnv, ","))
		}
		if installer != "" {
			info.Target.Command = fmt.Sprintf("jiri profile install --target=%s %s%s", target, clenv, name)
		} else {
			// TODO(cnicolaou): remove this when the transition is complete.
			info.Target.Command = fmt.Sprintf("jiri v23-profile install --target=%s %s%s", target, clenv, name)
		}
	}
	if profile != nil {
		rp := jiri.NewRelPath(profile.Root())
		info.Profile.Root = rp.Abs(jirix)
		info.Profile.Name = name
		info.Profile.Installer = installer
		info.Profile.DBPath = info.DBPath
		if installer != "" {
			info.Profile.DBPath = filepath.Join(info.DBPath, installer)
		}
	}

	// Use a template to print out any field in our instance of listInfo.
	tmpl, err := template.New("list").Parse("{{ ." + infoFmt + "}}")
	if err != nil {
		return "", err
	}
	out := &bytes.Buffer{}
	if err = tmpl.Execute(out, info); err != nil {
		return "", fmt.Errorf("please specify a supported field:\n%s", infoUsage())
	}
	return out.String(), nil
}
Example #7
0
func cleanupGC(jirix *jiri.X, db *profiles.DB, root jiri.RelPath, verbose bool, name string) error {
	mgr := profilesmanager.LookupManager(name)
	if mgr == nil {
		fmt.Fprintf(jirix.Stderr(), "%s is not linked into this binary\n", name)
		return nil
	}
	vi := mgr.VersionInfo()
	installer, profileName := profiles.SplitProfileName(name)
	profile := db.LookupProfile(installer, profileName)
	for _, target := range profile.Targets() {
		if vi.IsTargetOlderThanDefault(target.Version()) {
			err := mgr.Uninstall(jirix, db, root, *target)
			logResult(jirix, "Cleanup: -gc", mgr, *target, err)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
Example #8
0
// EnvFromProfile obtains the environment variable settings from the specified
// profile and target. It returns nil if the target and/or profile could not
// be found.
func (rd *Reader) EnvFromProfile(name string, target profiles.Target) []string {
	installer, profile := profiles.SplitProfileName(name)
	return rd.pdb.EnvFromProfile(installer, profile, target)
}
Example #9
0
func (rd *Reader) LookupProfileTarget(name string, target profiles.Target) *profiles.Target {
	installer, profile := profiles.SplitProfileName(name)
	return rd.pdb.LookupProfileTarget(installer, profile, target)
}
Example #10
0
func (rd *Reader) LookupProfile(name string) *profiles.Profile {
	installer, profile := profiles.SplitProfileName(name)
	return rd.pdb.LookupProfile(installer, profile)
}