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) }
func packagesImpl(jirix *jiri.X, cl *packagesFlagValues, args []string) error { mgrs, _, err := availableProfileManagers(jirix, cl.dbPath, args) if err != nil { return err } cl.target.UseCommandLineEnv() root := jiri.NewRelPath(cl.root).Join(profileInstaller) s := jirix.NewSeq() installPackages := cl.installPackages // Never ask a subcommand to install packages. cl.installPackages = false for _, mgr := range mgrs { cmds, err := mgr.packageCmds(jirix, cl, root) if err != nil { return err } for _, cmd := range cmds { if installPackages { if err := s.Verbose(true).Last(cmd[0], cmd[1:]...); err != nil { return err } } else { fmt.Fprintf(jirix.Stdout(), "%s\n", strings.TrimSpace(strings.Join(cmd, " "))) } } } return nil }
func cleanupImpl(jirix *jiri.X, cl *cleanupFlagValues, args []string) error { count := 0 if cl.gc { count++ } if cl.rewriteDB { count++ } if cl.rmAll { count++ } if count != 1 { fmt.Errorf("exactly one option must be specified") } mgrs, db, err := installedProfileManagers(jirix, cl.dbPath, args) if err != nil { return err } root := jiri.NewRelPath(cl.root).Join(profileInstaller) for _, mgr := range mgrs { if err := mgr.cleanup(jirix, cl, root); err != nil { return err } } if !cl.rmAll { return writeDB(jirix, db, profileInstaller, cl.dbPath) } return nil }
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 }
func updateImpl(jirix *jiri.X, cl *updateFlagValues, args []string) error { mgrs, db, err := availableProfileManagers(jirix, cl.dbPath, args) if err != nil { return err } root := jiri.NewRelPath(cl.root).Join(profileInstaller) for _, mgr := range mgrs { if err := mgr.update(jirix, cl, root); err != nil { return err } } return writeDB(jirix, db, profileInstaller, cl.dbPath) }
func uninstallImpl(jirix *jiri.X, cl *uninstallFlagValues, args []string) error { mgrs, db, err := availableProfileManagers(jirix, cl.dbPath, args) if err != nil { return err } if cl.allTargets && cl.target.IsSet() { fmt.Fprintf(jirix.Stdout(), "ignore target (%v) when used in conjunction with --all-targets\n", cl.target) } root := jiri.NewRelPath(cl.root).Join(profileInstaller) for _, mgr := range mgrs { if err := mgr.uninstall(jirix, cl, root); err != nil { return err } } return writeDB(jirix, db, profileInstaller, cl.dbPath) }
func ExampleManager() { pdb := profiles.NewDB() myInstaller := "myProject" myProfile := "myNewProfile" profileName := profiles.QualifiedProfileName(myInstaller, myProfile) var target profiles.Target init := func() { mgr := newProfileMgr(myInstaller, myProfile) profilesmanager.Register(mgr) flags := flag.NewFlagSet("example", flag.ContinueOnError) profiles.RegisterTargetAndEnvFlags(flags, &target) flags.Parse([]string{"--target=arm-linux@1", "--env=A=B,C=D", "--env=E=F"}) } init() profileRoot := jiri.NewRelPath("profiles") mgr := profilesmanager.LookupManager(profileName) if mgr == nil { panic("manager not found for: " + profileName) } jirix := &jiri.X{Context: tool.NewDefaultContext()} // Install myNewProfile for target. if err := mgr.Install(jirix, pdb, profileRoot, target); err != nil { panic("failed to find manager for: " + profileName) } fmt.Println(mgr.String()) filename := tmpFile() defer os.RemoveAll(filepath.Dir(filename)) if err := pdb.Write(jirix, "test", filename); err != nil { panic(err) } // Start with a new profile data base. pdb = profiles.NewDB() // Read the profile database. pdb.Read(jirix, filename) mgr = profilesmanager.LookupManager(profileName) if mgr == nil { panic("manager not found for: " + profileName) } fmt.Println(mgr.String()) mgr.Uninstall(jirix, pdb, profileRoot, target) fmt.Println(mgr.String()) fmt.Println(mgr.VersionInfo().Supported()) fmt.Println(mgr.VersionInfo().Default()) // Output: // Profile: myNewProfile: installed // [arm-linux@1] // // Profile: myNewProfile: installed // [arm-linux@1] // // Profile: myNewProfile: not installed // // [4 3 2] // 3 }