Rename BuildDir and NinjaBuildDir.

These are just out/ and out/soong/ and the old names were quite
confusing.

Test: Presubmits.
Merged-In: Idd9ce3c38a259faabcc56f0cd3fdac8b289123b1
Merged-In: I334ab40c668d2a94536f3e63d5f1fa0b401388ac
Change-Id: Ib7c568c6a97701f2240c5e3f0f2ce67397819ac0
diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go
index d014afb..2554724 100644
--- a/bootstrap/bootstrap.go
+++ b/bootstrap/bootstrap.go
@@ -106,7 +106,7 @@
 
 	bootstrap = pctx.StaticRule("bootstrap",
 		blueprint.RuleParams{
-			Command:     "BUILDDIR=$buildDir $bootstrapCmd -i $in",
+			Command:     "BUILDDIR=$soongOutDir $bootstrapCmd -i $in",
 			CommandDeps: []string{"$bootstrapCmd"},
 			Description: "bootstrap $in",
 			Generator:   true,
@@ -131,8 +131,8 @@
 				`cd / && ` +
 				`env -i "$$BUILDER" ` +
 				`    --top "$$TOP" ` +
-				`    --out "$buildDir" ` +
-				`    -n "$ninjaBuildDir" ` +
+				`    --out "$soongOutDir" ` +
+				`    -n "$outDir" ` +
 				`    -d "$out.d" ` +
 				`    $extra`,
 			CommandDeps: []string{"$builder"},
@@ -160,7 +160,7 @@
 		return toolDir(config), nil
 	})
 
-	bootstrapDir = filepath.Join("$buildDir", bootstrapSubDir)
+	bootstrapDir = filepath.Join("$soongOutDir", bootstrapSubDir)
 )
 
 type GoBinaryTool interface {
@@ -171,14 +171,14 @@
 }
 
 func bootstrapBinDir(config interface{}) string {
-	return filepath.Join(config.(BootstrapConfig).BuildDir(), bootstrapSubDir, "bin")
+	return filepath.Join(config.(BootstrapConfig).SoongOutDir(), bootstrapSubDir, "bin")
 }
 
 func toolDir(config interface{}) string {
 	if c, ok := config.(ConfigBlueprintToolLocation); ok {
 		return filepath.Join(c.BlueprintToolLocation())
 	}
-	return filepath.Join(config.(BootstrapConfig).BuildDir(), "bin")
+	return filepath.Join(config.(BootstrapConfig).SoongOutDir(), "bin")
 }
 
 func pluginDeps(ctx blueprint.BottomUpMutatorContext) {
@@ -334,7 +334,7 @@
 	ctx.VisitDepsDepthFirstIf(isGoPluginFor(name),
 		func(module blueprint.Module) { hasPlugins = true })
 	if hasPlugins {
-		pluginSrc = filepath.Join(moduleGenSrcDir(ctx, g.config), "plugin.go")
+		pluginSrc = filepath.Join(moduleGenSrcDir(ctx), "plugin.go")
 		genSrcs = append(genSrcs, pluginSrc)
 	}
 
@@ -448,14 +448,14 @@
 	if g.properties.Tool_dir {
 		g.installPath = filepath.Join(toolDir(ctx.Config()), name)
 	} else {
-		buildDir := ctx.Config().(BootstrapConfig).BuildDir()
-		g.installPath = filepath.Join(buildDir, bootstrapSubDir, "bin", name)
+		soongOutDir := ctx.Config().(BootstrapConfig).SoongOutDir()
+		g.installPath = filepath.Join(soongOutDir, bootstrapSubDir, "bin", name)
 	}
 
 	ctx.VisitDepsDepthFirstIf(isGoPluginFor(name),
 		func(module blueprint.Module) { hasPlugins = true })
 	if hasPlugins {
-		pluginSrc = filepath.Join(moduleGenSrcDir(ctx, g.config), "plugin.go")
+		pluginSrc = filepath.Join(moduleGenSrcDir(ctx), "plugin.go")
 		genSrcs = append(genSrcs, pluginSrc)
 	}
 
@@ -730,7 +730,7 @@
 	}
 
 	primaryBuilderFile := filepath.Join("$BinDir", primaryBuilderName)
