Merge changes Ie274263a,I45993324
* changes: Adds droidstubs support to sdk module Simplify building an SDK snapshot from the command line
This commit is contained in:
@@ -37,6 +37,8 @@ func init() {
|
||||
|
||||
android.RegisterModuleType("droidstubs", DroidstubsFactory)
|
||||
android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
|
||||
|
||||
android.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -1163,6 +1165,7 @@ func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
//
|
||||
type Droidstubs struct {
|
||||
Javadoc
|
||||
android.SdkBase
|
||||
|
||||
properties DroidstubsProperties
|
||||
apiFile android.WritablePath
|
||||
@@ -1208,6 +1211,7 @@ func DroidstubsFactory() android.Module {
|
||||
&module.Javadoc.properties)
|
||||
|
||||
InitDroiddocModule(module, android.HostAndDeviceSupported)
|
||||
android.InitSdkAwareModule(module)
|
||||
return module
|
||||
}
|
||||
|
||||
@@ -1913,3 +1917,88 @@ func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
|
||||
func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
|
||||
rule.Command().Text("rm -rf").Text(srcJarDir.String())
|
||||
}
|
||||
|
||||
var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
|
||||
|
||||
type PrebuiltStubsSourcesProperties struct {
|
||||
Srcs []string `android:"path"`
|
||||
}
|
||||
|
||||
type PrebuiltStubsSources struct {
|
||||
android.ModuleBase
|
||||
android.DefaultableModuleBase
|
||||
prebuilt android.Prebuilt
|
||||
android.SdkBase
|
||||
|
||||
properties PrebuiltStubsSourcesProperties
|
||||
|
||||
srcs android.Paths
|
||||
stubsSrcJar android.ModuleOutPath
|
||||
}
|
||||
|
||||
func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
p.srcs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
|
||||
}
|
||||
|
||||
func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
|
||||
return &p.prebuilt
|
||||
}
|
||||
|
||||
func (p *PrebuiltStubsSources) Name() string {
|
||||
return p.prebuilt.Name(p.ModuleBase.Name())
|
||||
}
|
||||
|
||||
func (p *PrebuiltStubsSources) Srcs() android.Paths {
|
||||
return append(android.Paths{}, p.srcs...)
|
||||
}
|
||||
|
||||
// prebuilt_stubs_sources imports a set of java source files as if they were
|
||||
// generated by droidstubs.
|
||||
//
|
||||
// By default, a prebuilt_stubs_sources has a single variant that expects a
|
||||
// set of `.java` files generated by droidstubs.
|
||||
//
|
||||
// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
|
||||
// for host modules.
|
||||
//
|
||||
// Intended only for use by sdk snapshots.
|
||||
func PrebuiltStubsSourcesFactory() android.Module {
|
||||
module := &PrebuiltStubsSources{}
|
||||
|
||||
module.AddProperties(&module.properties)
|
||||
|
||||
android.InitPrebuiltModule(module, &module.properties.Srcs)
|
||||
android.InitSdkAwareModule(module)
|
||||
InitDroiddocModule(module, android.HostAndDeviceSupported)
|
||||
return module
|
||||
}
|
||||
|
||||
func (d *Droidstubs) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder) {
|
||||
stubsSrcJar := d.stubsSrcJar
|
||||
|
||||
snapshotRelativeDir := filepath.Join("java", d.Name()+"_stubs_sources")
|
||||
builder.UnzipToSnapshot(stubsSrcJar, snapshotRelativeDir)
|
||||
|
||||
name := d.Name()
|
||||
bp := builder.AndroidBpFile()
|
||||
bp.Printfln("prebuilt_stubs_sources {")
|
||||
bp.Indent()
|
||||
bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name))
|
||||
bp.Printfln("sdk_member_name: %q,", name)
|
||||
bp.Printfln("srcs: [%q],", snapshotRelativeDir)
|
||||
bp.Dedent()
|
||||
bp.Printfln("}")
|
||||
bp.Printfln("")
|
||||
|
||||
// This module is for the case when the source tree for the unversioned module
|
||||
// doesn't exist (i.e. building in an unbundled tree). "prefer:" is set to false
|
||||
// so that this module does not eclipse the unversioned module if it exists.
|
||||
bp.Printfln("prebuilt_stubs_sources {")
|
||||
bp.Indent()
|
||||
bp.Printfln("name: %q,", name)
|
||||
bp.Printfln("srcs: [%q],", snapshotRelativeDir)
|
||||
bp.Printfln("prefer: false,")
|
||||
bp.Dedent()
|
||||
bp.Printfln("}")
|
||||
bp.Printfln("")
|
||||
}
|
||||
|
@@ -89,6 +89,7 @@ func testContext(bp string, fs map[string][]byte) *android.TestContext {
|
||||
ctx.RegisterModuleType("droiddoc", android.ModuleFactoryAdaptor(DroiddocFactory))
|
||||
ctx.RegisterModuleType("droiddoc_host", android.ModuleFactoryAdaptor(DroiddocHostFactory))
|
||||
ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(ExportedDroiddocDirFactory))
|
||||
ctx.RegisterModuleType("prebuilt_stubs_sources", android.ModuleFactoryAdaptor(PrebuiltStubsSourcesFactory))
|
||||
ctx.RegisterModuleType("java_sdk_library", android.ModuleFactoryAdaptor(SdkLibraryFactory))
|
||||
ctx.RegisterModuleType("java_sdk_library_import", android.ModuleFactoryAdaptor(sdkLibraryImportFactory))
|
||||
ctx.RegisterModuleType("override_android_app", android.ModuleFactoryAdaptor(OverrideAndroidAppModuleFactory))
|
||||
@@ -207,6 +208,9 @@ func testContext(bp string, fs map[string][]byte) *android.TestContext {
|
||||
"cert/new_cert.pk8": nil,
|
||||
|
||||
"testdata/data": nil,
|
||||
|
||||
"stubs-sources/foo/Foo.java": nil,
|
||||
"stubs/sources/foo/Foo.java": nil,
|
||||
}
|
||||
|
||||
for k, v := range fs {
|
||||
@@ -415,7 +419,7 @@ func TestPrebuilts(t *testing.T) {
|
||||
ctx, _ := testJava(t, `
|
||||
java_library {
|
||||
name: "foo",
|
||||
srcs: ["a.java"],
|
||||
srcs: ["a.java", ":stubs-source"],
|
||||
libs: ["bar", "sdklib"],
|
||||
static_libs: ["baz"],
|
||||
}
|
||||
@@ -439,6 +443,11 @@ func TestPrebuilts(t *testing.T) {
|
||||
name: "sdklib",
|
||||
jars: ["b.jar"],
|
||||
}
|
||||
|
||||
prebuilt_stubs_sources {
|
||||
name: "stubs-source",
|
||||
srcs: ["stubs/sources/**/*.java"],
|
||||
}
|
||||
`)
|
||||
|
||||
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
||||
@@ -447,6 +456,19 @@ func TestPrebuilts(t *testing.T) {
|
||||
bazJar := ctx.ModuleForTests("baz", "android_common").Rule("combineJar").Output
|
||||
sdklibStubsJar := ctx.ModuleForTests("sdklib.stubs", "android_common").Rule("combineJar").Output
|
||||
|
||||
inputs := []string{}
|
||||
for _, p := range javac.BuildParams.Inputs {
|
||||
inputs = append(inputs, p.String())
|
||||
}
|
||||
|
||||
expected := []string{
|
||||
"a.java",
|
||||
"stubs/sources/foo/Foo.java",
|
||||
}
|
||||
if !reflect.DeepEqual(expected, inputs) {
|
||||
t.Errorf("foo inputs incorrect: expected %q, found %q", expected, inputs)
|
||||
}
|
||||
|
||||
if !strings.Contains(javac.Args["classpath"], barJar.String()) {
|
||||
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barJar.String())
|
||||
}
|
||||
|
Reference in New Issue
Block a user