Merge changes If74eea67,I9d8089b2 am: 522bca3b26

Change-Id: I1800ea6f7bdbc5847917ca78e71f5fec4b504398
This commit is contained in:
Treehugger Robot 2020-04-09 17:04:56 +00:00 committed by Automerger Merge Worker
commit ec1c252f7b
3 changed files with 240 additions and 37 deletions

View file

@ -171,6 +171,14 @@ func init() {
sort.Strings(*javaSdkLibraries)
ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
})
// Register sdk member types.
android.RegisterSdkMemberType(&sdkLibrarySdkMemberType{
android.SdkMemberTypeBase{
PropertyName: "java_sdk_libs",
SupportsSdk: true,
},
})
}
func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) {
@ -830,6 +838,8 @@ type sdkLibraryImport struct {
android.ModuleBase
android.DefaultableModuleBase
prebuilt android.Prebuilt
android.ApexModuleBase
android.SdkBase
properties sdkLibraryImportProperties
@ -888,6 +898,8 @@ func sdkLibraryImportFactory() android.Module {
module.AddProperties(&module.properties, allScopeProperties)
android.InitPrebuiltModule(module, &[]string{""})
android.InitApexModule(module)
android.InitSdkAwareModule(module)
InitJavaModule(module, android.HostAndDeviceSupported)
android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
@ -914,43 +926,7 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte
continue
}
// Creates a java import for the jar with ".stubs" suffix
props := struct {
Name *string
Soc_specific *bool
Device_specific *bool
Product_specific *bool
System_ext_specific *bool
Sdk_version *string
Libs []string
Jars []string
Prefer *bool
}{}
props.Name = proptools.StringPtr(apiScope.stubsModuleName(module.BaseModuleName()))
props.Sdk_version = scopeProperties.Sdk_version
// Prepend any of the libs from the legacy public properties to the libs for each of the
// scopes to avoid having to duplicate them in each scope.
props.Libs = append(module.properties.Libs, scopeProperties.Libs...)
props.Jars = scopeProperties.Jars
if module.SocSpecific() {
props.Soc_specific = proptools.BoolPtr(true)
} else if module.DeviceSpecific() {
props.Device_specific = proptools.BoolPtr(true)
} else if module.ProductSpecific() {
props.Product_specific = proptools.BoolPtr(true)
} else if module.SystemExtSpecific() {
props.System_ext_specific = proptools.BoolPtr(true)
}
// If the build should use prebuilt sdks then set prefer to true on the stubs library.
// That will cause the prebuilt version of the stubs to override the source version.
if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
props.Prefer = proptools.BoolPtr(true)
}
mctx.CreateModule(ImportFactory, &props)
module.createJavaImportForStubs(mctx, apiScope, scopeProperties)
}
javaSdkLibraries := javaSdkLibraries(mctx.Config())
@ -959,6 +935,42 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte
*javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
}
func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.LoadHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) {
// Creates a java import for the jar with ".stubs" suffix
props := struct {
Name *string
Soc_specific *bool
Device_specific *bool
Product_specific *bool
System_ext_specific *bool
Sdk_version *string
Libs []string
Jars []string
Prefer *bool
}{}
props.Name = proptools.StringPtr(apiScope.stubsModuleName(module.BaseModuleName()))
props.Sdk_version = scopeProperties.Sdk_version
// Prepend any of the libs from the legacy public properties to the libs for each of the
// scopes to avoid having to duplicate them in each scope.
props.Libs = append(module.properties.Libs, scopeProperties.Libs...)
props.Jars = scopeProperties.Jars
if module.SocSpecific() {
props.Soc_specific = proptools.BoolPtr(true)
} else if module.DeviceSpecific() {
props.Device_specific = proptools.BoolPtr(true)
} else if module.ProductSpecific() {
props.Product_specific = proptools.BoolPtr(true)
} else if module.SystemExtSpecific() {
props.System_ext_specific = proptools.BoolPtr(true)
}
// If the build should use prebuilt sdks then set prefer to true on the stubs library.
// That will cause the prebuilt version of the stubs to override the source version.
if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
props.Prefer = proptools.BoolPtr(true)
}
mctx.CreateModule(ImportFactory, &props)
}
func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
for apiScope, scopeProperties := range module.scopeProperties {
if len(scopeProperties.Jars) == 0 {
@ -1127,3 +1139,81 @@ func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries {
},
}}
}
type sdkLibrarySdkMemberType struct {
android.SdkMemberTypeBase
}
func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
mctx.AddVariationDependencies(nil, dependencyTag, names...)
}
func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool {
_, ok := module.(*SdkLibrary)
return ok
}
func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import")
}
func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
return &sdkLibrarySdkMemberProperties{}
}
type sdkLibrarySdkMemberProperties struct {
android.SdkMemberPropertiesBase
// Scope to per scope properties.
Scopes map[*apiScope]scopeProperties
// Additional libraries that the exported stubs libraries depend upon.
Libs []string
}
type scopeProperties struct {
Jars android.Paths
SdkVersion string
}
func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
sdk := variant.(*SdkLibrary)
s.Scopes = make(map[*apiScope]scopeProperties)
for _, apiScope := range allApiScopes {
paths := sdk.getScopePaths(apiScope)
jars := paths.stubsImplPath
if len(jars) > 0 {
properties := scopeProperties{}
properties.Jars = jars
properties.SdkVersion = apiScope.sdkVersion
s.Scopes[apiScope] = properties
}
}
s.Libs = sdk.properties.Libs
}
func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
for _, apiScope := range allApiScopes {
if properties, ok := s.Scopes[apiScope]; ok {
scopeSet := propertySet.AddPropertySet(apiScope.name)
var jars []string
for _, p := range properties.Jars {
dest := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name, ctx.Name()+"-stubs.jar")
ctx.SnapshotBuilder().CopyToSnapshot(p, dest)
jars = append(jars, dest)
}
scopeSet.AddProperty("jars", jars)
if properties.SdkVersion != "" {
scopeSet.AddProperty("sdk_version", properties.SdkVersion)
}
}
}
if len(s.Libs) > 0 {
propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false))
}
}

