Merge "Add protobuf definition for METADATA files."
diff --git a/apex/apex.go b/apex/apex.go
index 6afbd4a..edba1f7 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -3415,7 +3415,12 @@
Native_shared_libs_32: bazel.LabelListAttribute{},
Native_shared_libs_64: bazel.LabelListAttribute{},
}
- compileMultilib := "both"
+
+ // https://cs.android.com/android/platform/superproject/+/master:build/soong/android/arch.go;l=698;drc=f05b0d35d2fbe51be9961ce8ce8031f840295c68
+ // https://cs.android.com/android/platform/superproject/+/master:build/soong/apex/apex.go;l=2549;drc=ec731a83e3e2d80a1254e32fd4ad7ef85e262669
+ // In Soong, decodeMultilib, used to get multilib, return "first" if defaultMultilib is set to "common".
+ // Since apex sets defaultMultilib to be "common", equivalent compileMultilib in bp2build for apex should be "first"
+ compileMultilib := "first"
if a.CompileMultilib() != nil {
compileMultilib = *a.CompileMultilib()
}
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 647a575..2e116c7 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -4130,6 +4130,76 @@
ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n")
}
+func TestCompileMultilibProp(t *testing.T) {
+ testCases := []struct {
+ compileMultiLibProp string
+ containedLibs []string
+ notContainedLibs []string
+ }{
+ {
+ containedLibs: []string{
+ "image.apex/lib64/mylib.so",
+ "image.apex/lib/mylib.so",
+ },
+ compileMultiLibProp: `compile_multilib: "both",`,
+ },
+ {
+ containedLibs: []string{"image.apex/lib64/mylib.so"},
+ notContainedLibs: []string{"image.apex/lib/mylib.so"},
+ compileMultiLibProp: `compile_multilib: "first",`,
+ },
+ {
+ containedLibs: []string{"image.apex/lib64/mylib.so"},
+ notContainedLibs: []string{"image.apex/lib/mylib.so"},
+ // compile_multilib, when unset, should result to the same output as when compile_multilib is "first"
+ },
+ {
+ containedLibs: []string{"image.apex/lib64/mylib.so"},
+ notContainedLibs: []string{"image.apex/lib/mylib.so"},
+ compileMultiLibProp: `compile_multilib: "64",`,
+ },
+ {
+ containedLibs: []string{"image.apex/lib/mylib.so"},
+ notContainedLibs: []string{"image.apex/lib64/mylib.so"},
+ compileMultiLibProp: `compile_multilib: "32",`,
+ },
+ }
+ for _, testCase := range testCases {
+ ctx := testApex(t, fmt.Sprintf(`
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ %s
+ native_shared_libs: ["mylib"],
+ updatable: false,
+ }
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+ cc_library {
+ name: "mylib",
+ srcs: ["mylib.cpp"],
+ apex_available: [
+ "//apex_available:platform",
+ "myapex",
+ ],
+ }
+ `, testCase.compileMultiLibProp),
+ )
+ module := ctx.ModuleForTests("myapex", "android_common_myapex_image")
+ apexRule := module.Rule("apexRule")
+ copyCmds := apexRule.Args["copy_commands"]
+ for _, containedLib := range testCase.containedLibs {
+ ensureContains(t, copyCmds, containedLib)
+ }
+ for _, notContainedLib := range testCase.notContainedLibs {
+ ensureNotContains(t, copyCmds, notContainedLib)
+ }
+ }
+}
+
func TestNonTestApex(t *testing.T) {
ctx := testApex(t, `
apex {
diff --git a/bazel/cquery/request_type.go b/bazel/cquery/request_type.go
index fcc2f07..fa73fb2 100644
--- a/bazel/cquery/request_type.go
+++ b/bazel/cquery/request_type.go
@@ -186,13 +186,8 @@
// Starlark given in StarlarkFunctionBody.
func (g getCcInfoType) ParseResult(rawString string) (CcInfo, error) {
var ccInfo CcInfo
- decoder := json.NewDecoder(strings.NewReader(rawString))
- decoder.DisallowUnknownFields() //useful to detect typos, e.g. in unit tests
- err := decoder.Decode(&ccInfo)
- if err != nil {
- return ccInfo, fmt.Errorf("error parsing CcInfo result. %s RAW STRING: %s", err, rawString)
- }
- return ccInfo, err
+ parseJson(rawString, &ccInfo)
+ return ccInfo, nil
}
// Query Bazel for the artifacts generated by the apex modules.
@@ -237,11 +232,7 @@
// Starlark given in StarlarkFunctionBody.
func (g getApexInfoType) ParseResult(rawString string) ApexCqueryInfo {
var info ApexCqueryInfo
- decoder := json.NewDecoder(strings.NewReader(rawString))
- decoder.DisallowUnknownFields() //useful to detect typos, e.g. in unit tests
- if err := decoder.Decode(&info); err != nil {
- panic(fmt.Errorf("cannot parse cquery result '%s': %s", rawString, err))
- }
+ parseJson(rawString, &info)
return info
}
@@ -273,11 +264,7 @@
// Starlark given in StarlarkFunctionBody.
func (g getCcUnstippedInfoType) ParseResult(rawString string) CcUnstrippedInfo {
var info CcUnstrippedInfo
- decoder := json.NewDecoder(strings.NewReader(rawString))
- decoder.DisallowUnknownFields() //useful to detect typos, e.g. in unit tests
- if err := decoder.Decode(&info); err != nil {
- panic(fmt.Errorf("cannot parse cquery result '%s': %s", rawString, err))
- }
+ parseJson(rawString, &info)
return info
}
@@ -295,3 +282,13 @@
return strings.Split(s, sep)
}
}
+
+// parseJson decodes json string into the fields of the receiver.
+// Unknown attribute name causes panic.
+func parseJson(jsonString string, info interface{}) {
+ decoder := json.NewDecoder(strings.NewReader(jsonString))
+ decoder.DisallowUnknownFields() //useful to detect typos, e.g. in unit tests
+ if err := decoder.Decode(info); err != nil {
+ panic(fmt.Errorf("cannot parse cquery result '%s': %s", jsonString, err))
+ }
+}
diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go
index 4fd6e43..a666e49 100644
--- a/bp2build/apex_conversion_test.go
+++ b/bp2build/apex_conversion_test.go
@@ -22,6 +22,7 @@
"android/soong/java"
"android/soong/sh"
+ "fmt"
"testing"
)
@@ -153,10 +154,17 @@
"key": `":com.android.apogee.key"`,
"manifest": `"apogee_manifest.json"`,
"min_sdk_version": `"29"`,
- "native_shared_libs_32": `[
- ":native_shared_lib_1",
- ":native_shared_lib_2",
- ]`,
+ "native_shared_libs_32": `select({
+ "//build/bazel/platforms/arch:arm": [
+ ":native_shared_lib_1",
+ ":native_shared_lib_2",
+ ],
+ "//build/bazel/platforms/arch:x86": [
+ ":native_shared_lib_1",
+ ":native_shared_lib_2",
+ ],
+ "//conditions:default": [],
+ })`,
"native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [
":native_shared_lib_1",
@@ -273,10 +281,11 @@
}
`,
},
- Blueprint: createMultilibBlueprint("both"),
+ Blueprint: createMultilibBlueprint(`compile_multilib: "both",`),
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
"native_shared_libs_32": `[
+ ":unnested_native_shared_lib",
":native_shared_lib_for_both",
":native_shared_lib_for_lib32",
] + select({
@@ -286,11 +295,13 @@
})`,
"native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [
+ ":unnested_native_shared_lib",
":native_shared_lib_for_both",
":native_shared_lib_for_lib64",
":native_shared_lib_for_first",
],
"//build/bazel/platforms/arch:x86_64": [
+ ":unnested_native_shared_lib",
":native_shared_lib_for_both",
":native_shared_lib_for_lib64",
":native_shared_lib_for_first",
@@ -303,53 +314,69 @@
}})
}
-func TestApexBundleCompileMultilibFirst(t *testing.T) {
- runApexTestCase(t, Bp2buildTestCase{
- Description: "apex - example with compile_multilib=first",
- ModuleTypeUnderTest: "apex",
- ModuleTypeUnderTestFactory: apex.BundleFactory,
- Filesystem: map[string]string{
- "system/sepolicy/apex/Android.bp": `
-filegroup {
- name: "com.android.apogee-file_contexts",
- srcs: [ "apogee-file_contexts", ],
- bazel_module: { bp2build_available: false },
-}
-`,
- },
- Blueprint: createMultilibBlueprint("first"),
- ExpectedBazelTargets: []string{
- MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
- "native_shared_libs_32": `select({
+func TestApexBundleCompileMultilibFirstAndDefaultValue(t *testing.T) {
+ expectedBazelTargets := []string{
+ MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
+ "native_shared_libs_32": `select({
"//build/bazel/platforms/arch:arm": [
+ ":unnested_native_shared_lib",
":native_shared_lib_for_both",
":native_shared_lib_for_lib32",
":native_shared_lib_for_first",
],
"//build/bazel/platforms/arch:x86": [
+ ":unnested_native_shared_lib",
":native_shared_lib_for_both",
":native_shared_lib_for_lib32",
":native_shared_lib_for_first",
],
"//conditions:default": [],
})`,
- "native_shared_libs_64": `select({
+ "native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [
+ ":unnested_native_shared_lib",
":native_shared_lib_for_both",
":native_shared_lib_for_lib64",
":native_shared_lib_for_first",
],
"//build/bazel/platforms/arch:x86_64": [
+ ":unnested_native_shared_lib",
":native_shared_lib_for_both",
":native_shared_lib_for_lib64",
":native_shared_lib_for_first",
],
"//conditions:default": [],
})`,
- "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
- "manifest": `"apex_manifest.json"`,
- }),
- }})
+ "file_contexts": `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
+ "manifest": `"apex_manifest.json"`,
+ }),
+ }
+
+ // "first" is the default value of compile_multilib prop so `compile_multilib_: "first"` and unset compile_multilib
+ // should result to the same bp2build output
+ compileMultiLibPropValues := []string{`compile_multilib: "first",`, ""}
+ for _, compileMultiLibProp := range compileMultiLibPropValues {
+ descriptionSuffix := compileMultiLibProp
+ if descriptionSuffix == "" {
+ descriptionSuffix = "compile_multilib unset"
+ }
+ runApexTestCase(t, Bp2buildTestCase{
+ Description: "apex - example with " + compileMultiLibProp,
+ ModuleTypeUnderTest: "apex",
+ ModuleTypeUnderTestFactory: apex.BundleFactory,
+ Filesystem: map[string]string{
+ "system/sepolicy/apex/Android.bp": `
+ filegroup {
+ name: "com.android.apogee-file_contexts",
+ srcs: [ "apogee-file_contexts", ],
+ bazel_module: { bp2build_available: false },
+ }
+ `,
+ },
+ Blueprint: createMultilibBlueprint(compileMultiLibProp),
+ ExpectedBazelTargets: expectedBazelTargets,
+ })
+ }
}
func TestApexBundleCompileMultilib32(t *testing.T) {
@@ -366,10 +393,11 @@
}
`,
},
- Blueprint: createMultilibBlueprint("32"),
+ Blueprint: createMultilibBlueprint(`compile_multilib: "32",`),
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
"native_shared_libs_32": `[
+ ":unnested_native_shared_lib",
":native_shared_lib_for_both",
":native_shared_lib_for_lib32",
] + select({
@@ -397,16 +425,18 @@
}
`,
},
- Blueprint: createMultilibBlueprint("64"),
+ Blueprint: createMultilibBlueprint(`compile_multilib: "64",`),
ExpectedBazelTargets: []string{
MakeBazelTarget("apex", "com.android.apogee", AttrNameToString{
"native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [
+ ":unnested_native_shared_lib",
":native_shared_lib_for_both",
":native_shared_lib_for_lib64",
":native_shared_lib_for_first",
],
"//build/bazel/platforms/arch:x86_64": [
+ ":unnested_native_shared_lib",
":native_shared_lib_for_both",
":native_shared_lib_for_lib64",
":native_shared_lib_for_first",
@@ -420,7 +450,7 @@
}
func createMultilibBlueprint(compile_multilib string) string {
- return `
+ return fmt.Sprintf(`
cc_library {
name: "native_shared_lib_for_both",
bazel_module: { bp2build_available: false },
@@ -441,9 +471,15 @@
bazel_module: { bp2build_available: false },
}
+cc_library {
+ name: "unnested_native_shared_lib",
+ bazel_module: { bp2build_available: false },
+}
+
apex {
name: "com.android.apogee",
- compile_multilib: "` + compile_multilib + `",
+ %s
+ native_shared_libs: ["unnested_native_shared_lib"],
multilib: {
both: {
native_shared_libs: [
@@ -466,7 +502,7 @@
],
},
},
-}`
+}`, compile_multilib)
}
func TestApexBundleDefaultPropertyValues(t *testing.T) {
@@ -636,10 +672,17 @@
"key": `":com.google.android.apogee.key"`,
"manifest": `"apogee_manifest.json"`,
"min_sdk_version": `"29"`,
- "native_shared_libs_32": `[
- ":native_shared_lib_1",
- ":native_shared_lib_2",
- ]`,
+ "native_shared_libs_32": `select({
+ "//build/bazel/platforms/arch:arm": [
+ ":native_shared_lib_1",
+ ":native_shared_lib_2",
+ ],
+ "//build/bazel/platforms/arch:x86": [
+ ":native_shared_lib_1",
+ ":native_shared_lib_2",
+ ],
+ "//conditions:default": [],
+ })`,
"native_shared_libs_64": `select({
"//build/bazel/platforms/arch:arm64": [
":native_shared_lib_1",
diff --git a/cc/config/tidy.go b/cc/config/tidy.go
index af49e88..8b5289d 100644
--- a/cc/config/tidy.go
+++ b/cc/config/tidy.go
@@ -58,17 +58,14 @@
)
func init() {
- // Many clang-tidy checks like altera-*, llvm-*, modernize-*
- // are not designed for Android source code or creating too
- // many (false-positive) warnings. The global default tidy checks
- // should include only tested groups and exclude known noisy checks.
+ // The global default tidy checks should include clang-tidy
+ // default checks and tested groups, but exclude known noisy checks.
// See https://clang.llvm.org/extra/clang-tidy/checks/list.html
pctx.VariableFunc("TidyDefaultGlobalChecks", func(ctx android.PackageVarContext) string {
if override := ctx.Config().Getenv("DEFAULT_GLOBAL_TIDY_CHECKS"); override != "" {
return override
}
checks := strings.Join([]string{
- "-*",
"android-*",
"bugprone-*",
"cert-*",
@@ -95,7 +92,7 @@
"-misc-non-private-member-variables-in-classes",
"-misc-unused-parameters",
"-performance-no-int-to-ptr",
- // the following groups are excluded by -*
+ // the following groups are not in clang-tidy default checks.
// -altera-*
// -cppcoreguidelines-*
// -darwin-*
@@ -109,28 +106,34 @@
// -readability-*
// -zircon-*
}, ",")
- // clang-analyzer-* checks are too slow to be in the default for WITH_TIDY=1.
- // nightly builds add CLANG_ANALYZER_CHECKS=1 to run those checks.
+ // clang-analyzer-* checks are slow for large files, but we have TIDY_TIMEOUT to
+ // limit clang-tidy runtime. We allow clang-tidy default clang-analyzer-* checks,
+ // and add it explicitly when CLANG_ANALYZER_CHECKS is set.
// The insecureAPI.DeprecatedOrUnsafeBufferHandling warning does not apply to Android.
if ctx.Config().IsEnvTrue("CLANG_ANALYZER_CHECKS") {
checks += ",clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
+ } else {
+ checks += ",-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
}
return checks
})
- // There are too many clang-tidy warnings in external and vendor projects.
- // Enable only some google checks for these projects.
+ // The external and vendor projects do not run clang-tidy unless TIDY_EXTERNAL_VENDOR is set.
+ // We do not add "-*" to the check list to avoid suppressing the check list in .clang-tidy config files.
+ // There are too many clang-tidy warnings in external and vendor projects, so we only
+ // enable some google checks for these projects. Users can add more checks locally with the
+ // "tidy_checks" list in .bp files, or the "Checks" list in .clang-tidy config files.
pctx.VariableFunc("TidyExternalVendorChecks", func(ctx android.PackageVarContext) string {
if override := ctx.Config().Getenv("DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS"); override != "" {
return override
}
return strings.Join([]string{
- "-*",
"clang-diagnostic-unused-command-line-argument",
"google-build-explicit-make-pair",
"google-build-namespaces",
"google-runtime-operator",
"google-upgrade-*",
+ "-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling",
}, ",")
})
diff --git a/cc/stl.go b/cc/stl.go
index 85a06da..6353a4a 100644
--- a/cc/stl.go
+++ b/cc/stl.go
@@ -139,6 +139,8 @@
return "libunwind"
}
+// Should be kept up to date with
+// https://cs.android.com/android/platform/superproject/+/master:build/bazel/rules/cc/stl.bzl;l=46;drc=21771b671ae08565033768a6d3d151c54f887fa2
func (stl *stl) deps(ctx BaseModuleContext, deps Deps) Deps {
switch stl.Properties.SelectedStl {
case "libstdc++":
@@ -194,6 +196,8 @@
return deps
}
+// Should be kept up to date with
+// https://cs.android.com/android/platform/superproject/+/master:build/bazel/rules/cc/stl.bzl;l=94;drc=5bc8e39d2637927dc57dd0850210d43d348a1341
func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
switch stl.Properties.SelectedStl {
case "libc++", "libc++_static":
diff --git a/java/base.go b/java/base.go
index ab5a7d9..96f36e8 100644
--- a/java/base.go
+++ b/java/base.go
@@ -190,7 +190,7 @@
// constructing a new module.
type DeviceProperties struct {
// If not blank, set to the version of the sdk to compile against.
- // Defaults to private.
+ // Defaults to an empty string, which compiles the module against the private platform APIs.
// Values are of one of the following forms:
// 1) numerical API level, "current", "none", or "core_platform"
// 2) An SDK kind with an API level: "<sdk kind>_<API level>"
diff --git a/java/config/config.go b/java/config/config.go
index a84c315..45b668b 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -83,7 +83,7 @@
// ErrorProne can use significantly more memory than javac alone, give it a higher heap
// size (b/221480398).
- exportedVars.ExportStringStaticVariable("ErrorProneHeapSize", "4096M")
+ exportedVars.ExportStringStaticVariable("ErrorProneHeapSize", "8192M")
exportedVars.ExportStringStaticVariable("ErrorProneHeapFlags", "-J-Xmx${ErrorProneHeapSize}")
// D8 invocations are shorter lived, so we restrict their JIT tiering relative to R8.
@@ -124,10 +124,6 @@
// This is set up and guaranteed by soong_ui
return ctx.Config().Getenv("ANDROID_JAVA_HOME")
})
- pctx.VariableFunc("Java11Home", func(ctx android.PackageVarContext) string {
- // This is set up and guaranteed by soong_ui
- return ctx.Config().Getenv("ANDROID_JAVA11_HOME")
- })
pctx.VariableFunc("JlinkVersion", func(ctx android.PackageVarContext) string {
if override := ctx.Config().Getenv("OVERRIDE_JLINK_VERSION_NUMBER"); override != "" {
return override
@@ -136,12 +132,11 @@
})
pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin")
- pctx.SourcePathVariable("Java11Toolchain", "${Java11Home}/bin")
pctx.SourcePathVariableWithEnvOverride("JavacCmd",
"${JavaToolchain}/javac", "ALTERNATE_JAVAC")
pctx.SourcePathVariable("JavaCmd", "${JavaToolchain}/java")
pctx.SourcePathVariable("JarCmd", "${JavaToolchain}/jar")
- pctx.SourcePathVariable("JavadocCmd", "${Java11Toolchain}/javadoc")
+ pctx.SourcePathVariable("JavadocCmd", "${JavaToolchain}/javadoc")
pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink")
pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod")
pctx.SourcePathVariable("JrtFsJar", "${JavaHome}/lib/jrt-fs.jar")
@@ -268,7 +263,7 @@
// JavadocCmd returns a SourcePath object with the path to the java command.
func JavadocCmd(ctx android.PathContext) android.SourcePath {
- return java11Tool(ctx, "javadoc")
+ return javaTool(ctx, "javadoc")
}
func javaTool(ctx android.PathContext, tool string) android.SourcePath {
@@ -282,17 +277,6 @@
}
-func java11Tool(ctx android.PathContext, tool string) android.SourcePath {
- type javaToolKey string
-
- key := android.NewCustomOnceKey(javaToolKey(tool))
-
- return ctx.Config().OnceSourcePath(key, func() android.SourcePath {
- return java11Toolchain(ctx).Join(ctx, tool)
- })
-
-}
-
var javaToolchainKey = android.NewOnceKey("javaToolchain")
func javaToolchain(ctx android.PathContext) android.SourcePath {
@@ -301,14 +285,6 @@
})
}
-var java11ToolchainKey = android.NewOnceKey("java11Toolchain")
-
-func java11Toolchain(ctx android.PathContext) android.SourcePath {
- return ctx.Config().OnceSourcePath(java11ToolchainKey, func() android.SourcePath {
- return java11Home(ctx).Join(ctx, "bin")
- })
-}
-
var javaHomeKey = android.NewOnceKey("javaHome")
func javaHome(ctx android.PathContext) android.SourcePath {
@@ -317,12 +293,3 @@
return android.PathForSource(ctx, ctx.Config().Getenv("ANDROID_JAVA_HOME"))
})
}
-
-var java11HomeKey = android.NewOnceKey("java11Home")
-
-func java11Home(ctx android.PathContext) android.SourcePath {
- return ctx.Config().OnceSourcePath(java11HomeKey, func() android.SourcePath {
- // This is set up and guaranteed by soong_ui
- return android.PathForSource(ctx, ctx.Config().Getenv("ANDROID_JAVA11_HOME"))
- })
-}