diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/Android.bp | 1 | ||||
-rw-r--r-- | java/aapt2.go | 7 | ||||
-rw-r--r-- | java/aar.go | 6 | ||||
-rw-r--r-- | java/app_test.go | 23 | ||||
-rw-r--r-- | java/base.go | 12 | ||||
-rw-r--r-- | java/container_test.go | 129 | ||||
-rw-r--r-- | java/java.go | 25 |
7 files changed, 197 insertions, 6 deletions
diff --git a/java/Android.bp b/java/Android.bp index 54b36ab60..a941754db 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -87,6 +87,7 @@ bootstrap_go_package { "app_set_test.go", "app_test.go", "code_metadata_test.go", + "container_test.go", "bootclasspath_fragment_test.go", "device_host_converter_test.go", "dex_test.go", diff --git a/java/aapt2.go b/java/aapt2.go index f704fc6fc..61cf37381 100644 --- a/java/aapt2.go +++ b/java/aapt2.go @@ -69,7 +69,7 @@ var aapt2CompileRule = pctx.AndroidStaticRule("aapt2Compile", // aapt2Compile compiles resources and puts the results in the requested directory. func aapt2Compile(ctx android.ModuleContext, dir android.Path, paths android.Paths, - flags []string, productToFilter string) android.WritablePaths { + flags []string, productToFilter string, featureFlagsPaths android.Paths) android.WritablePaths { if productToFilter != "" && productToFilter != "default" { // --filter-product leaves only product-specific resources. Product-specific resources only exist // in value resources (values/*.xml), so filter value resource files only. Ignore other types of @@ -85,6 +85,10 @@ func aapt2Compile(ctx android.ModuleContext, dir android.Path, paths android.Pat flags = append([]string{"--filter-product " + productToFilter}, flags...) } + for _, featureFlagsPath := range android.SortedUniquePaths(featureFlagsPaths) { + flags = append(flags, "--feature-flags", "@"+featureFlagsPath.String()) + } + // Shard the input paths so that they can be processed in parallel. If we shard them into too // small chunks, the additional cost of spinning up aapt2 outweighs the performance gain. The // current shard size, 100, seems to be a good balance between the added cost and the gain. @@ -112,6 +116,7 @@ func aapt2Compile(ctx android.ModuleContext, dir android.Path, paths android.Pat ctx.Build(pctx, android.BuildParams{ Rule: aapt2CompileRule, Description: "aapt2 compile " + dir.String() + shardDesc, + Implicits: featureFlagsPaths, Inputs: shard, Outputs: outPaths, Args: map[string]string{ diff --git a/java/aar.go b/java/aar.go index 2f49a959d..b69b7c262 100644 --- a/java/aar.go +++ b/java/aar.go @@ -440,7 +440,8 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio var compiledResDirs []android.Paths for _, dir := range resDirs { a.resourceFiles = append(a.resourceFiles, dir.files...) - compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags, a.filterProduct()).Paths()) + compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, + compileFlags, a.filterProduct(), opts.aconfigTextFiles).Paths()) } for i, zip := range resZips { @@ -499,7 +500,8 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio } for _, dir := range overlayDirs { - compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags, a.filterProduct()).Paths()...) + compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, + compileFlags, a.filterProduct(), opts.aconfigTextFiles).Paths()...) } var splitPackages android.WritablePaths diff --git a/java/app_test.go b/java/app_test.go index e878ccf6d..6b7d522f3 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -4364,7 +4364,16 @@ func TestPrivappAllowlistAndroidMk(t *testing.T) { } func TestAppFlagsPackages(t *testing.T) { - ctx := testApp(t, ` + ctx := android.GroupFixturePreparers( + prepareForJavaTest, + android.FixtureMergeMockFs( + map[string][]byte{ + "res/layout/layout.xml": nil, + "res/values/strings.xml": nil, + "res/values-en-rUS/strings.xml": nil, + }, + ), + ).RunTestWithBp(t, ` android_app { name: "foo", srcs: ["a.java"], @@ -4396,10 +4405,10 @@ func TestAppFlagsPackages(t *testing.T) { // android_app module depends on aconfig_declarations listed in flags_packages android.AssertBoolEquals(t, "foo expected to depend on bar", true, - CheckModuleHasDependency(t, ctx, "foo", "android_common", "bar")) + CheckModuleHasDependency(t, ctx.TestContext, "foo", "android_common", "bar")) android.AssertBoolEquals(t, "foo expected to depend on baz", true, - CheckModuleHasDependency(t, ctx, "foo", "android_common", "baz")) + CheckModuleHasDependency(t, ctx.TestContext, "foo", "android_common", "baz")) aapt2LinkRule := foo.Rule("android/soong/java.aapt2Link") linkInFlags := aapt2LinkRule.Args["inFlags"] @@ -4408,6 +4417,14 @@ func TestAppFlagsPackages(t *testing.T) { linkInFlags, "--feature-flags @out/soong/.intermediates/bar/intermediate.txt --feature-flags @out/soong/.intermediates/baz/intermediate.txt", ) + + aapt2CompileRule := foo.Rule("android/soong/java.aapt2Compile") + compileFlags := aapt2CompileRule.Args["cFlags"] + android.AssertStringDoesContain(t, + "aapt2 compile command expected to pass feature flags arguments", + compileFlags, + "--feature-flags @out/soong/.intermediates/bar/intermediate.txt --feature-flags @out/soong/.intermediates/baz/intermediate.txt", + ) } func TestAppFlagsPackagesPropagation(t *testing.T) { diff --git a/java/base.go b/java/base.go index fc68d2018..02dc3e35b 100644 --- a/java/base.go +++ b/java/base.go @@ -552,6 +552,18 @@ type Module struct { aconfigCacheFiles android.Paths } +var _ android.InstallableModule = (*Module)(nil) + +// To satisfy the InstallableModule interface +func (j *Module) EnforceApiContainerChecks() bool { + return true +} + +// Overrides android.ModuleBase.InstallInProduct() +func (j *Module) InstallInProduct() bool { + return j.ProductSpecific() +} + func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error { sdkVersion := j.SdkVersion(ctx) if sdkVersion.Stable() { diff --git a/java/container_test.go b/java/container_test.go new file mode 100644 index 000000000..344185553 --- /dev/null +++ b/java/container_test.go @@ -0,0 +1,129 @@ +// Copyright 2024 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" + "fmt" + "testing" +) + +var checkContainerMatch = func(t *testing.T, name string, container string, expected bool, actual bool) { + errorMessage := fmt.Sprintf("module %s container %s value differ", name, container) + android.AssertBoolEquals(t, errorMessage, expected, actual) +} + +func TestJavaContainersModuleProperties(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForJavaTest, + ).RunTestWithBp(t, ` + java_library { + name: "foo", + srcs: ["A.java"], + } + java_library { + name: "foo_vendor", + srcs: ["A.java"], + vendor: true, + sdk_version: "current", + } + java_library { + name: "foo_soc_specific", + srcs: ["A.java"], + soc_specific: true, + sdk_version: "current", + } + java_library { + name: "foo_product_specific", + srcs: ["A.java"], + product_specific: true, + sdk_version: "current", + } + java_test { + name: "foo_cts_test", + srcs: ["A.java"], + test_suites: [ + "cts", + ], + } + java_test { + name: "foo_non_cts_test", + srcs: ["A.java"], + test_suites: [ + "general-tests", + ], + } + `) + + testcases := []struct { + moduleName string + isSystemContainer bool + isVendorContainer bool + isProductContainer bool + isCts bool + }{ + { + moduleName: "foo", + isSystemContainer: true, + isVendorContainer: false, + isProductContainer: false, + isCts: false, + }, + { + moduleName: "foo_vendor", + isSystemContainer: false, + isVendorContainer: true, + isProductContainer: false, + isCts: false, + }, + { + moduleName: "foo_soc_specific", + isSystemContainer: false, + isVendorContainer: true, + isProductContainer: false, + isCts: false, + }, + { + moduleName: "foo_product_specific", + isSystemContainer: false, + isVendorContainer: false, + isProductContainer: true, + isCts: false, + }, + { + moduleName: "foo_cts_test", + isSystemContainer: false, + isVendorContainer: false, + isProductContainer: false, + isCts: true, + }, + { + moduleName: "foo_non_cts_test", + isSystemContainer: false, + isVendorContainer: false, + isProductContainer: false, + isCts: false, + }, + } + + for _, c := range testcases { + m := result.ModuleForTests(c.moduleName, "android_common") + containers, _ := android.OtherModuleProvider(result.TestContext.OtherModuleProviderAdaptor(), m.Module(), android.ContainersInfoProvider) + belongingContainers := containers.BelongingContainers() + checkContainerMatch(t, c.moduleName, "system", c.isSystemContainer, android.InList(android.SystemContainer, belongingContainers)) + checkContainerMatch(t, c.moduleName, "vendor", c.isVendorContainer, android.InList(android.VendorContainer, belongingContainers)) + checkContainerMatch(t, c.moduleName, "product", c.isProductContainer, android.InList(android.ProductContainer, belongingContainers)) + } +} diff --git a/java/java.go b/java/java.go index 88b31b586..498b53939 100644 --- a/java/java.go +++ b/java/java.go @@ -2386,10 +2386,35 @@ func (al *ApiLibrary) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiL return android.FutureApiLevel } +func (al *ApiLibrary) IDEInfo(i *android.IdeInfo) { + i.Deps = append(i.Deps, al.ideDeps()...) + i.Libs = append(i.Libs, al.properties.Libs...) + i.Static_libs = append(i.Static_libs, al.properties.Static_libs...) + i.SrcJars = append(i.SrcJars, al.stubsSrcJar.String()) +} + +// deps of java_api_library for module_bp_java_deps.json +func (al *ApiLibrary) ideDeps() []string { + ret := []string{} + ret = append(ret, al.properties.Libs...) + ret = append(ret, al.properties.Static_libs...) + if al.properties.System_modules != nil { + ret = append(ret, proptools.String(al.properties.System_modules)) + } + if al.properties.Full_api_surface_stub != nil { + ret = append(ret, proptools.String(al.properties.Full_api_surface_stub)) + } + // Other non java_library dependencies like java_api_contribution are ignored for now. + return ret +} + // implement the following interfaces for hiddenapi processing var _ hiddenAPIModule = (*ApiLibrary)(nil) var _ UsesLibraryDependency = (*ApiLibrary)(nil) +// implement the following interface for IDE completion. +var _ android.IDEInfo = (*ApiLibrary)(nil) + // // Java prebuilts // |