Convert sdk_library to use androidmk Dist

Reuse the generic Dist support instead of writing
custom mk rules for it. Use the new Tag support to
grab the classes.jar instead of the dexed jar.

Bug: 152618077
Test: m sdk dist
Change-Id: Id893d52cc24b66e6bd900b5062a59f3820000bcd
Merged-In: Id893d52cc24b66e6bd900b5062a59f3820000bcd
(cherry picked from commit 6bb8810c8e)
This commit is contained in:
Anton Hansson 2020-03-27 19:43:19 +00:00
parent 78156ef5dd
commit 5fd5d24a91
1 changed files with 36 additions and 36 deletions

View File

@ -18,7 +18,6 @@ import (
"android/soong/android" "android/soong/android"
"fmt" "fmt"
"io"
"path" "path"
"path/filepath" "path/filepath"
"sort" "sort"
@ -328,41 +327,6 @@ func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
entriesList := module.Library.AndroidMkEntries() entriesList := module.Library.AndroidMkEntries()
entries := &entriesList[0] entries := &entriesList[0]
entries.Required = append(entries.Required, module.xmlFileName()) entries.Required = append(entries.Required, module.xmlFileName())
entries.ExtraFooters = []android.AndroidMkExtraFootersFunc{
func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
if !Bool(module.sdkLibraryProperties.No_dist) {
// Create a phony module that installs the impl library, for the case when this lib is
// in PRODUCT_PACKAGES.
owner := module.ModuleBase.Owner()
if owner == "" {
if Bool(module.sdkLibraryProperties.Core_lib) {
owner = "core"
} else {
owner = "android"
}
}
// Create dist rules to install the stubs libs and api files to the dist dir
for _, apiScope := range module.getActiveApiScopes() {
if scopePaths, ok := module.scopePaths[apiScope]; ok {
if len(scopePaths.stubsHeaderPath) == 1 {
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
scopePaths.stubsImplPath.Strings()[0]+
":"+path.Join("apistubs", owner, apiScope.name,
module.BaseModuleName()+".jar")+")")
}
if scopePaths.apiFilePath != nil {
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
scopePaths.apiFilePath.String()+
":"+path.Join("apistubs", owner, apiScope.name, "api",
module.BaseModuleName()+".txt")+")")
}
}
}
}
},
}
return entriesList return entriesList
} }
@ -386,6 +350,17 @@ func (module *SdkLibrary) xmlFileName() string {
return module.BaseModuleName() + sdkXmlFileSuffix return module.BaseModuleName() + sdkXmlFileSuffix
} }
// The dist path of the stub artifacts
func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string {
if module.ModuleBase.Owner() != "" {
return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name)
} else if Bool(module.sdkLibraryProperties.Core_lib) {
return path.Join("apistubs", "core", apiScope.name)
} else {
return path.Join("apistubs", "android", apiScope.name)
}
}
// Get the sdk version for use when compiling the stubs library. // Get the sdk version for use when compiling the stubs library.
func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) string { func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) string {
sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
@ -438,6 +413,12 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc
Srcs []string Srcs []string
Javacflags []string Javacflags []string
} }
Dist struct {
Targets []string
Dest *string
Dir *string
Tag *string
}
}{} }{}
props.Name = proptools.StringPtr(module.stubsName(apiScope)) props.Name = proptools.StringPtr(module.stubsName(apiScope))
@ -466,6 +447,13 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc
} else if module.SystemExtSpecific() { } else if module.SystemExtSpecific() {
props.System_ext_specific = proptools.BoolPtr(true) props.System_ext_specific = proptools.BoolPtr(true)
} }
// Dist the class jar artifact for sdk builds.
if !Bool(module.sdkLibraryProperties.No_dist) {
props.Dist.Targets = []string{"sdk", "win_sdk"}
props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.BaseModuleName()))
props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope))
props.Dist.Tag = proptools.StringPtr(".jar")
}
mctx.CreateModule(LibraryFactory, &props) mctx.CreateModule(LibraryFactory, &props)
} }
@ -497,6 +485,11 @@ func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiSc
Include_dirs []string Include_dirs []string
Local_include_dirs []string Local_include_dirs []string
} }
Dist struct {
Targets []string
Dest *string
Dir *string
}
}{} }{}
sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
@ -578,6 +571,13 @@ func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiSc
module.latestRemovedApiFilegroupName(apiScope)) module.latestRemovedApiFilegroupName(apiScope))
props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true) props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
// Dist the api txt artifact for sdk builds.
if !Bool(module.sdkLibraryProperties.No_dist) {
props.Dist.Targets = []string{"sdk", "win_sdk"}
props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName()))
props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api"))
}
mctx.CreateModule(DroidstubsFactory, &props) mctx.CreateModule(DroidstubsFactory, &props)
} }