Merge "Export stub sources as part of the java_sdk_library" am: b661961825
Change-Id: Ic678a058f1ae7c32eb0183309f6762e8d9da0338
This commit is contained in:
commit
c61ca98d63
4 changed files with 61 additions and 9 deletions
|
@ -375,10 +375,17 @@ func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToC
|
||||||
apiToCheck.Removed_api_file = nil
|
apiToCheck.Removed_api_file = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used by xsd_config
|
||||||
type ApiFilePath interface {
|
type ApiFilePath interface {
|
||||||
ApiFilePath() android.Path
|
ApiFilePath() android.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Provider of information about API stubs, used by java_sdk_library.
|
||||||
|
type ApiStubsProvider interface {
|
||||||
|
ApiFilePath
|
||||||
|
StubsSrcJar() android.Path
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Javadoc
|
// Javadoc
|
||||||
//
|
//
|
||||||
|
@ -1264,6 +1271,10 @@ func (d *Droidstubs) ApiFilePath() android.Path {
|
||||||
return d.apiFilePath
|
return d.apiFilePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Droidstubs) StubsSrcJar() android.Path {
|
||||||
|
return d.stubsSrcJar
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
d.Javadoc.addDeps(ctx)
|
d.Javadoc.addDeps(ctx)
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,7 @@ type scopePaths struct {
|
||||||
stubsHeaderPath android.Paths
|
stubsHeaderPath android.Paths
|
||||||
stubsImplPath android.Paths
|
stubsImplPath android.Paths
|
||||||
apiFilePath android.Path
|
apiFilePath android.Path
|
||||||
|
stubsSrcJar android.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
// Common code between sdk library and sdk library import
|
// Common code between sdk library and sdk library import
|
||||||
|
@ -325,11 +326,12 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
|
||||||
scopePaths.stubsImplPath = lib.ImplementationJars()
|
scopePaths.stubsImplPath = lib.ImplementationJars()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if doc, ok := to.(ApiFilePath); ok {
|
if doc, ok := to.(ApiStubsProvider); ok {
|
||||||
if scopeTag, ok := tag.(scopeDependencyTag); ok {
|
if scopeTag, ok := tag.(scopeDependencyTag); ok {
|
||||||
apiScope := scopeTag.apiScope
|
apiScope := scopeTag.apiScope
|
||||||
scopePaths := module.getScopePaths(apiScope)
|
scopePaths := module.getScopePaths(apiScope)
|
||||||
scopePaths.apiFilePath = doc.ApiFilePath()
|
scopePaths.apiFilePath = doc.ApiFilePath()
|
||||||
|
scopePaths.stubsSrcJar = doc.StubsSrcJar()
|
||||||
} else {
|
} else {
|
||||||
ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
|
ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
|
||||||
}
|
}
|
||||||
|
@ -826,6 +828,9 @@ type sdkLibraryScopeProperties struct {
|
||||||
|
|
||||||
// List of shared java libs that this module has dependencies to
|
// List of shared java libs that this module has dependencies to
|
||||||
Libs []string
|
Libs []string
|
||||||
|
|
||||||
|
// The stub sources.
|
||||||
|
Stub_srcs []string `android:"path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type sdkLibraryImportProperties struct {
|
type sdkLibraryImportProperties struct {
|
||||||
|
@ -927,6 +932,8 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte
|
||||||
}
|
}
|
||||||
|
|
||||||
module.createJavaImportForStubs(mctx, apiScope, scopeProperties)
|
module.createJavaImportForStubs(mctx, apiScope, scopeProperties)
|
||||||
|
|
||||||
|
module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties)
|
||||||
}
|
}
|
||||||
|
|
||||||
javaSdkLibraries := javaSdkLibraries(mctx.Config())
|
javaSdkLibraries := javaSdkLibraries(mctx.Config())
|
||||||
|
@ -971,6 +978,16 @@ func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.LoadHookCo
|
||||||
mctx.CreateModule(ImportFactory, &props)
|
mctx.CreateModule(ImportFactory, &props)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.LoadHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
|
||||||
|
props := struct {
|
||||||
|
Name *string
|
||||||
|
Srcs []string
|
||||||
|
}{}
|
||||||
|
props.Name = proptools.StringPtr(apiScope.docsModuleName(module.BaseModuleName()))
|
||||||
|
props.Srcs = scopeProperties.Stub_srcs
|
||||||
|
mctx.CreateModule(PrebuiltStubsSourcesFactory, &props)
|
||||||
|
}
|
||||||
|
|
||||||
func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
for apiScope, scopeProperties := range module.scopeProperties {
|
for apiScope, scopeProperties := range module.scopeProperties {
|
||||||
if len(scopeProperties.Jars) == 0 {
|
if len(scopeProperties.Jars) == 0 {
|
||||||
|
@ -1169,11 +1186,15 @@ type sdkLibrarySdkMemberProperties struct {
|
||||||
|
|
||||||
// Additional libraries that the exported stubs libraries depend upon.
|
// Additional libraries that the exported stubs libraries depend upon.
|
||||||
Libs []string
|
Libs []string
|
||||||
|
|
||||||
|
// The Java stubs source files.
|
||||||
|
Stub_srcs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type scopeProperties struct {
|
type scopeProperties struct {
|
||||||
Jars android.Paths
|
Jars android.Paths
|
||||||
SdkVersion string
|
StubsSrcJar android.Path
|
||||||
|
SdkVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
|
||||||
|
@ -1187,6 +1208,7 @@ func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMembe
|
||||||
properties := scopeProperties{}
|
properties := scopeProperties{}
|
||||||
properties.Jars = jars
|
properties.Jars = jars
|
||||||
properties.SdkVersion = apiScope.sdkVersion
|
properties.SdkVersion = apiScope.sdkVersion
|
||||||
|
properties.StubsSrcJar = paths.stubsSrcJar
|
||||||
s.Scopes[apiScope] = properties
|
s.Scopes[apiScope] = properties
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1199,14 +1221,22 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo
|
||||||
if properties, ok := s.Scopes[apiScope]; ok {
|
if properties, ok := s.Scopes[apiScope]; ok {
|
||||||
scopeSet := propertySet.AddPropertySet(apiScope.name)
|
scopeSet := propertySet.AddPropertySet(apiScope.name)
|
||||||
|
|
||||||
|
scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name)
|
||||||
|
|
||||||
var jars []string
|
var jars []string
|
||||||
for _, p := range properties.Jars {
|
for _, p := range properties.Jars {
|
||||||
dest := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name, ctx.Name()+"-stubs.jar")
|
dest := filepath.Join(scopeDir, ctx.Name()+"-stubs.jar")
|
||||||
ctx.SnapshotBuilder().CopyToSnapshot(p, dest)
|
ctx.SnapshotBuilder().CopyToSnapshot(p, dest)
|
||||||
jars = append(jars, dest)
|
jars = append(jars, dest)
|
||||||
}
|
}
|
||||||
scopeSet.AddProperty("jars", jars)
|
scopeSet.AddProperty("jars", jars)
|
||||||
|
|
||||||
|
// Merge the stubs source jar into the snapshot zip so that when it is unpacked
|
||||||
|
// the source files are also unpacked.
|
||||||
|
snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources")
|
||||||
|
ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir)
|
||||||
|
scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir})
|
||||||
|
|
||||||
if properties.SdkVersion != "" {
|
if properties.SdkVersion != "" {
|
||||||
scopeSet.AddProperty("sdk_version", properties.SdkVersion)
|
scopeSet.AddProperty("sdk_version", properties.SdkVersion)
|
||||||
}
|
}
|
||||||
|
|
|
@ -624,7 +624,7 @@ module_exports_snapshot {
|
||||||
|
|
||||||
`),
|
`),
|
||||||
checkAllCopyRules(""),
|
checkAllCopyRules(""),
|
||||||
checkMergeZip(".intermediates/myexports/common_os/tmp/java/myjavaapistubs_stubs_sources.zip"),
|
checkMergeZips(".intermediates/myexports/common_os/tmp/java/myjavaapistubs_stubs_sources.zip"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,7 +678,7 @@ module_exports_snapshot {
|
||||||
}
|
}
|
||||||
`),
|
`),
|
||||||
checkAllCopyRules(""),
|
checkAllCopyRules(""),
|
||||||
checkMergeZip(".intermediates/myexports/common_os/tmp/java/myjavaapistubs_stubs_sources.zip"),
|
checkMergeZips(".intermediates/myexports/common_os/tmp/java/myjavaapistubs_stubs_sources.zip"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -997,14 +997,17 @@ java_sdk_library_import {
|
||||||
apex_available: ["//apex_available:anyapex"],
|
apex_available: ["//apex_available:anyapex"],
|
||||||
public: {
|
public: {
|
||||||
jars: ["sdk_library/public/myjavalib-stubs.jar"],
|
jars: ["sdk_library/public/myjavalib-stubs.jar"],
|
||||||
|
stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
|
||||||
sdk_version: "current",
|
sdk_version: "current",
|
||||||
},
|
},
|
||||||
system: {
|
system: {
|
||||||
jars: ["sdk_library/system/myjavalib-stubs.jar"],
|
jars: ["sdk_library/system/myjavalib-stubs.jar"],
|
||||||
|
stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
|
||||||
sdk_version: "system_current",
|
sdk_version: "system_current",
|
||||||
},
|
},
|
||||||
test: {
|
test: {
|
||||||
jars: ["sdk_library/test/myjavalib-stubs.jar"],
|
jars: ["sdk_library/test/myjavalib-stubs.jar"],
|
||||||
|
stub_srcs: ["sdk_library/test/myjavalib_stub_sources"],
|
||||||
sdk_version: "test_current",
|
sdk_version: "test_current",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1015,14 +1018,17 @@ java_sdk_library_import {
|
||||||
apex_available: ["//apex_available:anyapex"],
|
apex_available: ["//apex_available:anyapex"],
|
||||||
public: {
|
public: {
|
||||||
jars: ["sdk_library/public/myjavalib-stubs.jar"],
|
jars: ["sdk_library/public/myjavalib-stubs.jar"],
|
||||||
|
stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
|
||||||
sdk_version: "current",
|
sdk_version: "current",
|
||||||
},
|
},
|
||||||
system: {
|
system: {
|
||||||
jars: ["sdk_library/system/myjavalib-stubs.jar"],
|
jars: ["sdk_library/system/myjavalib-stubs.jar"],
|
||||||
|
stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
|
||||||
sdk_version: "system_current",
|
sdk_version: "system_current",
|
||||||
},
|
},
|
||||||
test: {
|
test: {
|
||||||
jars: ["sdk_library/test/myjavalib-stubs.jar"],
|
jars: ["sdk_library/test/myjavalib-stubs.jar"],
|
||||||
|
stub_srcs: ["sdk_library/test/myjavalib_stub_sources"],
|
||||||
sdk_version: "test_current",
|
sdk_version: "test_current",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1037,5 +1043,9 @@ sdk_snapshot {
|
||||||
.intermediates/myjavalib.stubs.system/android_common/javac/myjavalib.stubs.system.jar -> sdk_library/system/myjavalib-stubs.jar
|
.intermediates/myjavalib.stubs.system/android_common/javac/myjavalib.stubs.system.jar -> sdk_library/system/myjavalib-stubs.jar
|
||||||
.intermediates/myjavalib.stubs.test/android_common/javac/myjavalib.stubs.test.jar -> sdk_library/test/myjavalib-stubs.jar
|
.intermediates/myjavalib.stubs.test/android_common/javac/myjavalib.stubs.test.jar -> sdk_library/test/myjavalib-stubs.jar
|
||||||
`),
|
`),
|
||||||
|
checkMergeZips(
|
||||||
|
".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
|
||||||
|
".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip",
|
||||||
|
".intermediates/mysdk/common_os/tmp/sdk_library/test/myjavalib_stub_sources.zip"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,14 +339,15 @@ func checkAllOtherCopyRules(expected string) snapshotBuildInfoChecker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the specified path is in the list of zips to merge with the intermediate zip.
|
// Check that the specified paths match the list of zips to merge with the intermediate zip.
|
||||||
func checkMergeZip(expected string) snapshotBuildInfoChecker {
|
func checkMergeZips(expected ...string) snapshotBuildInfoChecker {
|
||||||
return func(info *snapshotBuildInfo) {
|
return func(info *snapshotBuildInfo) {
|
||||||
info.r.t.Helper()
|
info.r.t.Helper()
|
||||||
if info.intermediateZip == "" {
|
if info.intermediateZip == "" {
|
||||||
info.r.t.Errorf("No intermediate zip file was created")
|
info.r.t.Errorf("No intermediate zip file was created")
|
||||||
}
|
}
|
||||||
ensureListContains(info.r.t, info.mergeZips, expected)
|
|
||||||
|
info.r.AssertDeepEquals("mismatching merge zip files", expected, info.mergeZips)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue