jiri: Change jiri rebuild to rebuild all tools

Also move manifest description into a help topic.

MultiPart: 1/2

Change-Id: Ic9876445501ba6cc38e8f9185ffea595e4fb8f65
diff --git a/cmd.go b/cmd.go
index 8caf975..a3f6e93 100644
--- a/cmd.go
+++ b/cmd.go
@@ -42,6 +42,9 @@
 		cmdUpdate,
 		cmdVersion,
 	},
+	Topics: []cmdline.Topic{
+		topicManifest,
+	},
 }
 
 // cmdVersion represents the "jiri version" command.
@@ -56,3 +59,44 @@
 	fmt.Fprintf(env.Stdout, "jiri tool version %v\n", tool.Version)
 	return nil
 }
+
+var topicManifest = cmdline.Topic{
+	Name:  "manifest",
+	Short: "Description of manifest files",
+	Long: `
+Jiri manifests are revisioned and stored in a "manifest" repository, that is
+available locally in $JIRI_ROOT/.manifest. The manifest uses the following XML
+schema:
+
+ <manifest>
+   <imports>
+     <import name="default"/>
+     ...
+   </imports>
+   <projects>
+     <project name="release.go.jiri"
+              path="release/go/src/v.io/jiri"
+              protocol="git"
+              name="https://vanadium.googlesource.com/release.go.jiri"
+              revision="HEAD"/>
+     ...
+   </projects>
+   <tools>
+     <tool name="jiri" package="v.io/jiri"/>
+     ...
+   </tools>
+ </manifest>
+
+The <import> element can be used to share settings across multiple
+manifests. Import names are interpreted relative to the $JIRI_ROOT/.manifest/v2
+directory. Import cycles are not allowed and if a project or a tool is specified
+multiple times, the last specification takes effect. In particular, the elements
+<project name="foo" exclude="true"/> and <tool name="bar" exclude="true"/> can
+be used to exclude previously included projects and tools.
+
+The tool identifies which manifest to use using the following algorithm. If the
+$JIRI_ROOT/.local_manifest file exists, then it is used. Otherwise, the
+$JIRI_ROOT/.manifest/v2/<manifest>.xml file is used, where <manifest> is the
+value of the -manifest command-line flag, which defaults to "default".
+`,
+}
diff --git a/doc.go b/doc.go
index ddbc905..3940c48 100644
--- a/doc.go
+++ b/doc.go
@@ -15,12 +15,15 @@
    cl           Manage project changelists
    contributors List project contributors
    project      Manage the jiri projects
-   rebuild      Rebuild the jiri command line tool
+   rebuild      Rebuild all jiri tools
    snapshot     Manage project snapshots
    update       Update all jiri tools and projects
    version      Print version
    help         Display help for commands or topics
 
+The jiri additional help topics are:
+   manifest    Description of manifest files
+
 The jiri flags are:
  -color=true
    Use color to format output.
@@ -233,9 +236,14 @@
  -manifest=
    Name of the project manifest.
 
-Jiri rebuild - Rebuild the jiri command line tool
+Jiri rebuild - Rebuild all jiri tools
 
-Rebuild the jiri command line tool.
+Rebuilds all jiri tools and installs the resulting binaries into
+$JIRI_ROOT/devtools/bin. This is similar to "jiri update", but does not update
+any projects before building the tools. The set of tools to rebuild is described
+in the manifest.
+
+Run "jiri help manifest" for details on manifests.
 
 Usage:
    jiri rebuild
@@ -312,48 +320,13 @@
 
 Jiri update - Update all jiri tools and projects
 
-Updates all jiri projects, builds the latest version of jiri tools, and installs
-the resulting binaries into $JIRI_ROOT/devtools/bin. The sequence in which the
+Updates all projects, builds the latest version of all tools, and installs the
+resulting binaries into $JIRI_ROOT/devtools/bin. The sequence in which the
 individual updates happen guarantees that we end up with a consistent set of
-tools and source code.
+tools and source code. The set of projects and tools to update is described in
+the manifest.
 
