Make aconfig flags generate a library instead of a srcjar.
Also add unit tests for the rest of device_config Bug: 283475679 Test: m nothing (soong unit tests) Change-Id: Iee18a1f2f2cbb23e8c8d84c54e903b32be29a693
This commit is contained in:
@@ -48,6 +48,7 @@ bootstrap_go_package {
|
||||
"droidstubs.go",
|
||||
"fuzz.go",
|
||||
"gen.go",
|
||||
"generated_java_library.go",
|
||||
"genrule.go",
|
||||
"hiddenapi.go",
|
||||
"hiddenapi_modular.go",
|
||||
@@ -92,6 +93,7 @@ bootstrap_go_package {
|
||||
"droidstubs_test.go",
|
||||
"fuzz_test.go",
|
||||
"genrule_test.go",
|
||||
"generated_java_library_test.go",
|
||||
"hiddenapi_singleton_test.go",
|
||||
"jacoco_test.go",
|
||||
"java_test.go",
|
||||
|
11
java/base.go
11
java/base.go
@@ -187,6 +187,9 @@ type CommonProperties struct {
|
||||
|
||||
// A list of java_library instances that provide additional hiddenapi annotations for the library.
|
||||
Hiddenapi_additional_annotations []string
|
||||
|
||||
// Additional srcJars tacked in by GeneratedJavaLibraryModule
|
||||
Generated_srcjars []android.Path `android:"mutated"`
|
||||
}
|
||||
|
||||
// Properties that are specific to device modules. Host module factories should not add these when
|
||||
@@ -1041,6 +1044,10 @@ func (j *Module) AddJSONData(d *map[string]interface{}) {
|
||||
|
||||
}
|
||||
|
||||
func (module *Module) addGeneratedSrcJars(path android.Path) {
|
||||
module.properties.Generated_srcjars = append(module.properties.Generated_srcjars, path)
|
||||
}
|
||||
|
||||
func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
||||
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
|
||||
|
||||
@@ -1082,6 +1089,10 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
||||
if aaptSrcJar != nil {
|
||||
srcJars = append(srcJars, aaptSrcJar)
|
||||
}
|
||||
srcJars = append(srcJars, j.properties.Generated_srcjars...)
|
||||
if len(j.properties.Generated_srcjars) > 0 {
|
||||
fmt.Printf("Java module %s Generated_srcjars: %v\n", ctx.ModuleName(), j.properties.Generated_srcjars)
|
||||
}
|
||||
srcFiles = srcFiles.FilterOutByExt(".srcjar")
|
||||
|
||||
if j.properties.Jarjar_rules != nil {
|
||||
|
@@ -305,6 +305,12 @@ type javaBuilderFlags struct {
|
||||
proto android.ProtoFlags
|
||||
}
|
||||
|
||||
func DefaultJavaBuilderFlags() javaBuilderFlags {
|
||||
return javaBuilderFlags{
|
||||
javaVersion: JAVA_VERSION_8,
|
||||
}
|
||||
}
|
||||
|
||||
func TransformJavaToClasses(ctx android.ModuleContext, outputFile android.WritablePath, shardIdx int,
|
||||
srcFiles, srcJars android.Paths, flags javaBuilderFlags, deps android.Paths) {
|
||||
|
||||
|
94
java/generated_java_library.go
Normal file
94
java/generated_java_library.go
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package java
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
type GeneratedJavaLibraryModule struct {
|
||||
Library
|
||||
callbacks GeneratedJavaLibraryCallbacks
|
||||
moduleName string
|
||||
}
|
||||
|
||||
type GeneratedJavaLibraryCallbacks interface {
|
||||
// Called from inside DepsMutator, gives a chance to AddDependencies
|
||||
DepsMutator(module *GeneratedJavaLibraryModule, ctx android.BottomUpMutatorContext)
|
||||
|
||||
// Called from inside GenerateAndroidBuildActions. Add the build rules to
|
||||
// make the srcjar, and return the path to it.
|
||||
GenerateSourceJarBuildActions(ctx android.ModuleContext) android.Path
|
||||
}
|
||||
|
||||
// GeneratedJavaLibraryModuleFactory provides a utility for modules that are generated
|
||||
// source code, including ones outside the java package to build jar files
|
||||
// from that generated source.
|
||||
//
|
||||
// To use GeneratedJavaLibraryModule, call GeneratedJavaLibraryModuleFactory with
|
||||
// a callback interface and a properties object to add to the module.
|
||||
//
|
||||
// These modules will have some properties blocked, and it will be an error if
|
||||
// modules attempt to set them. See the list of property names in GeneratedAndroidBuildActions
|
||||
// for the list of those properties.
|
||||
func GeneratedJavaLibraryModuleFactory(moduleName string, callbacks GeneratedJavaLibraryCallbacks, properties interface{}) android.Module {
|
||||
module := &GeneratedJavaLibraryModule{
|
||||
callbacks: callbacks,
|
||||
moduleName: moduleName,
|
||||
}
|
||||
module.addHostAndDeviceProperties()
|
||||
module.initModuleAndImport(module)
|
||||
android.InitApexModule(module)
|
||||
android.InitBazelModule(module)
|
||||
InitJavaModule(module, android.HostAndDeviceSupported)
|
||||
if properties != nil {
|
||||
module.AddProperties(properties)
|
||||
}
|
||||
return module
|
||||
}
|
||||
|
||||
func (module *GeneratedJavaLibraryModule) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||
module.callbacks.DepsMutator(module, ctx)
|
||||
module.Library.DepsMutator(ctx)
|
||||
}
|
||||
|
||||
func checkPropertyEmpty(ctx android.ModuleContext, module *GeneratedJavaLibraryModule, name string, value []string) {
|
||||
if len(value) != 0 {
|
||||
ctx.PropertyErrorf(name, "%s not allowed on %s", name, module.moduleName)
|
||||
}
|
||||
}
|
||||
|
||||
func (module *GeneratedJavaLibraryModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
// These modules are all-generated, so disallow these properties to keep it simple.
|
||||
// No additional sources
|
||||
checkPropertyEmpty(ctx, module, "srcs", module.Library.properties.Srcs)
|
||||
checkPropertyEmpty(ctx, module, "common_srcs", module.Library.properties.Common_srcs)
|
||||
checkPropertyEmpty(ctx, module, "exclude_srcs", module.Library.properties.Exclude_srcs)
|
||||
checkPropertyEmpty(ctx, module, "java_resource_dirs", module.Library.properties.Java_resource_dirs)
|
||||
checkPropertyEmpty(ctx, module, "exclude_java_resource_dirs", module.Library.properties.Exclude_java_resource_dirs)
|
||||
// No additional libraries. The generator should add anything necessary automatically
|
||||
// by returning something from ____ (TODO: Additional libraries aren't needed now, so
|
||||
// these are just blocked).
|
||||
checkPropertyEmpty(ctx, module, "libs", module.Library.properties.Libs)
|
||||
checkPropertyEmpty(ctx, module, "static_libs", module.Library.properties.Static_libs)
|
||||
// Restrict these for no good reason other than to limit the surface area. If there's a
|
||||
// good use case put them back.
|
||||
checkPropertyEmpty(ctx, module, "plugins", module.Library.properties.Plugins)
|
||||
checkPropertyEmpty(ctx, module, "exported_plugins", module.Library.properties.Exported_plugins)
|
||||
|
||||
srcJarPath := module.callbacks.GenerateSourceJarBuildActions(ctx)
|
||||
module.Library.properties.Generated_srcjars = append(module.Library.properties.Generated_srcjars, srcJarPath)
|
||||
module.Library.GenerateAndroidBuildActions(ctx)
|
||||
}
|
65
java/generated_java_library_test.go
Normal file
65
java/generated_java_library_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright 2018 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package java
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
func JavaGenLibTestFactory() android.Module {
|
||||
callbacks := &JavaGenLibTestCallbacks{}
|
||||
return GeneratedJavaLibraryModuleFactory("test_java_gen_lib", callbacks, &callbacks.properties)
|
||||
}
|
||||
|
||||
type JavaGenLibTestProperties struct {
|
||||
Foo string
|
||||
}
|
||||
|
||||
type JavaGenLibTestCallbacks struct {
|
||||
properties JavaGenLibTestProperties
|
||||
}
|
||||
|
||||
func (callbacks *JavaGenLibTestCallbacks) DepsMutator(module *GeneratedJavaLibraryModule, ctx android.BottomUpMutatorContext) {
|
||||
}
|
||||
|
||||
func (callbacks *JavaGenLibTestCallbacks) GenerateSourceJarBuildActions(ctx android.ModuleContext) android.Path {
|
||||
return android.PathForOutput(ctx, "blah.srcjar")
|
||||
}
|
||||
|
||||
func testGenLib(t *testing.T, errorHandler android.FixtureErrorHandler, bp string) *android.TestResult {
|
||||
return android.GroupFixturePreparers(
|
||||
PrepareForIntegrationTestWithJava,
|
||||
android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("test_java_gen_lib", JavaGenLibTestFactory)
|
||||
}),
|
||||
).
|
||||
ExtendWithErrorHandler(errorHandler).
|
||||
RunTestWithBp(t, bp)
|
||||
}
|
||||
|
||||
func TestGenLib(t *testing.T) {
|
||||
bp := `
|
||||
test_java_gen_lib {
|
||||
name: "javagenlibtest",
|
||||
foo: "bar", // Note: This won't parse if the property didn't get added
|
||||
}
|
||||
`
|
||||
result := testGenLib(t, android.FixtureExpectsNoErrors, bp)
|
||||
|
||||
javagenlibtest := result.ModuleForTests("javagenlibtest", "android_common").Module().(*GeneratedJavaLibraryModule)
|
||||
android.AssertPathsEndWith(t, "Generated_srcjars", []string{"/blah.srcjar"}, javagenlibtest.Library.properties.Generated_srcjars)
|
||||
}
|
@@ -273,6 +273,8 @@ type JavaInfo struct {
|
||||
// JacocoReportClassesFile is the path to a jar containing uninstrumented classes that will be
|
||||
// instrumented by jacoco.
|
||||
JacocoReportClassesFile android.Path
|
||||
|
||||
// TODO: Add device config declarations here?
|
||||
}
|
||||
|
||||
var JavaInfoProvider = blueprint.NewProvider(JavaInfo{})
|
||||
|
Reference in New Issue
Block a user