示例#1
0
func (ip *inproc) update(jirix *jiri.X, cl *updateFlagValues, root jiri.RelPath) error {
	profile := ip.db.LookupProfile(ip.installer, ip.name)
	if profile == nil {
		// silently ignore uninstalled profile.
		return nil
	}
	mgr := profilesmanager.LookupManager(ip.qname)
	vi := mgr.VersionInfo()
	for _, target := range profile.Targets() {
		if vi.IsTargetOlderThanDefault(target.Version()) {
			// Check if default target is already installed.
			defTarget := *target
			defTarget.SetVersion(vi.Default())
			if profiles.FindTarget(profile.Targets(), &defTarget) != nil {
				// Default target is already installed.  Skip.
				continue
			}
			if cl.verbose {
				fmt.Fprintf(jirix.Stdout(), "Updating %s %s from %q to %s\n", ip.qname, target, target.Version(), vi)
			}
			err := mgr.Install(jirix, ip.db, root, defTarget)
			logResult(jirix, "Update", mgr, defTarget, err)
			if err != nil {
				return err
			}
		} else {
			if cl.verbose {
				fmt.Fprintf(jirix.Stdout(), "%s %s at %q is up to date(%s)\n", ip.qname, target, target.Version(), vi)
			}
		}
	}
	return nil
}
示例#2
0
func TestFindTarget(t *testing.T) {
	t1 := &profiles.Target{}
	t1.Set("a-o")
	ts := []*profiles.Target{t1}
	prev := os.Getenv("GOARCH")
	if len(prev) > 0 {
		// Clear GOARCH so that DefaultTarget is not set.
		os.Setenv("GOARCH", "")
		defer os.Setenv("GOARCH", prev)
	}
	def := profiles.DefaultTarget()
	if got, want := profiles.FindTargetWithDefault(ts, &def), t1; !got.Match(want) {
		t.Errorf("got %v, want %v", got, want)
	}
	t2 := &profiles.Target{}
	t2.Set("a-o1")
	ts = append(ts, t2)
	if got := profiles.FindTarget(ts, &def); got != nil {
		t.Errorf("got %v, want nil", got)
	}

	w := &profiles.Target{}
	w.Set("a-o")
	if got, want := profiles.FindTarget(ts, w), t1; !got.Match(want) {
		t.Errorf("got %v, want %v", got, want)
	}

	w.Set("a-o1")
	if got, want := profiles.FindTarget(ts, w), t2; !got.Match(want) {
		t.Errorf("got %v, want %v", got, want)
	}

	w.Set("c-d")
	if got := profiles.FindTarget(ts, w); got != nil {
		t.Errorf("got %v, want nil", got)
	}
}
示例#3
0
文件: driver.go 项目: 4shome/go.jiri
func runEnv(env *cmdline.Env, args []string) error {
	if len(profileFlag) == 0 {
		return fmt.Errorf("no profile was specified using --profile")
	}
	ctx := tool.NewContextFromEnv(env)
	if err := profiles.Read(ctx, manifestFlag); err != nil {
		return fmt.Errorf("Failed to read manifest: %v", err)
	}
	profile := profiles.LookupProfile(profileFlag)
	if profile == nil {
		return fmt.Errorf("profile %q is not installed", profileFlag)
	}
	target := profiles.FindTarget(profile.Targets(), &targetFlag)
	if target == nil {
		return fmt.Errorf("target %q is not installed for profile %q", targetFlag, profileFlag)
	}
	vars := envvar.SliceToMap(target.Env.Vars)
	buf := bytes.Buffer{}
	if len(args) == 0 {
		for k, v := range vars {
			buf.WriteString(fmt.Sprintf("%s=%q ", k, v))
		}
		for k, fn := range pseudoVariables {
			buf.WriteString(fmt.Sprintf("%s=%q ", k, fn(target)))
		}
	} else {
		for _, arg := range args {
			name := strings.TrimSuffix(arg, "=")
			trimmed := name != arg
			for k, fn := range pseudoVariables {
				if k == name {
					buf.WriteString(expr(k, fn(target), trimmed))
				}
			}
			for k, v := range vars {
				if k == name {
					buf.WriteString(expr(k, v, trimmed))
				}
			}
		}
	}
	fmt.Fprintf(ctx.Stdout(), strings.TrimSuffix(buf.String(), " ")+"\n")
	return nil
}