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) sort.Strings(*javaSdkLibraries)
ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*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) { func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) {
@ -830,6 +838,8 @@ type sdkLibraryImport struct {
android.ModuleBase android.ModuleBase
android.DefaultableModuleBase android.DefaultableModuleBase
prebuilt android.Prebuilt prebuilt android.Prebuilt
android.ApexModuleBase
android.SdkBase
properties sdkLibraryImportProperties properties sdkLibraryImportProperties
@ -888,6 +898,8 @@ func sdkLibraryImportFactory() android.Module {
module.AddProperties(&module.properties, allScopeProperties) module.AddProperties(&module.properties, allScopeProperties)
android.InitPrebuiltModule(module, &[]string{""}) android.InitPrebuiltModule(module, &[]string{""})
android.InitApexModule(module)
android.InitSdkAwareModule(module)
InitJavaModule(module, android.HostAndDeviceSupported) InitJavaModule(module, android.HostAndDeviceSupported)
android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) }) android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
@ -914,6 +926,16 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte
continue continue
} }
module.createJavaImportForStubs(mctx, apiScope, scopeProperties)
}
javaSdkLibraries := javaSdkLibraries(mctx.Config())
javaSdkLibrariesLock.Lock()
defer javaSdkLibrariesLock.Unlock()
*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 // Creates a java import for the jar with ".stubs" suffix
props := struct { props := struct {
Name *string Name *string
@ -926,14 +948,12 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte
Jars []string Jars []string
Prefer *bool Prefer *bool
}{} }{}
props.Name = proptools.StringPtr(apiScope.stubsModuleName(module.BaseModuleName())) props.Name = proptools.StringPtr(apiScope.stubsModuleName(module.BaseModuleName()))
props.Sdk_version = scopeProperties.Sdk_version props.Sdk_version = scopeProperties.Sdk_version
// Prepend any of the libs from the legacy public properties to the libs for each of the // 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. // scopes to avoid having to duplicate them in each scope.
props.Libs = append(module.properties.Libs, scopeProperties.Libs...) props.Libs = append(module.properties.Libs, scopeProperties.Libs...)
props.Jars = scopeProperties.Jars props.Jars = scopeProperties.Jars
if module.SocSpecific() { if module.SocSpecific() {
props.Soc_specific = proptools.BoolPtr(true) props.Soc_specific = proptools.BoolPtr(true)
} else if module.DeviceSpecific() { } else if module.DeviceSpecific() {
@ -943,22 +963,14 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte
} else if module.SystemExtSpecific() { } else if module.SystemExtSpecific() {
props.System_ext_specific = proptools.BoolPtr(true) props.System_ext_specific = proptools.BoolPtr(true)
} }
// If the build should use prebuilt sdks then set prefer to true on the stubs library. // 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. // That will cause the prebuilt version of the stubs to override the source version.
if mctx.Config().UnbundledBuildUsePrebuiltSdks() { if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
props.Prefer = proptools.BoolPtr(true) props.Prefer = proptools.BoolPtr(true)
} }
mctx.CreateModule(ImportFactory, &props) mctx.CreateModule(ImportFactory, &props)
} }
javaSdkLibraries := javaSdkLibraries(mctx.Config())
javaSdkLibrariesLock.Lock()
defer javaSdkLibrariesLock.Unlock()
*javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
}
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 {
@ -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{ fs := map[string][]byte{
"Test.java": nil, "Test.java": nil,
"aidl/foo/bar/Test.aidl": 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) 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 // from java package
java.RegisterJavaBuildComponents(ctx) java.RegisterJavaBuildComponents(ctx)
java.RegisterAppBuildComponents(ctx) java.RegisterAppBuildComponents(ctx)
java.RegisterSdkLibraryBuildComponents(ctx)
java.RegisterStubsBuildComponents(ctx) java.RegisterStubsBuildComponents(ctx)
java.RegisterSystemModulesBuildComponents(ctx) java.RegisterSystemModulesBuildComponents(ctx)