Merge "rust: Enable Product support for dylibs." into main
diff --git a/aconfig/Android.bp b/aconfig/Android.bp
index 5e0620e..6927765 100644
--- a/aconfig/Android.bp
+++ b/aconfig/Android.bp
@@ -20,6 +20,7 @@
"aconfig_values.go",
"aconfig_value_set.go",
"all_aconfig_declarations.go",
+ "cc_aconfig_library.go",
"init.go",
"java_aconfig_library.go",
"testing.go",
diff --git a/aconfig/cc_aconfig_library.go b/aconfig/cc_aconfig_library.go
new file mode 100644
index 0000000..14090bc
--- /dev/null
+++ b/aconfig/cc_aconfig_library.go
@@ -0,0 +1,128 @@
+// 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 aconfig
+
+import (
+ "android/soong/android"
+ "android/soong/cc"
+ "github.com/google/blueprint"
+
+ "fmt"
+ "strings"
+)
+
+type ccDeclarationsTagType struct {
+ blueprint.BaseDependencyTag
+}
+
+var ccDeclarationsTag = ccDeclarationsTagType{}
+
+type CcAconfigLibraryProperties struct {
+ // name of the aconfig_declarations module to generate a library for
+ Aconfig_declarations string
+}
+
+type CcAconfigLibraryCallbacks struct {
+ properties *CcAconfigLibraryProperties
+
+ generatedDir android.WritablePath
+ headerDir android.WritablePath
+ generatedCpp android.WritablePath
+ generatedH android.WritablePath
+}
+
+func CcAconfigLibraryFactory() android.Module {
+ callbacks := &CcAconfigLibraryCallbacks{
+ properties: &CcAconfigLibraryProperties{},
+ }
+ return cc.GeneratedCcLibraryModuleFactory("cc_aconfig_library", callbacks)
+}
+
+func (this *CcAconfigLibraryCallbacks) GeneratorInit(ctx cc.BaseModuleContext) {
+}
+
+func (this *CcAconfigLibraryCallbacks) GeneratorProps() []interface{} {
+ return []interface{}{this.properties}
+}
+
+func (this *CcAconfigLibraryCallbacks) GeneratorDeps(ctx cc.DepsContext, deps cc.Deps) cc.Deps {
+ // Add a dependency for the declarations module
+ declarations := this.properties.Aconfig_declarations
+ if len(declarations) == 0 {
+ ctx.PropertyErrorf("aconfig_declarations", "aconfig_declarations property required")
+ } else {
+ ctx.AddDependency(ctx.Module(), ccDeclarationsTag, declarations)
+ }
+
+ // Add a dependency for the aconfig flags base library
+ deps.SharedLibs = append(deps.SharedLibs, "server_configurable_flags")
+ // TODO: It'd be really nice if we could reexport this library and not make everyone do it.
+
+ return deps
+}
+
+func (this *CcAconfigLibraryCallbacks) GeneratorSources(ctx cc.ModuleContext) cc.GeneratedSource {
+ result := cc.GeneratedSource{}
+
+ // Get the values that came from the global RELEASE_ACONFIG_VALUE_SETS flag
+ declarationsModules := ctx.GetDirectDepsWithTag(ccDeclarationsTag)
+ if len(declarationsModules) != 1 {
+ panic(fmt.Errorf("Exactly one aconfig_declarations property required"))
+ }
+ declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
+
+ // Figure out the generated file paths. This has to match aconfig's codegen_cpp.rs.
+ this.generatedDir = android.PathForModuleGen(ctx)
+
+ this.headerDir = android.PathForModuleGen(ctx, "include")
+ result.IncludeDirs = []android.Path{this.headerDir}
+ result.ReexportedDirs = []android.Path{this.headerDir}
+
+ basename := strings.ReplaceAll(declarations.Package, ".", "_")
+
+ this.generatedCpp = android.PathForModuleGen(ctx, basename+".cc")
+ result.Sources = []android.Path{this.generatedCpp}
+
+ this.generatedH = android.PathForModuleGen(ctx, "include", basename+".h")
+ result.Headers = []android.Path{this.generatedH}
+
+ return result
+}
+
+func (this *CcAconfigLibraryCallbacks) GeneratorFlags(ctx cc.ModuleContext, flags cc.Flags, deps cc.PathDeps) cc.Flags {
+ return flags
+}
+
+func (this *CcAconfigLibraryCallbacks) GeneratorBuildActions(ctx cc.ModuleContext, flags cc.Flags, deps cc.PathDeps) {
+ // Get the values that came from the global RELEASE_ACONFIG_VALUE_SETS flag
+ declarationsModules := ctx.GetDirectDepsWithTag(ccDeclarationsTag)
+ if len(declarationsModules) != 1 {
+ panic(fmt.Errorf("Exactly one aconfig_declarations property required"))
+ }
+ declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: cppRule,
+ Input: declarations.IntermediatePath,
+ Outputs: []android.WritablePath{
+ this.generatedCpp,
+ this.generatedH,
+ },
+ Description: "cc_aconfig_library",
+ Args: map[string]string{
+ "gendir": this.generatedDir.String(),
+ },
+ })
+}
diff --git a/aconfig/init.go b/aconfig/init.go
index 634612d..3ed5faf 100644
--- a/aconfig/init.go
+++ b/aconfig/init.go
@@ -39,7 +39,7 @@
}, "release_version", "package", "declarations", "values")
// For java_aconfig_library: Generate java file
- srcJarRule = pctx.AndroidStaticRule("aconfig_srcjar",
+ javaRule = pctx.AndroidStaticRule("java_aconfig_library",
blueprint.RuleParams{
Command: `rm -rf ${out}.tmp` +
` && mkdir -p ${out}.tmp` +
@@ -55,6 +55,20 @@
Restat: true,
})
+ // For java_aconfig_library: Generate java file
+ cppRule = pctx.AndroidStaticRule("cc_aconfig_library",
+ blueprint.RuleParams{
+ Command: `rm -rf ${gendir}` +
+ ` && mkdir -p ${gendir}` +
+ ` && ${aconfig} create-cpp-lib` +
+ ` --cache ${in}` +
+ ` --out ${gendir}`,
+ CommandDeps: []string{
+ "$aconfig",
+ "$soong_zip",
+ },
+ }, "gendir")
+
// For all_aconfig_declarations
allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump",
blueprint.RuleParams{
@@ -75,6 +89,7 @@
ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
ctx.RegisterModuleType("aconfig_values", ValuesFactory)
ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
+ ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory)
ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
}
diff --git a/aconfig/java_aconfig_library.go b/aconfig/java_aconfig_library.go
index f98498e..53b2b10 100644
--- a/aconfig/java_aconfig_library.go
+++ b/aconfig/java_aconfig_library.go
@@ -62,7 +62,7 @@
// Generate the action to build the srcjar
srcJarPath := android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar")
ctx.Build(pctx, android.BuildParams{
- Rule: srcJarRule,
+ Rule: javaRule,
Input: declarations.IntermediatePath,
Output: srcJarPath,
Description: "aconfig.srcjar",
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 6f09a6d..a473343 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -141,11 +141,12 @@
"external/expat": Bp2BuildDefaultTrueRecursively,
"external/f2fs-tools": Bp2BuildDefaultTrue,
"external/flac": Bp2BuildDefaultTrueRecursively,
+ "external/flatbuffers": Bp2BuildDefaultTrueRecursively,
"external/fmtlib": Bp2BuildDefaultTrueRecursively,
"external/fsverity-utils": Bp2BuildDefaultTrueRecursively,
- "external/guava": Bp2BuildDefaultTrueRecursively,
"external/google-benchmark": Bp2BuildDefaultTrueRecursively,
"external/googletest": Bp2BuildDefaultTrueRecursively,
+ "external/guava": Bp2BuildDefaultTrueRecursively,
"external/gwp_asan": Bp2BuildDefaultTrueRecursively,
"external/hamcrest": Bp2BuildDefaultTrueRecursively,
"external/icu": Bp2BuildDefaultTrueRecursively,
@@ -227,6 +228,7 @@
"frameworks/hardware/interfaces/stats/aidl": Bp2BuildDefaultTrue,
"frameworks/libs/modules-utils/build": Bp2BuildDefaultTrueRecursively,
"frameworks/libs/net/common/native": Bp2BuildDefaultTrueRecursively,
+ "frameworks/native": Bp2BuildDefaultTrue,
"frameworks/native/libs/adbd_auth": Bp2BuildDefaultTrueRecursively,
"frameworks/native/libs/arect": Bp2BuildDefaultTrueRecursively,
"frameworks/native/libs/gui": Bp2BuildDefaultTrue,
@@ -474,6 +476,8 @@
Bp2buildModuleAlwaysConvertList = []string{
"libidmap2_policies",
"libSurfaceFlingerProp",
+ "toolbox_input_labels",
+
// cc mainline modules
// com.android.media.swcodec
@@ -491,7 +495,6 @@
"code_coverage.policy.other",
"codec2_soft_exports",
"compatibility_matrix_schema",
- "flatbuffer_headers",
"framework-connectivity-protos",
"gemmlowp_headers",
"gl_headers",
@@ -614,10 +617,6 @@
"libhidlbase", // needed by cc_hidl_library
"libhidl_gtest_helper",
- //frameworks/native
- "framework_native_aidl_binder",
- "framework_native_aidl_gui",
-
//frameworks/native/libs/input
"inputconstants_aidl",
@@ -764,6 +763,7 @@
// Mainline Module Apps
"CaptivePortalLogin",
+ "ModuleMetadata",
"libstagefright_headers",
@@ -1492,8 +1492,6 @@
"ICU4CTestRunner",
"DeviceLongPollingStubTest",
- "HelloWorldHostTest", // TODO(b/280452825): Convert HelloWorldHostTest to b test
-
"libprotobuf-full-test", // TODO(b/246997908): cannot convert proto_libraries which implicitly include other srcs in the same directory
"libprotobuf-lite-test", // TODO(b/246997908): cannot convert proto_libraries which implicitly include other srcs in the same directory
diff --git a/android/api_levels.go b/android/api_levels.go
index 2391e6c..44c8640 100644
--- a/android/api_levels.go
+++ b/android/api_levels.go
@@ -275,10 +275,6 @@
// relocations itself.
var FirstPackedRelocationsVersion = uncheckedFinalApiLevel(23)
-// The first API level that does not require NDK code to link
-// libandroid_support.
-var FirstNonLibAndroidSupportVersion = uncheckedFinalApiLevel(21)
-
// LastWithoutModuleLibCoreSystemModules is the last API level where prebuilts/sdk does not contain
// a core-for-system-modules.jar for the module-lib API scope.
var LastWithoutModuleLibCoreSystemModules = uncheckedFinalApiLevel(31)
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index 4d91cc8..94bc88b 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -1389,9 +1389,6 @@
cmd.ImplicitOutput(PathForBazelOut(ctx, outputPath))
}
}
- for _, inputPath := range buildStatement.OrderOnlyInputs {
- cmd.OrderOnly(PathForBazelOut(ctx, inputPath))
- }
for _, inputPath := range buildStatement.InputPaths {
cmd.Implicit(PathForBazelOut(ctx, inputPath))
}
diff --git a/bazel/aquery.go b/bazel/aquery.go
index 186a494..3428328 100644
--- a/bazel/aquery.go
+++ b/bazel/aquery.go
@@ -115,7 +115,6 @@
// input path string, but not both.
InputDepsetHashes []string
InputPaths []string
- OrderOnlyInputs []string
FileContents string
// If ShouldRunInSbox is true, Soong will use sbox to created an isolated environment
// and run the mixed build action there
@@ -138,8 +137,6 @@
depsetHashToArtifactPathsCache sync.Map
// Maps artifact ids to fully expanded paths.
artifactIdToPath map[artifactId]string
-
- extraBuildStatements []*BuildStatement
}
// The tokens should be substituted with the value specified here, instead of the
@@ -169,29 +166,13 @@
return pathFragmentId(pf.Id)
})
- var extraBuildStatements []*BuildStatement
artifactIdToPath := make(map[artifactId]string, len(aqueryResult.Artifacts))
for _, artifact := range aqueryResult.Artifacts {
artifactPath, err := expandPathFragment(pathFragmentId(artifact.PathFragmentId), pathFragments)
if err != nil {
return nil, err
}
- if strings.HasSuffix(artifactPath, "DumpPlatformClassPath.java") {
- // TODO(b/291828210): This is a workaround for the fact that DumpPlatformClassPath.java
- // has a timestamp in 2033. We'll copy it to a new file using a order-only dep, so that
- // the file is not recopied every build. Technically the order-only dep would produce
- // incremental build issues if this was a regular file produced as part of the build,
- // but this file is actually created by bazel during analysis, so it's not an issue.
- outputPath := "hack_for_b291828210/DumpPlatformClassPath.java"
- extraBuildStatements = append(extraBuildStatements, &BuildStatement{
- Command: fmt.Sprintf("cp %s %s", artifactPath, outputPath),
- OutputPaths: []string{outputPath},
- OrderOnlyInputs: []string{artifactPath},
- })
- artifactIdToPath[artifactId(artifact.Id)] = outputPath
- } else {
- artifactIdToPath[artifactId(artifact.Id)] = artifactPath
- }
+ artifactIdToPath[artifactId(artifact.Id)] = artifactPath
}
// Map middleman artifact ContentHash to input artifact depset ID.
@@ -218,7 +199,6 @@
depsetHashToArtifactPathsCache: sync.Map{},
emptyDepsetIds: make(map[depsetId]struct{}, 0),
artifactIdToPath: artifactIdToPath,
- extraBuildStatements: extraBuildStatements,
}
// Validate and adjust aqueryResult.DepSetOfFiles values.
@@ -392,7 +372,6 @@
if err != nil {
return nil, nil, err
}
- buildStatements = append(buildStatements, aqueryHandler.extraBuildStatements...)
depsetsByHash := map[string]AqueryDepset{}
depsets := make([]AqueryDepset, 0, len(aqueryHandler.depsetIdToAqueryDepset))
diff --git a/bp2build/bp2build_product_config.go b/bp2build/bp2build_product_config.go
index 42a0866..c8067af 100644
--- a/bp2build/bp2build_product_config.go
+++ b/bp2build/bp2build_product_config.go
@@ -183,6 +183,7 @@
buildSettings += fmt.Sprintf(" --//build/bazel/product_config:cfi_include_paths=%s\n", strings.Join(productVariables.CFIIncludePaths, ","))
buildSettings += fmt.Sprintf(" --//build/bazel/product_config:cfi_exclude_paths=%s\n", strings.Join(productVariables.CFIExcludePaths, ","))
buildSettings += fmt.Sprintf(" --//build/bazel/product_config:enable_cfi=%t\n", proptools.BoolDefault(productVariables.EnableCFI, true))
+ buildSettings += fmt.Sprintf(" --//build/bazel/product_config:device_abi=%s\n", strings.Join(productVariables.DeviceAbi, ","))
result := ""
for _, suffix := range bazelPlatformSuffixes {
result += " " + label + suffix + "\n" + buildSettings
@@ -209,5 +210,9 @@
if err != nil {
return result, err
}
+ result.DeviceAbi, err = starlark_import.Unmarshal[[]string](in["DeviceAbi"])
+ if err != nil {
+ return result, err
+ }
return result, nil
}
diff --git a/bp2build/java_test_host_conversion_test.go b/bp2build/java_test_host_conversion_test.go
index f411ffb..f41345e 100644
--- a/bp2build/java_test_host_conversion_test.go
+++ b/bp2build/java_test_host_conversion_test.go
@@ -71,6 +71,11 @@
}),
MakeBazelTarget("java_test", "java_test_host-1", AttrNameToString{
"runtime_deps": `[":java_test_host-1_lib"]`,
+ "deps": `[
+ ":lib_a-neverlink",
+ ":static_libs_a",
+ ]`,
+ "srcs": `["a.java"]`,
"target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
@@ -128,6 +133,10 @@
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_test", "java_test_host-1", AttrNameToString{
+ "srcs": `[
+ "a.java",
+ "b.kt",
+ ]`,
"runtime_deps": `[":java_test_host-1_lib"]`,
"target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
diff --git a/cc/Android.bp b/cc/Android.bp
index f49dc1a..e88ea03 100644
--- a/cc/Android.bp
+++ b/cc/Android.bp
@@ -32,6 +32,7 @@
"check.go",
"coverage.go",
"gen.go",
+ "generated_cc_library.go",
"image.go",
"linkable.go",
"lto.go",
diff --git a/cc/cc.go b/cc/cc.go
index 84b80a1..be67286 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -569,6 +569,24 @@
props() []interface{}
}
+// Information returned from Generator about the source code it's generating
+type GeneratedSource struct {
+ IncludeDirs android.Paths
+ Sources android.Paths
+ Headers android.Paths
+ ReexportedDirs android.Paths
+}
+
+// generator allows injection of generated code
+type Generator interface {
+ GeneratorProps() []interface{}
+ GeneratorInit(ctx BaseModuleContext)
+ GeneratorDeps(ctx DepsContext, deps Deps) Deps
+ GeneratorFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
+ GeneratorSources(ctx ModuleContext) GeneratedSource
+ GeneratorBuildActions(ctx ModuleContext, flags Flags, deps PathDeps)
+}
+
// compiler is the interface for a compiler helper object. Different module decorators may implement
// this helper differently.
type compiler interface {
@@ -851,6 +869,7 @@
// type-specific logic. These members may reference different objects or the same object.
// Functions of these decorators will be invoked to initialize and register type-specific
// build statements.
+ generators []Generator
compiler compiler
linker linker
installer installer
@@ -1201,6 +1220,9 @@
func (c *Module) Init() android.Module {
c.AddProperties(&c.Properties, &c.VendorProperties)
+ for _, generator := range c.generators {
+ c.AddProperties(generator.GeneratorProps()...)
+ }
if c.compiler != nil {
c.AddProperties(c.compiler.compilerProps()...)
}
@@ -2149,6 +2171,25 @@
return
}
+ for _, generator := range c.generators {
+ gen := generator.GeneratorSources(ctx)
+ deps.IncludeDirs = append(deps.IncludeDirs, gen.IncludeDirs...)
+ deps.ReexportedDirs = append(deps.ReexportedDirs, gen.ReexportedDirs...)
+ deps.GeneratedDeps = append(deps.GeneratedDeps, gen.Headers...)
+ deps.ReexportedGeneratedHeaders = append(deps.ReexportedGeneratedHeaders, gen.Headers...)
+ deps.ReexportedDeps = append(deps.ReexportedDeps, gen.Headers...)
+ if len(deps.Objs.objFiles) == 0 {
+ // If we are reusuing object files (which happens when we're a shared library and we're
+ // reusing our static variant's object files), then skip adding the actual source files,
+ // because we already have the object for it.
+ deps.GeneratedSources = append(deps.GeneratedSources, gen.Sources...)
+ }
+ }
+
+ if ctx.Failed() {
+ return
+ }
+
if c.stubLibraryMultipleApexViolation(actx) {
actx.PropertyErrorf("apex_available",
"Stub libraries should have a single apex_available (test apexes excluded). Got %v", c.ApexAvailable())
@@ -2163,6 +2204,9 @@
Toolchain: c.toolchain(ctx),
EmitXrefs: ctx.Config().EmitXrefRules(),
}
+ for _, generator := range c.generators {
+ flags = generator.GeneratorFlags(ctx, flags, deps)
+ }
if c.compiler != nil {
flags = c.compiler.compilerFlags(ctx, flags, deps)
}
@@ -2220,6 +2264,10 @@
flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
+ for _, generator := range c.generators {
+ generator.GeneratorBuildActions(ctx, flags, deps)
+ }
+
var objs Objects
if c.compiler != nil {
objs = c.compiler.compile(ctx, flags, deps)
@@ -2307,6 +2355,9 @@
}
func (c *Module) begin(ctx BaseModuleContext) {
+ for _, generator := range c.generators {
+ generator.GeneratorInit(ctx)
+ }
if c.compiler != nil {
c.compiler.compilerInit(ctx)
}
@@ -2342,6 +2393,9 @@
func (c *Module) deps(ctx DepsContext) Deps {
deps := Deps{}
+ for _, generator := range c.generators {
+ deps = generator.GeneratorDeps(ctx, deps)
+ }
if c.compiler != nil {
deps = c.compiler.compilerDeps(ctx, deps)
}
diff --git a/cc/generated_cc_library.go b/cc/generated_cc_library.go
new file mode 100644
index 0000000..55e19f9
--- /dev/null
+++ b/cc/generated_cc_library.go
@@ -0,0 +1,38 @@
+// 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 cc
+
+import (
+ "android/soong/android"
+)
+
+func GeneratedCcLibraryModuleFactory(moduleName string, callbacks Generator) android.Module {
+ module, _ := NewLibrary(android.HostAndDeviceSupported)
+
+ // Can be used as both a static and a shared library.
+ module.sdkMemberTypes = []android.SdkMemberType{
+ sharedLibrarySdkMemberType,
+ staticLibrarySdkMemberType,
+ staticAndSharedLibrarySdkMemberType,
+ }
+
+ // TODO: Need to be bazelable
+ // module.bazelable = true
+ // module.bazelHandler = &ccLibraryBazelHandler{module: module}
+
+ module.generators = append(module.generators, callbacks)
+
+ return module.Init()
+}
diff --git a/cc/stl.go b/cc/stl.go
index f1433ef..ffc7c76 100644
--- a/cc/stl.go
+++ b/cc/stl.go
@@ -120,11 +120,6 @@
}()
}
-func needsLibAndroidSupport(ctx BaseModuleContext) bool {
- version := nativeApiLevelOrPanic(ctx, ctx.sdkVersion())
- return version.LessThan(android.FirstNonLibAndroidSupportVersion)
-}
-
func staticUnwinder(ctx android.BaseModuleContext) string {
vndkVersion := ctx.Module().(*Module).VndkVersion()
@@ -184,11 +179,6 @@
} else {
deps.StaticLibs = append(deps.StaticLibs, stl.Properties.SelectedStl, "ndk_libc++abi")
}
- if needsLibAndroidSupport(ctx) {
- // Use LateStaticLibs for ndk_libandroid_support so that its include directories
- // come after ndk_libc++_static or ndk_libc++_shared.
- deps.LateStaticLibs = append(deps.LateStaticLibs, "ndk_libandroid_support")
- }
deps.StaticLibs = append(deps.StaticLibs, "ndk_libunwind")
default:
panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl))
diff --git a/cc/testing.go b/cc/testing.go
index d346739..d1632aa 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -423,11 +423,6 @@
export_include_dirs: ["ndk_libc++_shared"],
}
- ndk_prebuilt_static_stl {
- name: "ndk_libandroid_support",
- export_include_dirs: ["ndk_libandroid_support"],
- }
-
cc_library_static {
name: "libgoogle-benchmark",
sdk_version: "current",
@@ -573,16 +568,15 @@
// Additional files needed in tests that disallow non-existent source.
android.MockFS{
- "defaults/cc/common/libc.map.txt": nil,
- "defaults/cc/common/libdl.map.txt": nil,
- "defaults/cc/common/libm.map.txt": nil,
- "defaults/cc/common/ndk_libandroid_support": nil,
- "defaults/cc/common/ndk_libc++_shared": nil,
- "defaults/cc/common/crtbegin_so.c": nil,
- "defaults/cc/common/crtbegin.c": nil,
- "defaults/cc/common/crtend_so.c": nil,
- "defaults/cc/common/crtend.c": nil,
- "defaults/cc/common/crtbrand.c": nil,
+ "defaults/cc/common/libc.map.txt": nil,
+ "defaults/cc/common/libdl.map.txt": nil,
+ "defaults/cc/common/libm.map.txt": nil,
+ "defaults/cc/common/ndk_libc++_shared": nil,
+ "defaults/cc/common/crtbegin_so.c": nil,
+ "defaults/cc/common/crtbegin.c": nil,
+ "defaults/cc/common/crtend_so.c": nil,
+ "defaults/cc/common/crtend.c": nil,
+ "defaults/cc/common/crtbrand.c": nil,
"defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
"defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
diff --git a/cmd/merge_zips/merge_zips.go b/cmd/merge_zips/merge_zips.go
index e3d1179..a70a9d1 100644
--- a/cmd/merge_zips/merge_zips.go
+++ b/cmd/merge_zips/merge_zips.go
@@ -122,7 +122,7 @@
}
func (be ZipEntryFromBuffer) WriteToZip(dest string, zw *zip.Writer) error {
- w, err := zw.CreateHeader(be.fh)
+ w, err := zw.CreateHeaderAndroid(be.fh)
if err != nil {
return err
}
@@ -562,6 +562,8 @@
}
}
+ var jarServices jar.Services
+
// Finally, add entries from all the input zips.
for _, inputZip := range inputZips {
_, copyFully := zipsToNotStrip[inputZip.Name()]
@@ -570,6 +572,14 @@
}
for i, entry := range inputZip.Entries() {
+ if emulateJar && jarServices.IsServiceFile(entry) {
+ // If this is a jar, collect service files to combine instead of adding them to the zip.
+ err := jarServices.AddServiceFile(entry)
+ if err != nil {
+ return err
+ }
+ continue
+ }
if copyFully || !out.isEntryExcluded(entry.Name) {
if err := out.copyEntry(inputZip, i); err != nil {
return err
@@ -585,6 +595,16 @@
}
if emulateJar {
+ // Combine all the service files into a single list of combined service files and add them to the zip.
+ for _, serviceFile := range jarServices.ServiceFiles() {
+ _, err := out.addZipEntry(serviceFile.Name, ZipEntryFromBuffer{
+ fh: serviceFile.FileHeader,
+ content: serviceFile.Contents,
+ })
+ if err != nil {
+ return err
+ }
+ }
return out.writeEntries(out.jarSorted())
} else if sortEntries {
return out.writeEntries(out.alphanumericSorted())
diff --git a/cmd/merge_zips/merge_zips_test.go b/cmd/merge_zips/merge_zips_test.go
index cb58436..767d4e61 100644
--- a/cmd/merge_zips/merge_zips_test.go
+++ b/cmd/merge_zips/merge_zips_test.go
@@ -17,6 +17,7 @@
import (
"bytes"
"fmt"
+ "hash/crc32"
"os"
"strconv"
"strings"
@@ -27,28 +28,34 @@
)
type testZipEntry struct {
- name string
- mode os.FileMode
- data []byte
+ name string
+ mode os.FileMode
+ data []byte
+ method uint16
}
var (
- A = testZipEntry{"A", 0755, []byte("foo")}
- a = testZipEntry{"a", 0755, []byte("foo")}
- a2 = testZipEntry{"a", 0755, []byte("FOO2")}
- a3 = testZipEntry{"a", 0755, []byte("Foo3")}
- bDir = testZipEntry{"b/", os.ModeDir | 0755, nil}
- bbDir = testZipEntry{"b/b/", os.ModeDir | 0755, nil}
- bbb = testZipEntry{"b/b/b", 0755, nil}
- ba = testZipEntry{"b/a", 0755, []byte("foob")}
- bc = testZipEntry{"b/c", 0755, []byte("bar")}
- bd = testZipEntry{"b/d", 0700, []byte("baz")}
- be = testZipEntry{"b/e", 0700, []byte("")}
+ A = testZipEntry{"A", 0755, []byte("foo"), zip.Deflate}
+ a = testZipEntry{"a", 0755, []byte("foo"), zip.Deflate}
+ a2 = testZipEntry{"a", 0755, []byte("FOO2"), zip.Deflate}
+ a3 = testZipEntry{"a", 0755, []byte("Foo3"), zip.Deflate}
+ bDir = testZipEntry{"b/", os.ModeDir | 0755, nil, zip.Deflate}
+ bbDir = testZipEntry{"b/b/", os.ModeDir | 0755, nil, zip.Deflate}
+ bbb = testZipEntry{"b/b/b", 0755, nil, zip.Deflate}
+ ba = testZipEntry{"b/a", 0755, []byte("foo"), zip.Deflate}
+ bc = testZipEntry{"b/c", 0755, []byte("bar"), zip.Deflate}
+ bd = testZipEntry{"b/d", 0700, []byte("baz"), zip.Deflate}
+ be = testZipEntry{"b/e", 0700, []byte(""), zip.Deflate}
- metainfDir = testZipEntry{jar.MetaDir, os.ModeDir | 0755, nil}
- manifestFile = testZipEntry{jar.ManifestFile, 0755, []byte("manifest")}
- manifestFile2 = testZipEntry{jar.ManifestFile, 0755, []byte("manifest2")}
- moduleInfoFile = testZipEntry{jar.ModuleInfoClass, 0755, []byte("module-info")}
+ service1a = testZipEntry{"META-INF/services/service1", 0755, []byte("class1\nclass2\n"), zip.Store}
+ service1b = testZipEntry{"META-INF/services/service1", 0755, []byte("class1\nclass3\n"), zip.Deflate}
+ service1combined = testZipEntry{"META-INF/services/service1", 0755, []byte("class1\nclass2\nclass3\n"), zip.Store}
+ service2 = testZipEntry{"META-INF/services/service2", 0755, []byte("class1\nclass2\n"), zip.Deflate}
+
+ metainfDir = testZipEntry{jar.MetaDir, os.ModeDir | 0755, nil, zip.Deflate}
+ manifestFile = testZipEntry{jar.ManifestFile, 0755, []byte("manifest"), zip.Deflate}
+ manifestFile2 = testZipEntry{jar.ManifestFile, 0755, []byte("manifest2"), zip.Deflate}
+ moduleInfoFile = testZipEntry{jar.ModuleInfoClass, 0755, []byte("module-info"), zip.Deflate}
)
type testInputZip struct {
@@ -236,6 +243,15 @@
"in1": true,
},
},
+ {
+ name: "services",
+ in: [][]testZipEntry{
+ {service1a, service2},
+ {service1b},
+ },
+ jar: true,
+ out: []testZipEntry{service1combined, service2},
+ },
}
for _, test := range testCases {
@@ -256,7 +272,7 @@
closeErr := writer.Close()
if closeErr != nil {
- t.Fatal(err)
+ t.Fatal(closeErr)
}
if test.err != "" {
@@ -266,12 +282,16 @@
t.Fatal("incorrect err, want:", test.err, "got:", err)
}
return
+ } else if err != nil {
+ t.Fatal("unexpected err: ", err)
}
if !bytes.Equal(want, out.Bytes()) {
t.Error("incorrect zip output")
t.Errorf("want:\n%s", dumpZip(want))
t.Errorf("got:\n%s", dumpZip(out.Bytes()))
+ os.WriteFile("/tmp/got.zip", out.Bytes(), 0755)
+ os.WriteFile("/tmp/want.zip", want, 0755)
}
})
}
@@ -286,8 +306,14 @@
Name: e.name,
}
fh.SetMode(e.mode)
+ fh.Method = e.method
+ fh.UncompressedSize64 = uint64(len(e.data))
+ fh.CRC32 = crc32.ChecksumIEEE(e.data)
+ if fh.Method == zip.Store {
+ fh.CompressedSize64 = fh.UncompressedSize64
+ }
- w, err := zw.CreateHeader(&fh)
+ w, err := zw.CreateHeaderAndroid(&fh)
if err != nil {
panic(err)
}
diff --git a/genrule/allowlists.go b/genrule/allowlists.go
index c6fa030..afa52cc 100644
--- a/genrule/allowlists.go
+++ b/genrule/allowlists.go
@@ -116,6 +116,25 @@
"aidl_camera_build_version",
"cronet_aml_base_android_runtime_unchecked_jni_headers",
"cronet_aml_base_android_runtime_jni_headers",
+ "aidl-golden-test-build-hook-gen",
+ "PacketStreamerStub_h",
+ "FrontendStub_cc",
+ "FrontendStub_h",
+ "PacketStreamerStub_cc",
+ "pixelstatsatoms.h",
+ "pixelatoms_defs.h",
+ "pixelstatsatoms.cpp",
+ "hidl_java_impl_test_gen",
+ "cronet_aml_base_android_runtime_jni_headers__testing",
+ "cronet_aml_base_android_runtime_unchecked_jni_headers__testing",
+ "hidl_cpp_impl_test_gen-sources",
+ "fdt_test_tree_multiple_memory_ranges_dtb",
+ "fdt_test_tree_one_memory_range_dtb",
+ "fdt_test_tree_empty_memory_range_dtb",
+ "ltp_config_arm_64_lowmem",
+ "ltp_config_arm_64_lowmem_hwasan",
+ "ltp_config_x86",
+ "libbssl_sys_src_nostd",
}
SandboxingDenyPathList = []string{
diff --git a/jar/Android.bp b/jar/Android.bp
index 46113d8..c03e491 100644
--- a/jar/Android.bp
+++ b/jar/Android.bp
@@ -21,6 +21,7 @@
pkgPath: "android/soong/jar",
srcs: [
"jar.go",
+ "services.go",
],
testSrcs: [
"jar_test.go",
diff --git a/jar/services.go b/jar/services.go
new file mode 100644
index 0000000..d06a6dc
--- /dev/null
+++ b/jar/services.go
@@ -0,0 +1,128 @@
+// 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 jar
+
+import (
+ "android/soong/third_party/zip"
+ "bufio"
+ "hash/crc32"
+ "sort"
+ "strings"
+)
+
+const servicesPrefix = "META-INF/services/"
+
+// Services is used to collect service files from multiple zip files and produce a list of ServiceFiles containing
+// the unique lines from all the input zip entries with the same name.
+type Services struct {
+ services map[string]*ServiceFile
+}
+
+// ServiceFile contains the combined contents of all input zip entries with a single name.
+type ServiceFile struct {
+ Name string
+ FileHeader *zip.FileHeader
+ Contents []byte
+ Lines []string
+}
+
+// IsServiceFile returns true if the zip entry is in the META-INF/services/ directory.
+func (Services) IsServiceFile(entry *zip.File) bool {
+ return strings.HasPrefix(entry.Name, servicesPrefix)
+}
+
+// AddServiceFile adds a zip entry in the META-INF/services/ directory to the list of service files that need
+// to be combined.
+func (j *Services) AddServiceFile(entry *zip.File) error {
+ if j.services == nil {
+ j.services = map[string]*ServiceFile{}
+ }
+
+ service := entry.Name
+ serviceFile := j.services[service]
+ fh := entry.FileHeader
+ if serviceFile == nil {
+ serviceFile = &ServiceFile{
+ Name: service,
+ FileHeader: &fh,
+ }
+ j.services[service] = serviceFile
+ }
+
+ f, err := entry.Open()
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ scanner := bufio.NewScanner(f)
+ for scanner.Scan() {
+ line := scanner.Text()
+ if line != "" {
+ serviceFile.Lines = append(serviceFile.Lines, line)
+ }
+ }
+
+ if err := scanner.Err(); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// ServiceFiles returns the list of combined service files, each containing all the unique lines from the
+// corresponding service files in the input zip entries.
+func (j *Services) ServiceFiles() []ServiceFile {
+ services := make([]ServiceFile, 0, len(j.services))
+
+ for _, serviceFile := range j.services {
+ serviceFile.Lines = dedupServicesLines(serviceFile.Lines)
+ serviceFile.Lines = append(serviceFile.Lines, "")
+ serviceFile.Contents = []byte(strings.Join(serviceFile.Lines, "\n"))
+
+ serviceFile.FileHeader.UncompressedSize64 = uint64(len(serviceFile.Contents))
+ serviceFile.FileHeader.CRC32 = crc32.ChecksumIEEE(serviceFile.Contents)
+ if serviceFile.FileHeader.Method == zip.Store {
+ serviceFile.FileHeader.CompressedSize64 = serviceFile.FileHeader.UncompressedSize64
+ }
+
+ services = append(services, *serviceFile)
+ }
+
+ sort.Slice(services, func(i, j int) bool {
+ return services[i].Name < services[j].Name
+ })
+
+ return services
+}
+
+func dedupServicesLines(in []string) []string {
+ writeIndex := 0
+outer:
+ for readIndex := 0; readIndex < len(in); readIndex++ {
+ for compareIndex := 0; compareIndex < writeIndex; compareIndex++ {
+ if interface{}(in[readIndex]) == interface{}(in[compareIndex]) {
+ // The value at readIndex already exists somewhere in the output region
+ // of the slice before writeIndex, skip it.
+ continue outer
+ }
+ }
+ if readIndex != writeIndex {
+ in[writeIndex] = in[readIndex]
+ }
+ writeIndex++
+ }
+ return in[0:writeIndex]
+}
diff --git a/java/androidmk.go b/java/androidmk.go
index 4fca08d..36271dd 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -346,6 +346,9 @@
// App module names can be overridden.
entries.SetString("LOCAL_MODULE", app.installApkName)
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", app.appProperties.PreventInstall)
+ if app.headerJarFile != nil {
+ entries.SetPath("LOCAL_SOONG_HEADER_JAR", app.headerJarFile)
+ }
entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", app.exportPackage)
if app.dexJarFile.IsSet() {
entries.SetPath("LOCAL_SOONG_DEX_JAR", app.dexJarFile.Path())
diff --git a/java/base.go b/java/base.go
index 6a532da..2293f64 100644
--- a/java/base.go
+++ b/java/base.go
@@ -1485,7 +1485,13 @@
j.implementationJarFile = outputFile
if j.headerJarFile == nil {
- j.headerJarFile = j.implementationJarFile
+ // If this module couldn't generate a header jar (for example due to api generating annotation processors)
+ // then use the implementation jar. Run it through zip2zip first to remove any files in META-INF/services
+ // so that javac on modules that depend on this module don't pick up annotation processors (which may be
+ // missing their implementations) from META-INF/services/javax.annotation.processing.Processor.
+ headerJarFile := android.PathForModuleOut(ctx, "javac-header", jarName)
+ convertImplementationJarToHeaderJar(ctx, j.implementationJarFile, headerJarFile)
+ j.headerJarFile = headerJarFile
}
// enforce syntax check to jacoco filters for any build (http://b/183622051)
diff --git a/java/builder.go b/java/builder.go
index 94a6b84..afbd69e 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -271,6 +271,12 @@
Description: "Check zip alignment",
},
)
+
+ convertImplementationJarToHeaderJarRule = pctx.AndroidStaticRule("convertImplementationJarToHeaderJar",
+ blueprint.RuleParams{
+ Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} -x 'META-INF/services/**/*'`,
+ CommandDeps: []string{"${config.Zip2ZipCmd}"},
+ })
)
func init() {
@@ -633,6 +639,15 @@
})
}
+func convertImplementationJarToHeaderJar(ctx android.ModuleContext, implementationJarFile android.Path,
+ headerJarFile android.WritablePath) {
+ ctx.Build(pctx, android.BuildParams{
+ Rule: convertImplementationJarToHeaderJarRule,
+ Input: implementationJarFile,
+ Output: headerJarFile,
+ })
+}
+
func TransformJarJar(ctx android.ModuleContext, outputFile android.WritablePath,
classesJar android.Path, rulesFile android.Path) {
ctx.Build(pctx, android.BuildParams{
diff --git a/java/device_host_converter_test.go b/java/device_host_converter_test.go
index 3c9a0f3..3413da0 100644
--- a/java/device_host_converter_test.go
+++ b/java/device_host_converter_test.go
@@ -135,6 +135,7 @@
hostModule := ctx.ModuleForTests("host_module", config.BuildOSCommonTarget.String())
hostJavac := hostModule.Output("javac/host_module.jar")
+ hostJavacHeader := hostModule.Output("javac-header/host_module.jar")
hostRes := hostModule.Output("res/host_module.jar")
hostImportModule := ctx.ModuleForTests("host_import_module", config.BuildOSCommonTarget.String())
@@ -148,7 +149,7 @@
// check classpath of device module with dependency on host_for_device_module
expectedClasspath := "-classpath " + strings.Join(android.Paths{
- hostJavac.Output,
+ hostJavacHeader.Output,
hostImportCombined.Output,
}.Strings(), ":")
diff --git a/java/fuzz_test.go b/java/fuzz_test.go
index dd1e96b..f29c913 100644
--- a/java/fuzz_test.go
+++ b/java/fuzz_test.go
@@ -71,8 +71,8 @@
}
baz := result.ModuleForTests("baz", osCommonTarget).Rule("javac").Output.String()
- barOut := filepath.Join("out", "soong", ".intermediates", "bar", osCommonTarget, "javac", "bar.jar")
- bazOut := filepath.Join("out", "soong", ".intermediates", "baz", osCommonTarget, "javac", "baz.jar")
+ barOut := filepath.Join("out", "soong", ".intermediates", "bar", osCommonTarget, "javac-header", "bar.jar")
+ bazOut := filepath.Join("out", "soong", ".intermediates", "baz", osCommonTarget, "javac-header", "baz.jar")
android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], barOut)
android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], bazOut)
diff --git a/java/java.go b/java/java.go
index ee20698..20d9afc 100644
--- a/java/java.go
+++ b/java/java.go
@@ -3165,6 +3165,7 @@
type javaTestHostAttributes struct {
*javaCommonAttributes
+ Srcs bazel.LabelListAttribute
Deps bazel.LabelListAttribute
Runtime_deps bazel.LabelListAttribute
}
@@ -3201,8 +3202,10 @@
hasKotlin: bp2BuildInfo.hasKotlin,
}
libName := createLibraryTarget(ctx, libInfo)
- attrs.Runtime_deps.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + libName}})
+ attrs.Srcs = commonAttrs.Srcs
+ attrs.Deps = deps
+ attrs.Runtime_deps.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + libName}})
// Create the BazelTargetModule.
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
}
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index c018671..680494f 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -160,7 +160,7 @@
}
`),
checkAllCopyRules(`
-.intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/myjavalib.jar
+.intermediates/myjavalib/linux_glibc_common/javac-header/myjavalib.jar -> java/myjavalib.jar
aidl/foo/bar/Test.aidl -> aidl/aidl/foo/bar/Test.aidl
`),
)
@@ -206,7 +206,7 @@
`),
checkAllCopyRules(`
.intermediates/myjavalib/android_common/turbine-combined/myjavalib.jar -> java/android/myjavalib.jar
-.intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/linux_glibc/myjavalib.jar
+.intermediates/myjavalib/linux_glibc_common/javac-header/myjavalib.jar -> java/linux_glibc/myjavalib.jar
`),
)
}
@@ -799,7 +799,7 @@
libs: ["mysdk_system-module"],
}
`),
- checkAllCopyRules(".intermediates/system-module/linux_glibc_common/javac/system-module.jar -> java/system-module.jar"),
+ checkAllCopyRules(".intermediates/system-module/linux_glibc_common/javac-header/system-module.jar -> java/system-module.jar"),
)
}
@@ -879,7 +879,7 @@
}
`),
checkAllCopyRules(`
-.intermediates/hostjavalib/linux_glibc_common/javac/hostjavalib.jar -> java/hostjavalib.jar
+.intermediates/hostjavalib/linux_glibc_common/javac-header/hostjavalib.jar -> java/hostjavalib.jar
.intermediates/androidjavalib/android_common/turbine-combined/androidjavalib.jar -> java/androidjavalib.jar
.intermediates/myjavalib/android_common/javac/myjavalib.jar -> java/android/myjavalib.jar
.intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/linux_glibc/myjavalib.jar
diff --git a/third_party/zip/android.go b/third_party/zip/android.go
index f8e45c5..0f41f62 100644
--- a/third_party/zip/android.go
+++ b/third_party/zip/android.go
@@ -170,7 +170,7 @@
func (w *Writer) CreateHeaderAndroid(fh *FileHeader) (io.Writer, error) {
writeDataDescriptor := fh.Method != Store
if writeDataDescriptor {
- fh.Flags &= DataDescriptorFlag
+ fh.Flags |= DataDescriptorFlag
} else {
fh.Flags &= ^uint16(DataDescriptorFlag)
}