github.com/vanadium-archive/go.jiri@v0.0.0-20160715023856-abfb8b131290/cmd/jiri/update.go (about) 1 // Copyright 2015 The Vanadium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "v.io/jiri" 9 "v.io/jiri/project" 10 "v.io/jiri/retry" 11 "v.io/jiri/tool" 12 "v.io/x/lib/cmdline" 13 ) 14 15 var ( 16 gcFlag bool 17 attemptsFlag int 18 ) 19 20 func init() { 21 tool.InitializeProjectFlags(&cmdUpdate.Flags) 22 23 cmdUpdate.Flags.BoolVar(&gcFlag, "gc", false, "Garbage collect obsolete repositories.") 24 cmdUpdate.Flags.IntVar(&attemptsFlag, "attempts", 1, "Number of attempts before failing.") 25 } 26 27 // cmdUpdate represents the "jiri update" command. 28 var cmdUpdate = &cmdline.Command{ 29 Runner: jiri.RunnerFunc(runUpdate), 30 Name: "update", 31 Short: "Update all jiri tools and projects", 32 Long: ` 33 Updates all projects, builds the latest version of all tools, and installs the 34 resulting binaries into $JIRI_ROOT/.jiri_root/bin. The sequence in which the 35 individual updates happen guarantees that we end up with a consistent set of 36 tools and source code. The set of projects and tools to update is described in 37 the manifest. 38 39 Run "jiri help manifest" for details on manifests. 40 `, 41 } 42 43 func runUpdate(jirix *jiri.X, _ []string) error { 44 seq := jirix.NewSeq() 45 // Create the $JIRI_ROOT/.jiri_root directory if it doesn't already exist. 46 // 47 // TODO(toddw): Remove this logic after the transition to .jiri_root is done. 48 // The bootstrapping logic should create this directory, and jiri should fail 49 // if the directory doesn't exist. 50 if err := seq.MkdirAll(jirix.RootMetaDir(), 0755).Done(); err != nil { 51 return err 52 } 53 54 // Update all projects to their latest version. 55 // Attempt <attemptsFlag> times before failing. 56 updateFn := func() error { return project.UpdateUniverse(jirix, gcFlag) } 57 if err := retry.Function(jirix.Context, updateFn, retry.AttemptsOpt(attemptsFlag)); err != nil { 58 return err 59 } 60 if err := project.WriteUpdateHistorySnapshot(jirix, ""); err != nil { 61 return err 62 } 63 64 // Only attempt the bin dir transition after the update has succeeded, to 65 // avoid messy partial states. 66 return project.TransitionBinDir(jirix) 67 }