From 16fec72dfc0ea8ed90c50fedd78176575e09a5ee Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 17 Oct 2019 13:41:20 -0700 Subject: [PATCH] Move outputs of bootstrap modules in main stage to separate directory Don't write to $buildDir/.bootstrap in the ninja file generated for the main stage. Test: examine main stage build.ninja file Change-Id: I9c6183c9a434ff11d44cdd4f9844eae192ebfe03 --- bootstrap/bootstrap.go | 52 ++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index 1799e68..f6146b5 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -27,6 +27,7 @@ import ( "github.com/google/blueprint/pathtools" ) +const mainSubDir = ".primary" const bootstrapSubDir = ".bootstrap" const miniBootstrapSubDir = ".minibootstrap" @@ -143,15 +144,16 @@ var ( "depfile") _ = pctx.VariableFunc("BinDir", func(config interface{}) (string, error) { - return binDir(), nil + return bootstrapBinDir(), nil }) _ = pctx.VariableFunc("ToolDir", func(config interface{}) (string, error) { return toolDir(config), nil }) - docsDir = filepath.Join(bootstrapDir, "docs") + docsDir = filepath.Join(mainDir, "docs") + mainDir = filepath.Join("$buildDir", mainSubDir) bootstrapDir = filepath.Join("$buildDir", bootstrapSubDir) miniBootstrapDir = filepath.Join("$buildDir", miniBootstrapSubDir) @@ -165,7 +167,7 @@ type GoBinaryTool interface { isGoBinary() } -func binDir() string { +func bootstrapBinDir() string { return filepath.Join(BuildDir, bootstrapSubDir, "bin") } @@ -307,14 +309,14 @@ func (g *goPackage) GenerateBuildActions(ctx blueprint.ModuleContext) { return } - g.pkgRoot = packageRoot(ctx) + g.pkgRoot = packageRoot(ctx, g.config) g.archiveFile = filepath.Join(g.pkgRoot, filepath.FromSlash(g.properties.PkgPath)+".a") ctx.VisitDepsDepthFirstIf(isGoPluginFor(name), func(module blueprint.Module) { hasPlugins = true }) if hasPlugins { - pluginSrc = filepath.Join(moduleGenSrcDir(ctx), "plugin.go") + pluginSrc = filepath.Join(moduleGenSrcDir(ctx, g.config), "plugin.go") genSrcs = append(genSrcs, pluginSrc) } @@ -332,9 +334,9 @@ func (g *goPackage) GenerateBuildActions(ctx blueprint.ModuleContext) { } if g.config.runGoTests { - testArchiveFile := filepath.Join(testRoot(ctx), + testArchiveFile := filepath.Join(testRoot(ctx, g.config), filepath.FromSlash(g.properties.PkgPath)+".a") - g.testResultFile = buildGoTest(ctx, testRoot(ctx), testArchiveFile, + g.testResultFile = buildGoTest(ctx, testRoot(ctx, g.config), testArchiveFile, g.properties.PkgPath, srcs, genSrcs, testSrcs) } @@ -395,9 +397,9 @@ func (g *goBinary) InstallPath() string { func (g *goBinary) GenerateBuildActions(ctx blueprint.ModuleContext) { var ( name = ctx.ModuleName() - objDir = moduleObjDir(ctx) + objDir = moduleObjDir(ctx, g.config) archiveFile = filepath.Join(objDir, name+".a") - testArchiveFile = filepath.Join(testRoot(ctx), name+".a") + testArchiveFile = filepath.Join(testRoot(ctx, g.config), name+".a") aoutFile = filepath.Join(objDir, "a.out") hasPlugins = false pluginSrc = "" @@ -406,14 +408,16 @@ func (g *goBinary) GenerateBuildActions(ctx blueprint.ModuleContext) { if g.properties.Tool_dir { g.installPath = filepath.Join(toolDir(ctx.Config()), name) + } else if g.config.stage == StageMain { + g.installPath = filepath.Join(mainDir, "bin", name) } else { - g.installPath = filepath.Join(binDir(), name) + g.installPath = filepath.Join(bootstrapDir, "bin", name) } ctx.VisitDepsDepthFirstIf(isGoPluginFor(name), func(module blueprint.Module) { hasPlugins = true }) if hasPlugins { - pluginSrc = filepath.Join(moduleGenSrcDir(ctx), "plugin.go") + pluginSrc = filepath.Join(moduleGenSrcDir(ctx, g.config), "plugin.go") genSrcs = append(genSrcs, pluginSrc) } @@ -433,7 +437,7 @@ func (g *goBinary) GenerateBuildActions(ctx blueprint.ModuleContext) { } if g.config.runGoTests { - deps = buildGoTest(ctx, testRoot(ctx), testArchiveFile, + deps = buildGoTest(ctx, testRoot(ctx, g.config), testArchiveFile, name, srcs, genSrcs, testSrcs) } @@ -758,18 +762,26 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) { } } +func stageDir(config *Config) string { + if config.stage == StageMain { + return mainDir + } else { + return bootstrapDir + } +} + // packageRoot returns the module-specific package root directory path. This // 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 { - return filepath.Join(bootstrapDir, ctx.ModuleName(), "pkg") +func packageRoot(ctx blueprint.ModuleContext, config *Config) string { + return filepath.Join(stageDir(config), 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 { - return filepath.Join(bootstrapDir, ctx.ModuleName(), "test") +func testRoot(ctx blueprint.ModuleContext, config *Config) string { + return filepath.Join(stageDir(config), ctx.ModuleName(), "test") } // moduleSrcDir returns the path of the directory that all source file paths are @@ -779,11 +791,11 @@ func moduleSrcDir(ctx blueprint.ModuleContext) string { } // moduleObjDir returns the module-specific object directory path. -func moduleObjDir(ctx blueprint.ModuleContext) string { - return filepath.Join(bootstrapDir, ctx.ModuleName(), "obj") +func moduleObjDir(ctx blueprint.ModuleContext, config *Config) string { + return filepath.Join(stageDir(config), ctx.ModuleName(), "obj") } // moduleGenSrcDir returns the module-specific generated sources path. -func moduleGenSrcDir(ctx blueprint.ModuleContext) string { - return filepath.Join(bootstrapDir, ctx.ModuleName(), "gen") +func moduleGenSrcDir(ctx blueprint.ModuleContext, config *Config) string { + return filepath.Join(stageDir(config), ctx.ModuleName(), "gen") }