-The set of project and tools to update is describe by a manifest. Jiri manifests
-are revisioned and stored in a "manifest" repository, that is available locally
-in $JIRI_ROOT/.manifest. The manifest uses the following XML schema:
-
- <manifest>
-   <imports>
-     <import name="default"/>
-     ...
-   </imports>
-   <projects>
-     <project name="release.go.jiri"
-              path="release/go/src/v.io/jiri"
-              protocol="git"
-              name="https://vanadium.googlesource.com/release.go.jiri"
-              revision="HEAD"/>
-     ...
-   </projects>
-   <tools>
-     <tool name="jiri" package="v.io/jiri"/>
-     ...
-   </tools>
- </manifest>
-
-The <import> element can be used to share settings across multiple manifests.
-Import names are interpreted relative to the $JIRI_ROOT/.manifest/v2 directory.
-Import cycles are not allowed and if a project or a tool is specified multiple
-times, the last specification takes effect. In particular, the elements <project
-name="foo" exclude="true"/> and <tool name="bar" exclude="true"/> can be used to
-exclude previously included projects and tools.
-
-The tool identifies which manifest to use using the following algorithm. If the
-$JIRI_ROOT/.local_manifest file exists, then it is used. Otherwise, the
-$JIRI_ROOT/.manifest/v2/<manifest>.xml file is used, which <manifest> is the
-value of the -manifest command-line flag, which defaults to "default".
-
-NOTE: Unlike the jiri tool commands, the above manifest file format is not an
-API. It is an implementation and can change without notice.
+Run "jiri help manifest" for details on manifests.
 
 Usage:
    jiri update [flags]
@@ -397,5 +370,42 @@
    Format output to this target width in runes, or unlimited if width < 0.
    Defaults to the terminal width if available.  Override the default by setting
    the CMDLINE_WIDTH environment variable.
+
+Jiri manifest - Description of manifest files
+
+Jiri manifests are revisioned and stored in a "manifest" repository, that is
+available locally in $JIRI_ROOT/.manifest. The manifest uses the following XML
+schema:
+
+ <manifest>
+   <imports>
+     <import name="default"/>
+     ...
+   </imports>
+   <projects>
+     <project name="release.go.jiri"
+              path="release/go/src/v.io/jiri"
+              protocol="git"
+              name="https://vanadium.googlesource.com/release.go.jiri"
+              revision="HEAD"/>
+     ...
+   </projects>
+   <tools>
+     <tool name="jiri" package="v.io/jiri"/>
+     ...
+   </tools>
+ </manifest>
+
+The <import> element can be used to share settings across multiple manifests.
+Import names are interpreted relative to the $JIRI_ROOT/.manifest/v2 directory.
+Import cycles are not allowed and if a project or a tool is specified multiple
+times, the last specification takes effect. In particular, the elements <project
+name="foo" exclude="true"/> and <tool name="bar" exclude="true"/> can be used to
+exclude previously included projects and tools.
+
+The tool identifies which manifest to use using the following algorithm. If the
+$JIRI_ROOT/.local_manifest file exists, then it is used. Otherwise, the
+$JIRI_ROOT/.manifest/v2/<manifest>.xml file is used, where <manifest> is the
+value of the -manifest command-line flag, which defaults to "default".
 */
 package main
diff --git a/rebuild.go b/rebuild.go
index 37a45af..577c1d8 100644
--- a/rebuild.go
+++ b/rebuild.go
@@ -17,21 +17,25 @@
 var cmdRebuild = &cmdline.Command{
 	Runner: cmdline.RunnerFunc(runRebuild),
 	Name:   "rebuild",
-	Short:  "Rebuild the jiri command line tool",
-	Long:   "Rebuild the jiri command line tool.",
+	Short:  "Rebuild all jiri tools",
+	Long: `
+Rebuilds all jiri tools and installs the resulting binaries into
+$JIRI_ROOT/devtools/bin. This is similar to "jiri update", but does not update
+any projects before building the tools. The set of tools to rebuild is described
+in the manifest.
+
+Run "jiri help manifest" for details on manifests.
+`,
 }
 