-	ctx.SetNinjaBuildDir(pctx, "${ninjaBuildDir}")
+	ctx.SetOutDir(pctx, "${outDir}")
 
 	for _, subninja := range s.config.subninjas {
 		ctx.AddSubninja(subninja)
@@ -781,16 +781,16 @@
 // directory is where the final package .a files are output and where dependant
 // modules search for this package via -I arguments.
 func packageRoot(ctx blueprint.ModuleContext) string {
-	buildDir := ctx.Config().(BootstrapConfig).BuildDir()
-	return filepath.Join(buildDir, bootstrapSubDir, ctx.ModuleName(), "pkg")
+	soongOutDir := ctx.Config().(BootstrapConfig).SoongOutDir()
+	return filepath.Join(soongOutDir, bootstrapSubDir, ctx.ModuleName(), "pkg")
 }
 
 // testRoot returns the module-specific package root directory path used for
 // building tests. The .a files generated here will include everything from
 // packageRoot, plus the test-only code.
 func testRoot(ctx blueprint.ModuleContext) string {
-	buildDir := ctx.Config().(BootstrapConfig).BuildDir()
-	return filepath.Join(buildDir, bootstrapSubDir, ctx.ModuleName(), "test")
+	soongOutDir := ctx.Config().(BootstrapConfig).SoongOutDir()
+	return filepath.Join(soongOutDir, bootstrapSubDir, ctx.ModuleName(), "test")
 }
 
 // moduleSrcDir returns the path of the directory that all source file paths are
@@ -801,12 +801,12 @@
 
 // moduleObjDir returns the module-specific object directory path.
 func moduleObjDir(ctx blueprint.ModuleContext) string {
-	buildDir := ctx.Config().(BootstrapConfig).BuildDir()
-	return filepath.Join(buildDir, bootstrapSubDir, ctx.ModuleName(), "obj")
+	soongOutDir := ctx.Config().(BootstrapConfig).SoongOutDir()
+	return filepath.Join(soongOutDir, bootstrapSubDir, ctx.ModuleName(), "obj")
 }
 
 // moduleGenSrcDir returns the module-specific generated sources path.
-func moduleGenSrcDir(ctx blueprint.ModuleContext, config *Config) string {
-	buildDir := ctx.Config().(BootstrapConfig).BuildDir()
-	return filepath.Join(buildDir, bootstrapSubDir, ctx.ModuleName(), "gen")
+func moduleGenSrcDir(ctx blueprint.ModuleContext) string {
+	soongOutDir := ctx.Config().(BootstrapConfig).SoongOutDir()
+	return filepath.Join(soongOutDir, bootstrapSubDir, ctx.ModuleName(), "gen")
 }
diff --git a/bootstrap/cleanup.go b/bootstrap/cleanup.go
index 8aa8318..ed3c630 100644
--- a/bootstrap/cleanup.go
+++ b/bootstrap/cleanup.go
@@ -38,7 +38,7 @@
 		return nil
 	}
 
-	ninjaBuildDir, err := ctx.NinjaBuildDir()
+	outDir, err := ctx.OutDir()
 	if err != nil {
 		return err
 	}
@@ -51,7 +51,7 @@
 	replacer := strings.NewReplacer(
 		"@@SrcDir@@", srcDir,
 		"@@BuildDir@@", buildDir)
-	ninjaBuildDir = replacer.Replace(ninjaBuildDir)
+	outDir = replacer.Replace(outDir)
 	targets := make(map[string]bool)
 	for target := range targetRules {
 		replacedTarget := replacer.Replace(target)
@@ -62,7 +62,7 @@
 		targets[filepath.Clean(replacedTarget)] = true
 	}
 
-	filePaths, err := parseNinjaLog(ninjaBuildDir, under)
+	filePaths, err := parseNinjaLog(outDir, under)
 	if err != nil {
 		return err
 	}
@@ -80,8 +80,8 @@
 	return nil
 }
 
