Add droiddoc_template

We prefer not to use absolute paths in modules, but to reference modules
that have associated paths. This a few benefits:

* it's easier to move a module than to update all the references
* if the module doesn't exist, we treat it as a normal missing
dependency, not having to deal with the missing dependency in path.go
* implementing visibility(etc) in the future would be simpler if there
was a module attached to the reference, so we don't have to do various
path-based lookups to try and match things up.

So define a `droiddoc_template` module, which takes a path, and will run
the glob once in that module. All of the `droiddoc` modules can then
specify it through the `custom_template` property, which will pull the
necessary data.

Also fix that htmldirs should be references from the local path, the
htmldir2 argument never being specified, and complain if more than two
htmldirs are specified, or if the custom template isn't specified.

Test: m core-docs
Test: out/soong/build.ninja is nearly identical
      - line numbers in comments
      - adds directories to droiddoc template dependency lists, which
        is more correct, since we need to rerun on added or removed
	files too.
Change-Id: Iff630bddb3818b8eeed439de7e41fc7fbe7cdcb0
This commit is contained in:
Dan Willemsen
2018-02-26 14:33:31 -08:00
parent 3bb14200e2
commit cc09097359
2 changed files with 66 additions and 15 deletions

View File

@@ -18,7 +18,6 @@ import (
"android/soong/android" "android/soong/android"
"android/soong/java/config" "android/soong/java/config"
"fmt" "fmt"
"path/filepath"
"strings" "strings"
"github.com/google/blueprint" "github.com/google/blueprint"
@@ -52,6 +51,7 @@ var (
func init() { func init() {
android.RegisterModuleType("droiddoc", DroiddocFactory) android.RegisterModuleType("droiddoc", DroiddocFactory)
android.RegisterModuleType("droiddoc_host", DroiddocHostFactory) android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
android.RegisterModuleType("droiddoc_template", DroiddocTemplateFactory)
android.RegisterModuleType("javadoc", JavadocFactory) android.RegisterModuleType("javadoc", JavadocFactory)
android.RegisterModuleType("javadoc_host", JavadocHostFactory) android.RegisterModuleType("javadoc_host", JavadocHostFactory)
} }
@@ -82,7 +82,7 @@ type JavadocProperties struct {
type DroiddocProperties struct { type DroiddocProperties struct {
// directory relative to top of the source tree that contains doc templates files. // directory relative to top of the source tree that contains doc templates files.
Custom_template_dir *string `android:"arch_variant"` Custom_template *string `android:"arch_variant"`
// directories relative to top of the source tree which contains html/jd files. // directories relative to top of the source tree which contains html/jd files.
Html_dirs []string `android:"arch_variant"` Html_dirs []string `android:"arch_variant"`
@@ -233,7 +233,7 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
} }
default: default:
switch tag { switch tag {
case android.DefaultsDepTag, android.SourceDepTag: case android.DefaultsDepTag, android.SourceDepTag, droiddocTemplateTag:
// Nothing to do // Nothing to do
default: default:
ctx.ModuleErrorf("depends on non-java module %q", otherName) ctx.ModuleErrorf("depends on non-java module %q", otherName)
@@ -319,6 +319,13 @@ func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) { func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
d.Javadoc.addDeps(ctx) d.Javadoc.addDeps(ctx)
if String(d.properties.Custom_template) == "" {
// TODO: This is almost always droiddoc-templates-sdk
ctx.PropertyErrorf("custom_template", "must specify a template")
} else {
ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
}
// extra_arg_files may contains filegroup or genrule. // extra_arg_files may contains filegroup or genrule.
android.ExtractSourcesDeps(ctx, d.properties.Arg_files) android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
@@ -373,24 +380,32 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":") classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
} }
// templateDir (maybe missing) is relative to top of the source tree instead of current module. var templateDir string
templateDir := android.PathForSource(ctx, String(d.properties.Custom_template_dir)).String() ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
implicits = append(implicits, ctx.GlobFiles(filepath.Join(templateDir, "**/*"), nil)...) if t, ok := m.(*DroiddocTemplate); ok {
implicits = append(implicits, t.deps...)
templateDir = t.dir.String()
} else {
ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
}
})
var htmlDirArgs string var htmlDirArgs string
if len(d.properties.Html_dirs) > 0 { if len(d.properties.Html_dirs) > 0 {
// htmlDir is relative to top of the source tree instead of current module. htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
htmlDir := android.PathForSource(ctx, d.properties.Html_dirs[0]).String() implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
implicits = append(implicits, ctx.GlobFiles(filepath.Join(htmlDir, "**/*"), nil)...) htmlDirArgs = "-htmldir " + htmlDir.String()
htmlDirArgs = "-htmldir " + htmlDir
} }
var htmlDir2Args string var htmlDir2Args string
if len(d.properties.Html_dirs) > 1 { if len(d.properties.Html_dirs) > 1 {
// htmlDir2 is relative to top of the source tree instead of current module. htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
htmlDir2 := android.PathForSource(ctx, d.properties.Html_dirs[1]).String() implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
implicits = append(implicits, ctx.GlobFiles(filepath.Join(htmlDir2, "**/*"), nil)...) htmlDir2Args = "-htmldir2 " + htmlDir2.String()
htmlDirArgs = "-htmldir2 " + htmlDir2 }
if len(d.properties.Html_dirs) > 2 {
ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
} }
knownTags := ctx.ExpandSources(d.properties.Knowntags, nil) knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
@@ -451,3 +466,34 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}, },
}) })
} }
var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
type DroiddocTemplateProperties struct {
// path to the directory containing the droiddoc templates.
Path *string
}
type DroiddocTemplate struct {
android.ModuleBase
properties DroiddocTemplateProperties
deps android.Paths
dir android.Path
}
func DroiddocTemplateFactory() android.Module {
module := &DroiddocTemplate{}
module.AddProperties(&module.properties)
android.InitAndroidModule(module)
return module
}
func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {}
func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
path := android.PathForModuleSrc(ctx, String(d.properties.Path))
d.dir = path
d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
}

View File

@@ -81,6 +81,7 @@ func testContext(config android.Config, bp string,
ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(genrule.GenRuleFactory)) ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(genrule.GenRuleFactory))
ctx.RegisterModuleType("droiddoc", android.ModuleFactoryAdaptor(DroiddocFactory)) ctx.RegisterModuleType("droiddoc", android.ModuleFactoryAdaptor(DroiddocFactory))
ctx.RegisterModuleType("droiddoc_host", android.ModuleFactoryAdaptor(DroiddocHostFactory)) ctx.RegisterModuleType("droiddoc_host", android.ModuleFactoryAdaptor(DroiddocHostFactory))
ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(DroiddocTemplateFactory))
ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators) ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
@@ -865,6 +866,10 @@ func TestSharding(t *testing.T) {
func TestDroiddoc(t *testing.T) { func TestDroiddoc(t *testing.T) {
ctx := testJava(t, ` ctx := testJava(t, `
droiddoc_template {
name: "droiddoc-templates-sdk",
path: ".",
}
droiddoc { droiddoc {
name: "bar-doc", name: "bar-doc",
srcs: [ srcs: [
@@ -873,7 +878,7 @@ func TestDroiddoc(t *testing.T) {
exclude_srcs: [ exclude_srcs: [
"bar-doc/b.java" "bar-doc/b.java"
], ],
custom_template_dir: "external/doclava/templates-sdk", custom_template: "droiddoc-templates-sdk",
hdf: [ hdf: [
"android.whichdoc offline", "android.whichdoc offline",
], ],