View file

@ -24,7 +24,51 @@ func testSdkWithJava(t *testing.T, bp string) *testSdkResult {
fs := map[string][]byte{
"Test.java": nil,
"aidl/foo/bar/Test.aidl": nil,
// For java_sdk_library
"api/current.txt": nil,
"api/removed.txt": nil,
"api/system-current.txt": nil,
"api/system-removed.txt": nil,
"api/test-current.txt": nil,
"api/test-removed.txt": nil,
"build/soong/scripts/gen-java-current-api-files.sh": nil,
}
// for java_sdk_library tests
bp = `
java_system_modules_import {
name: "core-current-stubs-system-modules",
}
java_system_modules_import {
name: "core-platform-api-stubs-system-modules",
}
java_import {
name: "core.platform.api.stubs",
}
java_sdk_library_import {
name: "android_stubs_current",
}
java_sdk_library_import {
name: "android_system_stubs_current",
}
java_sdk_library_import {
name: "android_test_stubs_current",
}
java_import {
name: "core-lambda-stubs",
sdk_version: "none",
}
java_import {
name: "ext",
sdk_version: "none",
}
java_import {
name: "framework",
sdk_version: "none",
}
` + bp
return testSdkWithFs(t, bp, fs)
}
@ -927,3 +971,71 @@ module_exports_snapshot {
`),
)
}
func TestSnapshotWithJavaSdkLibrary(t *testing.T) {
result := testSdkWithJava(t, `
sdk {
name: "mysdk",
java_sdk_libs: ["myjavalib"],
}
java_sdk_library {
name: "myjavalib",
apex_available: ["//apex_available:anyapex"],
srcs: ["Test.java"],
sdk_version: "current",
}
`)
result.CheckSnapshot("mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
name: "mysdk_myjavalib@current",
sdk_member_name: "myjavalib",
apex_available: ["//apex_available:anyapex"],
public: {
jars: ["sdk_library/public/myjavalib-stubs.jar"],
sdk_version: "current",
},
system: {
jars: ["sdk_library/system/myjavalib-stubs.jar"],
sdk_version: "system_current",
},
test: {
jars: ["sdk_library/test/myjavalib-stubs.jar"],
sdk_version: "test_current",
},
}
java_sdk_library_import {
name: "myjavalib",
prefer: false,
apex_available: ["//apex_available:anyapex"],
public: {
jars: ["sdk_library/public/myjavalib-stubs.jar"],
sdk_version: "current",
},
system: {
jars: ["sdk_library/system/myjavalib-stubs.jar"],
sdk_version: "system_current",
},
test: {
jars: ["sdk_library/test/myjavalib-stubs.jar"],
sdk_version: "test_current",
},
}
sdk_snapshot {
name: "mysdk@current",
java_sdk_libs: ["mysdk_myjavalib@current"],
}
`),
checkAllCopyRules(`
.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/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
`),
)
}

View file

@ -90,6 +90,7 @@ func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, andr
// from java package
java.RegisterJavaBuildComponents(ctx)
java.RegisterAppBuildComponents(ctx)
java.RegisterSdkLibraryBuildComponents(ctx)
java.RegisterStubsBuildComponents(ctx)
java.RegisterSystemModulesBuildComponents(ctx)