-func parseNinjaLog(ninjaBuildDir string, under []string) ([]string, error) {
-	logFilePath := filepath.Join(ninjaBuildDir, logFileName)
+func parseNinjaLog(outDir string, under []string) ([]string, error) {
+	logFilePath := filepath.Join(outDir, logFileName)
 	logFile, err := os.Open(logFilePath)
 	if err != nil {
 		if os.IsNotExist(err) {
diff --git a/bootstrap/command.go b/bootstrap/command.go
index 1d1b6b7..f193580 100644
--- a/bootstrap/command.go
+++ b/bootstrap/command.go
@@ -121,14 +121,14 @@
 		fatalf("could not enumerate files: %v\n", err.Error())
 	}
 
-	buildDir := config.(BootstrapConfig).BuildDir()
+	soongOutDir := config.(BootstrapConfig).SoongOutDir()
 
 	stage := StageMain
 	if args.GeneratingPrimaryBuilder {
 		stage = StagePrimary
 	}
 
-	mainNinjaFile := filepath.Join("$buildDir", "build.ninja")
+	mainNinjaFile := filepath.Join("$soongOutDir", "build.ninja")
 
 	var invocations []PrimaryBuilderInvocation
 
@@ -235,8 +235,8 @@
 	}
 
 	if c, ok := config.(ConfigRemoveAbandonedFilesUnder); ok {
-		under, except := c.RemoveAbandonedFilesUnder(buildDir)
-		err := removeAbandonedFilesUnder(ctx, srcDir, buildDir, under, except)
+		under, except := c.RemoveAbandonedFilesUnder(soongOutDir)
+		err := removeAbandonedFilesUnder(ctx, srcDir, soongOutDir, under, except)
 		if err != nil {
 			fatalf("error removing abandoned files: %s", err)
 		}
diff --git a/bootstrap/config.go b/bootstrap/config.go
index b6e37e4..8f5fb11 100644
--- a/bootstrap/config.go
+++ b/bootstrap/config.go
@@ -41,11 +41,11 @@
 	srcDirVariable = bootstrapVariable("srcDir", func(c BootstrapConfig) string {
 		return "."
 	})
-	buildDirVariable = bootstrapVariable("buildDir", func(c BootstrapConfig) string {
-		return c.BuildDir()
+	soongOutDirVariable = bootstrapVariable("soongOutDir", func(c BootstrapConfig) string {
+		return c.SoongOutDir()
 	})
-	ninjaBuildDirVariable = bootstrapVariable("ninjaBuildDir", func(c BootstrapConfig) string {
-		return c.NinjaBuildDir()
+	outDirVariable = bootstrapVariable("outDir", func(c BootstrapConfig) string {
+		return c.OutDir()
 	})
 	goRootVariable = bootstrapVariable("goRoot", func(c BootstrapConfig) string {
 		goroot := runtime.GOROOT()
@@ -77,11 +77,11 @@
 
 type BootstrapConfig interface {
 	// The directory where files emitted during bootstrapping are located.
-	// Usually NinjaBuildDir() + "/soong".
-	BuildDir() string
+	// Usually OutDir() + "/soong".
+	SoongOutDir() string
 
 	// The output directory for the build.
-	NinjaBuildDir() string
+	OutDir() string
 
 	// Whether to compile Go code in such a way that it can be debugged
 	DebugCompilation() bool
diff --git a/context.go b/context.go
index 3234fd7..0685148 100644
--- a/context.go
+++ b/context.go
@@ -102,7 +102,7 @@
 	globalRules     map[Rule]*ruleDef
 
 	// set during PrepareBuildActions
-	ninjaBuildDir      ninjaString // The builddir special Ninja variable
+	outDir             ninjaString // The builddir special Ninja variable
 	requiredNinjaMajor int         // For the ninja_required_version variable
 	requiredNinjaMinor int         // For the ninja_required_version variable
 	requiredNinjaMicro int         // For the ninja_required_version variable
@@ -388,7 +388,7 @@
 		globs:              make(map[globKey]pathtools.GlobResult),
 		fs:                 pathtools.OsFs,
 		finishedMutators:   make(map[*mutatorInfo]bool),
-		ninjaBuildDir:      nil,
+		outDir:             nil,
 		requiredNinjaMajor: 1,
 		requiredNinjaMinor: 7,
 		requiredNinjaMicro: 0,
@@ -2392,8 +2392,8 @@
 		deps = append(deps, depsModules...)
 		deps = append(deps, depsSingletons...)
 
-		if c.ninjaBuildDir != nil {
-			err := c.liveGlobals.addNinjaStringDeps(c.ninjaBuildDir)
+		if c.outDir != nil {
+			err := c.liveGlobals.addNinjaStringDeps(c.outDir)
 			if err != nil {
 				errs = []error{err}
 				return
@@ -3205,9 +3205,9 @@
 	}
 }
 
-func (c *Context) setNinjaBuildDir(value ninjaString) {
-	if c.ninjaBuildDir == nil {
-		c.ninjaBuildDir = value
+func (c *Context) setOutDir(value ninjaString) {
+	if c.outDir == nil {
+		c.outDir = value
 	}
 }
 
@@ -3399,9 +3399,9 @@
 	return targets, nil
 }
 
-func (c *Context) NinjaBuildDir() (string, error) {
-	if c.ninjaBuildDir != nil {
-		return c.ninjaBuildDir.Eval(c.globalVariables)
+func (c *Context) OutDir() (string, error) {
+	if c.outDir != nil {
+		return c.outDir.Eval(c.globalVariables)
 	} else {
 		return "", nil
 	}
@@ -3751,8 +3751,8 @@
 }
 
 func (c *Context) writeBuildDir(nw *ninjaWriter) error {
-	if c.ninjaBuildDir != nil {
-		err := nw.Assign("builddir", c.ninjaBuildDir.Value(c.pkgNames))
+	if c.outDir != nil {
+		err := nw.Assign("builddir", c.outDir.Value(c.pkgNames))
 		if err != nil {
 			return err
 		}
diff --git a/singleton_ctx.go b/singleton_ctx.go
index a4e7153..455f6fc 100644
--- a/singleton_ctx.go
+++ b/singleton_ctx.go
@@ -82,10 +82,10 @@
 	// RequireNinjaVersion sets the generated ninja manifest to require at least the specified version of ninja.
 	RequireNinjaVersion(major, minor, micro int)
 
-	// SetNinjaBuildDir sets the value of the top-level "builddir" Ninja variable
+	// SetOutDir sets the value of the top-level "builddir" Ninja variable
 	// that controls where Ninja stores its build log files.  This value can be
 	// set at most one time for a single build, later calls are ignored.
-	SetNinjaBuildDir(pctx PackageContext, value string)
+	SetOutDir(pctx PackageContext, value string)
 
 	// AddSubninja adds a ninja file to include with subninja. This should likely
 	// only ever be used inside bootstrap to handle glob rules.
@@ -289,7 +289,7 @@
 	s.context.requireNinjaVersion(major, minor, micro)
 }
 
-func (s *singletonContext) SetNinjaBuildDir(pctx PackageContext, value string) {
+func (s *singletonContext) SetOutDir(pctx PackageContext, value string) {
 	s.scope.ReparentTo(pctx)
 
 	ninjaValue, err := parseNinjaString(s.scope, value)
@@ -297,7 +297,7 @@
 		panic(err)
 	}
 
-	s.context.setNinjaBuildDir(ninjaValue)
+	s.context.setOutDir(ninjaValue)
 }
 
 func (s *singletonContext) AddSubninja(file string) {