-// Implements cmdRebuild.  This function is like project.BuildTools except it
-// only builds the jiri tool.  We also don't update anything before we do so.
 func runRebuild(env *cmdline.Env, args []string) (e error) {
 	ctx := tool.NewContextFromEnv(env)
-
 	_, tools, err := project.ReadManifest(ctx)
 	if err != nil {
 		return err
 	}
 
-	// Create a temporary directory in which jiri will be built.
+	// Create a temporary directory in which tools will be built.
 	tmpDir, err := ctx.Run().TempDir("", "tmp-jiri-rebuild")
 	if err != nil {
 		return fmt.Errorf("TempDir() failed: %v", err)
@@ -41,16 +45,13 @@
 	defer collect.Error(func() error { return ctx.Run().RemoveAll(tmpDir) }, &e)
 
 	// Paranoid sanity checking.
-	jiriTool, ok := tools[project.JiriName]
-	if !ok {
-		return fmt.Errorf("jiri tool (%s) not found", project.JiriName)
+	if _, ok := tools[project.JiriName]; !ok {
+		return fmt.Errorf("tool %q not found", project.JiriName)
 	}
 
-	// Build jiri.
-	if err = project.BuildTools(ctx, project.Tools{jiriTool.Name: jiriTool}, tmpDir); err != nil {
+	// Build and install tools.
+	if err := project.BuildTools(ctx, tools, tmpDir); err != nil {
 		return err
 	}
-
-	// Install jiri.
 	return project.InstallTools(ctx, tmpDir)
 }
diff --git a/update.go b/update.go
index 7a5a61e..5576500 100644
--- a/update.go
+++ b/update.go
@@ -32,52 +32,13 @@
 	Name:   "update",
 	Short:  "Update all jiri tools and projects",
 	Long: `
-Updates all jiri projects, builds the latest version of jiri
-tools, and installs the resulting binaries into
-$JIRI_ROOT/devtools/bin. The sequence in which the individual updates
-happen guarantees that we end up with a consistent set of tools and
-source code.
+Updates all projects, builds the latest version of all tools, and installs the
+resulting binaries into $JIRI_ROOT/devtools/bin. The sequence in which the
+individual updates happen guarantees that we end up with a consistent set of
+tools and source code. The set of projects and tools to update is described in
+the manifest.
 
-The set of project and tools to update is describe by a
-manifest. Jiri manifests are revisioned and stored in a "manifest"
-repository, that is available locally in $JIRI_ROOT/.manifest. The
-manifest uses the following XML schema:
-
- <manifest>
-   <imports>
-     <import name="default"/>
-     ...
-   </imports>
-   <projects>
-     <project name="release.go.jiri"
-              path="release/go/src/v.io/jiri"
-              protocol="git"
-              name="https://vanadium.googlesource.com/release.go.jiri"
-              revision="HEAD"/>
-     ...
-   </projects>
-   <tools>
-     <tool name="jiri" package="v.io/jiri"/>
-     ...
-   </tools>
- </manifest>
-
-The <import> element can be used to share settings across multiple
-manifests. Import names are interpreted relative to the
-$JIRI_ROOT/.manifest/v2 directory. Import cycles are not allowed and
-if a project or a tool is specified multiple times, the last
-specification takes effect. In particular, the elements <project
-name="foo" exclude="true"/> and <tool name="bar" exclude="true"/> can
-be used to exclude previously included projects and tools.
-
-The tool identifies which manifest to use using the following
-algorithm. If the $JIRI_ROOT/.local_manifest file exists, then it is
-used. Otherwise, the $JIRI_ROOT/.manifest/v2/<manifest>.xml file is
-used, which <manifest> is the value of the -manifest command-line
-flag, which defaults to "default".
-
-NOTE: Unlike the jiri tool commands, the above manifest file format
-is not an API. It is an implementation and can change without notice.
+Run "jiri help manifest" for details on manifests.
 `,
 }