github.com/vanadium-archive/go.jiri@v0.0.0-20160715023856-abfb8b131290/cmd/jiri/rebuild.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 "fmt" 9 10 "v.io/jiri" 11 "v.io/jiri/collect" 12 "v.io/jiri/project" 13 "v.io/x/lib/cmdline" 14 ) 15 16 // cmdRebuild represents the "jiri rebuild" command. 17 var cmdRebuild = &cmdline.Command{ 18 Runner: jiri.RunnerFunc(runRebuild), 19 Name: "rebuild", 20 Short: "Rebuild all jiri tools", 21 Long: ` 22 Rebuilds all jiri tools and installs the resulting binaries into 23 $JIRI_ROOT/.jiri_root/bin. This is similar to "jiri update", but does not update 24 any projects before building the tools. The set of tools to rebuild is described 25 in the manifest. 26 27 Run "jiri help manifest" for details on manifests. 28 `, 29 } 30 31 func runRebuild(jirix *jiri.X, args []string) (e error) { 32 projects, tools, err := project.LoadManifest(jirix) 33 if err != nil { 34 return err 35 } 36 37 // Create a temporary directory in which tools will be built. 38 tmpDir, err := jirix.NewSeq().TempDir("", "tmp-jiri-rebuild") 39 if err != nil { 40 return fmt.Errorf("TempDir() failed: %v", err) 41 } 42 43 // Make sure we cleanup the temp directory. 44 defer collect.Error(func() error { return jirix.NewSeq().RemoveAll(tmpDir).Done() }, &e) 45 46 // Paranoid sanity checking. 47 if _, ok := tools[project.JiriName]; !ok { 48 return fmt.Errorf("tool %q not found", project.JiriName) 49 } 50 51 // Build and install tools. 52 if err := project.BuildTools(jirix, projects, tools, tmpDir); err != nil { 53 return err 54 } 55 return project.InstallTools(jirix, tmpDir) 56 }