diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index bf12cd3..ead22d0 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -155,7 +155,7 @@ type GoBinaryTool interface { } func pluginDeps(ctx blueprint.BottomUpMutatorContext) { - if pkg, ok := ctx.Module().(*goPackage); ok { + if pkg, ok := ctx.Module().(*GoPackage); ok { if ctx.PrimaryModule() == ctx.Module() { for _, plugin := range pkg.properties.PluginFor { ctx.AddReverseDependency(ctx.Module(), nil, plugin) @@ -190,18 +190,18 @@ func isGoPluginFor(name string) func(blueprint.Module) bool { } func IsBootstrapModule(module blueprint.Module) bool { - _, isPackage := module.(*goPackage) - _, isBinary := module.(*goBinary) + _, isPackage := module.(*GoPackage) + _, isBinary := module.(*GoBinary) return isPackage || isBinary } func isBootstrapBinaryModule(module blueprint.Module) bool { - _, isBinary := module.(*goBinary) + _, isBinary := module.(*GoBinary) return isBinary } -// A goPackage is a module for building Go packages. -type goPackage struct { +// A GoPackage is a module for building Go packages. +type GoPackage struct { blueprint.SimpleName properties struct { Deps []string @@ -231,39 +231,39 @@ type goPackage struct { testResultFile []string } -var _ goPackageProducer = (*goPackage)(nil) +var _ goPackageProducer = (*GoPackage)(nil) func newGoPackageModuleFactory() func() (blueprint.Module, []interface{}) { return func() (blueprint.Module, []interface{}) { - module := &goPackage{} + module := &GoPackage{} return module, []interface{}{&module.properties, &module.SimpleName.Properties} } } -func (g *goPackage) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string { +func (g *GoPackage) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string { if ctx.Module() != ctx.PrimaryModule() { return nil } return g.properties.Deps } -func (g *goPackage) GoPkgPath() string { +func (g *GoPackage) GoPkgPath() string { return g.properties.PkgPath } -func (g *goPackage) GoPkgRoot() string { +func (g *GoPackage) GoPkgRoot() string { return g.pkgRoot } -func (g *goPackage) GoPackageTarget() string { +func (g *GoPackage) GoPackageTarget() string { return g.archiveFile } -func (g *goPackage) GoTestTargets() []string { +func (g *GoPackage) GoTestTargets() []string { return g.testResultFile } -func (g *goPackage) IsPluginFor(name string) bool { +func (g *GoPackage) IsPluginFor(name string) bool { for _, plugin := range g.properties.PluginFor { if plugin == name { return true @@ -272,11 +272,11 @@ func (g *goPackage) IsPluginFor(name string) bool { return false } -func (g *goPackage) GenerateBuildActions(ctx blueprint.ModuleContext) { +func (g *GoPackage) GenerateBuildActions(ctx blueprint.ModuleContext) { // Allow the primary builder to create multiple variants. Any variants after the first // will copy outputs from the first. if ctx.Module() != ctx.PrimaryModule() { - primary := ctx.PrimaryModule().(*goPackage) + primary := ctx.PrimaryModule().(*GoPackage) g.pkgRoot = primary.pkgRoot g.archiveFile = primary.archiveFile g.testResultFile = primary.testResultFile @@ -340,8 +340,36 @@ func (g *goPackage) GenerateBuildActions(ctx blueprint.ModuleContext) { srcs, genSrcs) } -// A goBinary is a module for building executable binaries from Go sources. -type goBinary struct { +func (g *GoPackage) Srcs() []string { + return g.properties.Srcs +} + +func (g *GoPackage) LinuxSrcs() []string { + return g.properties.Linux.Srcs +} + +func (g *GoPackage) DarwinSrcs() []string { + return g.properties.Darwin.Srcs +} + +func (g *GoPackage) TestSrcs() []string { + return g.properties.TestSrcs +} + +func (g *GoPackage) LinuxTestSrcs() []string { + return g.properties.Linux.TestSrcs +} + +func (g *GoPackage) DarwinTestSrcs() []string { + return g.properties.Darwin.TestSrcs +} + +func (g *GoPackage) Deps() []string { + return g.properties.Deps +} + +// A GoBinary is a module for building executable binaries from Go sources. +type GoBinary struct { blueprint.SimpleName properties struct { Deps []string @@ -363,32 +391,60 @@ type goBinary struct { installPath string } -var _ GoBinaryTool = (*goBinary)(nil) +var _ GoBinaryTool = (*GoBinary)(nil) func newGoBinaryModuleFactory() func() (blueprint.Module, []interface{}) { return func() (blueprint.Module, []interface{}) { - module := &goBinary{} + module := &GoBinary{} return module, []interface{}{&module.properties, &module.SimpleName.Properties} } } -func (g *goBinary) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string { +func (g *GoBinary) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string { if ctx.Module() != ctx.PrimaryModule() { return nil } return g.properties.Deps } -func (g *goBinary) isGoBinary() {} -func (g *goBinary) InstallPath() string { +func (g *GoBinary) isGoBinary() {} +func (g *GoBinary) InstallPath() string { return g.installPath } -func (g *goBinary) GenerateBuildActions(ctx blueprint.ModuleContext) { +func (g *GoBinary) Srcs() []string { + return g.properties.Srcs +} + +func (g *GoBinary) LinuxSrcs() []string { + return g.properties.Linux.Srcs +} + +func (g *GoBinary) DarwinSrcs() []string { + return g.properties.Darwin.Srcs +} + +func (g *GoBinary) TestSrcs() []string { + return g.properties.TestSrcs +} + +func (g *GoBinary) LinuxTestSrcs() []string { + return g.properties.Linux.TestSrcs +} + +func (g *GoBinary) DarwinTestSrcs() []string { + return g.properties.Darwin.TestSrcs +} + +func (g *GoBinary) Deps() []string { + return g.properties.Deps +} + +func (g *GoBinary) GenerateBuildActions(ctx blueprint.ModuleContext) { // Allow the primary builder to create multiple variants. Any variants after the first // will copy outputs from the first. if ctx.Module() != ctx.PrimaryModule() { - primary := ctx.PrimaryModule().(*goBinary) + primary := ctx.PrimaryModule().(*GoBinary) g.installPath = primary.installPath return } @@ -619,7 +675,7 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) { // Find the module that's marked as the "primary builder", which means it's // creating the binary that we'll use to generate the non-bootstrap // build.ninja file. - var primaryBuilders []*goBinary + var primaryBuilders []*GoBinary // blueprintTools contains blueprint go binaries that will be built in StageMain var blueprintTools []string // blueprintGoPackages contains all blueprint go packages that can be built in StageMain @@ -627,14 +683,14 @@ func (s *singleton) GenerateBuildActions(ctx blueprint.SingletonContext) { ctx.VisitAllModulesIf(IsBootstrapModule, func(module blueprint.Module) { if ctx.PrimaryModule(module) == module { - if binaryModule, ok := module.(*goBinary); ok { + if binaryModule, ok := module.(*GoBinary); ok { blueprintTools = append(blueprintTools, binaryModule.InstallPath()) if binaryModule.properties.PrimaryBuilder { primaryBuilders = append(primaryBuilders, binaryModule) } } - if packageModule, ok := module.(*goPackage); ok { + if packageModule, ok := module.(*GoPackage); ok { blueprintGoPackages = append(blueprintGoPackages, packageModule.GoPackageTarget()) blueprintGoPackages = append(blueprintGoPackages, diff --git a/bootstrap/writedocs.go b/bootstrap/writedocs.go index f7314f7..d172f70 100644 --- a/bootstrap/writedocs.go +++ b/bootstrap/writedocs.go @@ -16,16 +16,16 @@ func ModuleTypeDocs(ctx *blueprint.Context, factories map[string]reflect.Value) // Find the module that's marked as the "primary builder", which means it's // creating the binary that we'll use to generate the non-bootstrap // build.ninja file. - var primaryBuilders []*goBinary + var primaryBuilders []*GoBinary ctx.VisitAllModulesIf(isBootstrapBinaryModule, func(module blueprint.Module) { - binaryModule := module.(*goBinary) + binaryModule := module.(*GoBinary) if binaryModule.properties.PrimaryBuilder { primaryBuilders = append(primaryBuilders, binaryModule) } }) - var primaryBuilder *goBinary + var primaryBuilder *GoBinary switch len(primaryBuilders) { case 0: return nil, fmt.Errorf("no primary builder module present") @@ -40,7 +40,7 @@ func ModuleTypeDocs(ctx *blueprint.Context, factories map[string]reflect.Value) pkgFiles := make(map[string][]string) ctx.VisitDepsDepthFirst(primaryBuilder, func(module blueprint.Module) { switch m := module.(type) { - case (*goPackage): + case (*GoPackage): pkgFiles[m.properties.PkgPath] = pathtools.PrefixPaths(m.properties.Srcs, filepath.Join(ctx.SrcDir(), ctx.ModuleDir(m))) default: