Loading java/sdk_library.go +53 −23 Original line number Diff line number Diff line Loading @@ -15,17 +15,18 @@ package java import ( "android/soong/android" "fmt" "path" "path/filepath" "reflect" "sort" "strings" "sync" "github.com/google/blueprint" "github.com/google/blueprint/proptools" "android/soong/android" ) const ( Loading Loading @@ -66,6 +67,9 @@ type apiScope struct { // The name of the api scope, e.g. public, system, test name string // The name of the field in the dynamically created structure. fieldName string // The tag to use to depend on the stubs library module. stubsTag scopeDependencyTag Loading Loading @@ -93,7 +97,7 @@ type apiScope struct { // Initialize a scope, creating and adding appropriate dependency tags func initApiScope(scope *apiScope) *apiScope { //apiScope := &scope scope.fieldName = proptools.FieldNameForProperty(scope.name) scope.stubsTag = scopeDependencyTag{ name: scope.name + "-stubs", apiScope: scope, Loading Loading @@ -820,15 +824,6 @@ type sdkLibraryImportProperties struct { // List of shared java libs, common to all scopes, that this module has // dependencies to Libs []string // Properties associated with the public api scope. Public sdkLibraryScopeProperties // Properties associated with the system api scope. System sdkLibraryScopeProperties // Properties associated with the test api scope. Test sdkLibraryScopeProperties } type sdkLibraryImport struct { Loading @@ -838,16 +833,59 @@ type sdkLibraryImport struct { properties sdkLibraryImportProperties // Map from api scope to the scope specific property structure. scopeProperties map[*apiScope]*sdkLibraryScopeProperties commonToSdkLibraryAndImport } var _ SdkLibraryDependency = (*sdkLibraryImport)(nil) // The type of a structure that contains a field of type sdkLibraryScopeProperties // for each apiscope in allApiScopes, e.g. something like: // struct { // Public sdkLibraryScopeProperties // System sdkLibraryScopeProperties // ... // } var allScopeStructType = createAllScopePropertiesStructType() // Dynamically create a structure type for each apiscope in allApiScopes. func createAllScopePropertiesStructType() reflect.Type { var fields []reflect.StructField for _, apiScope := range allApiScopes { field := reflect.StructField{ Name: apiScope.fieldName, Type: reflect.TypeOf(sdkLibraryScopeProperties{}), } fields = append(fields, field) } return reflect.StructOf(fields) } // Create an instance of the scope specific structure type and return a map // from apiscope to a pointer to each scope specific field. func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) { allScopePropertiesPtr := reflect.New(allScopeStructType) allScopePropertiesStruct := allScopePropertiesPtr.Elem() scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties) for _, apiScope := range allApiScopes { field := allScopePropertiesStruct.FieldByName(apiScope.fieldName) scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties) } return allScopePropertiesPtr.Interface(), scopeProperties } // java_sdk_library_import imports a prebuilt java_sdk_library. func sdkLibraryImportFactory() android.Module { module := &sdkLibraryImport{} module.AddProperties(&module.properties) allScopeProperties, scopeToProperties := createPropertiesInstance() module.scopeProperties = scopeToProperties module.AddProperties(&module.properties, allScopeProperties) android.InitPrebuiltModule(module, &[]string{""}) InitJavaModule(module, android.HostAndDeviceSupported) Loading @@ -871,7 +909,7 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte module.prebuilt.ForcePrefer() } for apiScope, scopeProperties := range module.scopeProperties() { for apiScope, scopeProperties := range module.scopeProperties { if len(scopeProperties.Jars) == 0 { continue } Loading Loading @@ -921,16 +959,8 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) } func (module *sdkLibraryImport) scopeProperties() map[*apiScope]*sdkLibraryScopeProperties { p := make(map[*apiScope]*sdkLibraryScopeProperties) p[apiScopePublic] = &module.properties.Public p[apiScopeSystem] = &module.properties.System p[apiScopeTest] = &module.properties.Test return p } func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { for apiScope, scopeProperties := range module.scopeProperties() { for apiScope, scopeProperties := range module.scopeProperties { if len(scopeProperties.Jars) == 0 { continue } Loading Loading
java/sdk_library.go +53 −23 Original line number Diff line number Diff line Loading @@ -15,17 +15,18 @@ package java import ( "android/soong/android" "fmt" "path" "path/filepath" "reflect" "sort" "strings" "sync" "github.com/google/blueprint" "github.com/google/blueprint/proptools" "android/soong/android" ) const ( Loading Loading @@ -66,6 +67,9 @@ type apiScope struct { // The name of the api scope, e.g. public, system, test name string // The name of the field in the dynamically created structure. fieldName string // The tag to use to depend on the stubs library module. stubsTag scopeDependencyTag Loading Loading @@ -93,7 +97,7 @@ type apiScope struct { // Initialize a scope, creating and adding appropriate dependency tags func initApiScope(scope *apiScope) *apiScope { //apiScope := &scope scope.fieldName = proptools.FieldNameForProperty(scope.name) scope.stubsTag = scopeDependencyTag{ name: scope.name + "-stubs", apiScope: scope, Loading Loading @@ -820,15 +824,6 @@ type sdkLibraryImportProperties struct { // List of shared java libs, common to all scopes, that this module has // dependencies to Libs []string // Properties associated with the public api scope. Public sdkLibraryScopeProperties // Properties associated with the system api scope. System sdkLibraryScopeProperties // Properties associated with the test api scope. Test sdkLibraryScopeProperties } type sdkLibraryImport struct { Loading @@ -838,16 +833,59 @@ type sdkLibraryImport struct { properties sdkLibraryImportProperties // Map from api scope to the scope specific property structure. scopeProperties map[*apiScope]*sdkLibraryScopeProperties commonToSdkLibraryAndImport } var _ SdkLibraryDependency = (*sdkLibraryImport)(nil) // The type of a structure that contains a field of type sdkLibraryScopeProperties // for each apiscope in allApiScopes, e.g. something like: // struct { // Public sdkLibraryScopeProperties // System sdkLibraryScopeProperties // ... // } var allScopeStructType = createAllScopePropertiesStructType() // Dynamically create a structure type for each apiscope in allApiScopes. func createAllScopePropertiesStructType() reflect.Type { var fields []reflect.StructField for _, apiScope := range allApiScopes { field := reflect.StructField{ Name: apiScope.fieldName, Type: reflect.TypeOf(sdkLibraryScopeProperties{}), } fields = append(fields, field) } return reflect.StructOf(fields) } // Create an instance of the scope specific structure type and return a map // from apiscope to a pointer to each scope specific field. func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) { allScopePropertiesPtr := reflect.New(allScopeStructType) allScopePropertiesStruct := allScopePropertiesPtr.Elem() scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties) for _, apiScope := range allApiScopes { field := allScopePropertiesStruct.FieldByName(apiScope.fieldName) scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties) } return allScopePropertiesPtr.Interface(), scopeProperties } // java_sdk_library_import imports a prebuilt java_sdk_library. func sdkLibraryImportFactory() android.Module { module := &sdkLibraryImport{} module.AddProperties(&module.properties) allScopeProperties, scopeToProperties := createPropertiesInstance() module.scopeProperties = scopeToProperties module.AddProperties(&module.properties, allScopeProperties) android.InitPrebuiltModule(module, &[]string{""}) InitJavaModule(module, android.HostAndDeviceSupported) Loading @@ -871,7 +909,7 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte module.prebuilt.ForcePrefer() } for apiScope, scopeProperties := range module.scopeProperties() { for apiScope, scopeProperties := range module.scopeProperties { if len(scopeProperties.Jars) == 0 { continue } Loading Loading @@ -921,16 +959,8 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) } func (module *sdkLibraryImport) scopeProperties() map[*apiScope]*sdkLibraryScopeProperties { p := make(map[*apiScope]*sdkLibraryScopeProperties) p[apiScopePublic] = &module.properties.Public p[apiScopeSystem] = &module.properties.System p[apiScopeTest] = &module.properties.Test return p } func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { for apiScope, scopeProperties := range module.scopeProperties() { for apiScope, scopeProperties := range module.scopeProperties { if len(scopeProperties.Jars) == 0 { continue } Loading