diff options
-rw-r--r-- | android/apex.go | 9 | ||||
-rw-r--r-- | android/arch.go | 2 | ||||
-rw-r--r-- | android/arch_list.go | 1 | ||||
-rw-r--r-- | android/config.go | 14 | ||||
-rw-r--r-- | android/paths.go | 19 | ||||
-rw-r--r-- | android/util.go | 10 | ||||
-rw-r--r-- | android/variable.go | 4 | ||||
-rw-r--r-- | apex/allowed_deps.txt | 8 | ||||
-rw-r--r-- | apex/apex.go | 4 | ||||
-rw-r--r-- | bp2build/Android.bp | 3 | ||||
-rw-r--r-- | bp2build/build_conversion_test.go | 39 | ||||
-rw-r--r-- | bp2build/cc_conversion_test.go | 221 | ||||
-rw-r--r-- | bp2build/sh_conversion_test.go | 134 | ||||
-rw-r--r-- | cc/config/arm64_device.go | 7 | ||||
-rw-r--r-- | cc/config/clang.go | 2 | ||||
-rw-r--r-- | cc/config/global.go | 4 | ||||
-rw-r--r-- | cc/config/tidy.go | 24 | ||||
-rw-r--r-- | cc/library.go | 4 | ||||
-rw-r--r-- | cc/library_headers.go | 90 | ||||
-rw-r--r-- | cc/tidy.go | 15 | ||||
-rw-r--r-- | etc/prebuilt_etc.go | 13 | ||||
-rw-r--r-- | filesystem/bootimg.go | 18 | ||||
-rw-r--r-- | java/hiddenapi.go | 28 | ||||
-rw-r--r-- | java/hiddenapi_singleton_test.go | 19 | ||||
-rw-r--r-- | java/java.go | 8 | ||||
-rw-r--r-- | rust/config/arm64_device.go | 7 | ||||
-rw-r--r-- | scripts/hiddenapi/Android.bp | 4 | ||||
-rwxr-xr-x | scripts/hiddenapi/merge_csv.py | 21 |
28 files changed, 638 insertions, 94 deletions
diff --git a/android/apex.go b/android/apex.go index 6bb0751d7..463794245 100644 --- a/android/apex.go +++ b/android/apex.go @@ -757,7 +757,6 @@ var minSdkVersionAllowlist = func(apiMap map[string]int) map[string]ApiLevel { "captiveportal-lib": 28, "flatbuffer_headers": 30, "framework-permission": 30, - "framework-statsd": 30, "gemmlowp_headers": 30, "ike-internals": 30, "kotlinx-coroutines-android": 28, @@ -790,11 +789,6 @@ var minSdkVersionAllowlist = func(apiMap map[string]int) map[string]ApiLevel { "libprotobuf-java-lite": 30, "libprotoutil": 30, "libqemu_pipe": 30, - "libstats_jni": 30, - "libstatslog_statsd": 30, - "libstatsmetadata": 30, - "libstatspull": 30, - "libstatssocket": 30, "libsync": 30, "libtextclassifier_hash_headers": 30, "libtextclassifier_hash_static": 30, @@ -807,9 +801,6 @@ var minSdkVersionAllowlist = func(apiMap map[string]int) map[string]ApiLevel { "philox_random_headers": 30, "philox_random": 30, "service-permission": 30, - "service-statsd": 30, - "statsd-aidl-ndk_platform": 30, - "statsd": 30, "tensorflow_headers": 30, "xz-java": 29, }) diff --git a/android/arch.go b/android/arch.go index b2773810b..2decea8a5 100644 --- a/android/arch.go +++ b/android/arch.go @@ -1442,7 +1442,7 @@ type archConfig struct { func getNdkAbisConfig() []archConfig { return []archConfig{ {"arm", "armv7-a", "", []string{"armeabi-v7a"}}, - {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, + {"arm64", "armv8-a-branchprot", "", []string{"arm64-v8a"}}, {"x86", "", "", []string{"x86"}}, {"x86_64", "", "", []string{"x86_64"}}, } diff --git a/android/arch_list.go b/android/arch_list.go index 0c33b9d34..d68a0d1d1 100644 --- a/android/arch_list.go +++ b/android/arch_list.go @@ -41,6 +41,7 @@ var archVariants = map[ArchType][]string{ }, Arm64: { "armv8_a", + "armv8_a_branchprot", "armv8_2a", "armv8-2a-dotprod", "cortex-a53", diff --git a/android/config.go b/android/config.go index 50e39d7e9..9162eaae7 100644 --- a/android/config.go +++ b/android/config.go @@ -24,6 +24,7 @@ import ( "os" "path/filepath" "runtime" + "strconv" "strings" "sync" @@ -246,6 +247,7 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string AAPTCharacteristics: stringPtr("nosdcard"), AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"}, UncompressPrivAppDex: boolPtr(true), + ShippingApiLevel: stringPtr("30"), }, buildDir: buildDir, @@ -1421,6 +1423,18 @@ func (c *deviceConfig) RecoverySnapshotModules() map[string]bool { return c.config.productVariables.RecoverySnapshotModules } +func (c *deviceConfig) ShippingApiLevel() ApiLevel { + if c.config.productVariables.ShippingApiLevel == nil { + return NoneApiLevel + } + apiLevel, _ := strconv.Atoi(*c.config.productVariables.ShippingApiLevel) + return uncheckedFinalApiLevel(apiLevel) +} + +func (c *deviceConfig) BuildBrokenVendorPropertyNamespace() bool { + return c.config.productVariables.BuildBrokenVendorPropertyNamespace +} + // The ConfiguredJarList struct provides methods for handling a list of (apex, jar) pairs. // Such lists are used in the build system for things like bootclasspath jars or system server jars. // The apex part is either an apex name, or a special names "platform" or "system_ext". Jar is a diff --git a/android/paths.go b/android/paths.go index c3fa61a09..58e1f746b 100644 --- a/android/paths.go +++ b/android/paths.go @@ -280,7 +280,8 @@ func (paths Paths) containsPath(path Path) bool { return false } -// PathsForSource returns Paths rooted from SrcDir +// PathsForSource returns Paths rooted from SrcDir, *not* rooted from the module's local source +// directory func PathsForSource(ctx PathContext, paths []string) Paths { ret := make(Paths, len(paths)) for i, path := range paths { @@ -289,9 +290,9 @@ func PathsForSource(ctx PathContext, paths []string) Paths { return ret } -// ExistentPathsForSources returns a list of Paths rooted from SrcDir that are -// found in the tree. If any are not found, they are omitted from the list, -// and dependencies are added so that we're re-run when they are added. +// ExistentPathsForSources returns a list of Paths rooted from SrcDir, *not* rooted from the +// module's local source directory, that are found in the tree. If any are not found, they are +// omitted from the list, and dependencies are added so that we're re-run when they are added. func ExistentPathsForSources(ctx PathContext, paths []string) Paths { ret := make(Paths, 0, len(paths)) for _, path := range paths { @@ -395,6 +396,9 @@ func BazelLabelForModuleSrcExcludes(ctx BazelConversionPathContext, paths, exclu // `android:"path"` so that dependencies on other modules will have already been handled by the // path_properties mutator. func expandSrcsForBazel(ctx BazelConversionPathContext, paths, expandedExcludes []string) bazel.LabelList { + if paths == nil { + return bazel.LabelList{} + } labels := bazel.LabelList{ Includes: []bazel.Label{}, } @@ -1024,9 +1028,10 @@ func PathForSource(ctx PathContext, pathComponents ...string) SourcePath { return path } -// ExistentPathForSource returns an OptionalPath with the SourcePath if the -// path exists, or an empty OptionalPath if it doesn't exist. Dependencies are added -// so that the ninja file will be regenerated if the state of the path changes. +// ExistentPathForSource returns an OptionalPath with the SourcePath, rooted from SrcDir, *not* +// rooted from the module's local source directory, if the path exists, or an empty OptionalPath if +// it doesn't exist. Dependencies are added so that the ninja file will be regenerated if the state +// of the path changes. func ExistentPathForSource(ctx PathContext, pathComponents ...string) OptionalPath { path, err := pathForSource(ctx, pathComponents...) if err != nil { diff --git a/android/util.go b/android/util.go index 0f940fa40..506f8f7b7 100644 --- a/android/util.go +++ b/android/util.go @@ -137,6 +137,16 @@ func HasAnyPrefix(s string, prefixList []string) bool { return false } +// Returns true if any string in the given list has the given substring. +func SubstringInList(list []string, substr string) bool { + for _, s := range list { + if strings.Contains(s, substr) { + return true + } + } + return false +} + // Returns true if any string in the given list has the given prefix. func PrefixInList(list []string, prefix string) bool { for _, s := range list { diff --git a/android/variable.go b/android/variable.go index e76d68397..76666c57f 100644 --- a/android/variable.go +++ b/android/variable.go @@ -367,6 +367,10 @@ type productVariables struct { BoardMoveRecoveryResourcesToVendorBoot *bool `json:",omitempty"` PrebuiltHiddenApiDir *string `json:",omitempty"` + + ShippingApiLevel *string `json:",omitempty"` + + BuildBrokenVendorPropertyNamespace bool `json:",omitempty"` } func boolPtr(v bool) *bool { diff --git a/apex/allowed_deps.txt b/apex/allowed_deps.txt index aee3fc496..add0e1ed7 100644 --- a/apex/allowed_deps.txt +++ b/apex/allowed_deps.txt @@ -182,6 +182,7 @@ framework-permission-s(minSdkVersion:30) framework-permission-s-shared(minSdkVersion:30) framework-sdkextensions(minSdkVersion:30) framework-sdkextensions(minSdkVersion:current) +framework-statsd(minSdkVersion:30) framework-statsd(minSdkVersion:current) framework-tethering(minSdkVersion:30) framework-tethering(minSdkVersion:current) @@ -425,11 +426,15 @@ libstagefright_mp3dec_headers(minSdkVersion:29) libstagefright_mpeg2extractor(minSdkVersion:29) libstagefright_mpeg2support_nocrypto(minSdkVersion:29) libstats_jni(minSdkVersion:(no version)) +libstats_jni(minSdkVersion:30) libstatslog_resolv(minSdkVersion:29) libstatslog_statsd(minSdkVersion:(no version)) +libstatslog_statsd(minSdkVersion:30) libstatspull(minSdkVersion:(no version)) +libstatspull(minSdkVersion:30) libstatspush_compat(minSdkVersion:29) libstatssocket(minSdkVersion:(no version)) +libstatssocket(minSdkVersion:30) libstatssocket_headers(minSdkVersion:29) libstd(minSdkVersion:29) libsystem_headers(minSdkVersion:apex_inherit) @@ -592,6 +597,7 @@ service-media-s(minSdkVersion:29) service-permission(minSdkVersion:30) service-permission(minSdkVersion:current) service-permission-shared(minSdkVersion:30) +service-statsd(minSdkVersion:30) service-statsd(minSdkVersion:current) SettingsLibActionBarShadow(minSdkVersion:21) SettingsLibAppPreference(minSdkVersion:21) @@ -605,7 +611,9 @@ SettingsLibSettingsTheme(minSdkVersion:21) SettingsLibUtils(minSdkVersion:21) stats_proto(minSdkVersion:29) statsd(minSdkVersion:(no version)) +statsd(minSdkVersion:30) statsd-aidl-ndk_platform(minSdkVersion:(no version)) +statsd-aidl-ndk_platform(minSdkVersion:30) statsprotos(minSdkVersion:29) tensorflow_headers(minSdkVersion:(no version)) Tethering(minSdkVersion:30) diff --git a/apex/apex.go b/apex/apex.go index cfeac72a0..e06a96730 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -208,6 +208,9 @@ type ApexNativeDependencies struct { // List of native tests that are embedded inside this APEX. Tests []string + + // List of filesystem images that are embedded inside this APEX bundle. + Filesystems []string } type apexMultilibProperties struct { @@ -580,6 +583,7 @@ func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeM ctx.AddFarVariationDependencies(libVariations, jniLibTag, nativeModules.Jni_libs...) ctx.AddFarVariationDependencies(libVariations, sharedLibTag, nativeModules.Native_shared_libs...) ctx.AddFarVariationDependencies(rustLibVariations, sharedLibTag, nativeModules.Rust_dyn_libs...) + ctx.AddFarVariationDependencies(target.Variations(), fsTag, nativeModules.Filesystems...) } func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) { diff --git a/bp2build/Android.bp b/bp2build/Android.bp index fdac88dfd..ddde1b7fc 100644 --- a/bp2build/Android.bp +++ b/bp2build/Android.bp @@ -15,13 +15,16 @@ bootstrap_go_package { deps: [ "soong-android", "soong-bazel", + "soong-cc", "soong-genrule", "soong-sh", ], testSrcs: [ "build_conversion_test.go", "bzl_conversion_test.go", + "cc_conversion_test.go", "conversion_test.go", + "sh_conversion_test.go", "testing.go", ], pluginFor: [ diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go index df554a09a..422422b1f 100644 --- a/bp2build/build_conversion_test.go +++ b/bp2build/build_conversion_test.go @@ -17,7 +17,6 @@ package bp2build import ( "android/soong/android" "android/soong/genrule" - "android/soong/sh" "strings" "testing" ) @@ -358,12 +357,6 @@ load("//build/bazel/rules:java.bzl", "java_binary")`, ruleClass: "genrule", // Note: no bzlLoadLocation for native rules }, - BazelTarget{ - name: "sh_binary_target", - ruleClass: "sh_binary", - // Note: no bzlLoadLocation for native rules - // TODO(ruperts): Could open source the existing, experimental Starlark sh_ rules? - }, }, expectedLoadStatements: `load("//build/bazel/rules:cc.bzl", "cc_binary") load("//build/bazel/rules:java.bzl", "java_binary")`, @@ -476,6 +469,21 @@ genrule { dir string }{ { + description: "filegroup with does not specify srcs", + moduleTypeUnderTest: "filegroup", + moduleTypeUnderTestFactory: android.FileGroupFactory, + moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, + bp: `filegroup { + name: "fg_foo", + bazel_module: { bp2build_available: true }, +}`, + expectedBazelTargets: []string{ + `filegroup( + name = "fg_foo", +)`, + }, + }, + { description: "filegroup with no srcs", moduleTypeUnderTest: "filegroup", moduleTypeUnderTestFactory: android.FileGroupFactory, @@ -860,23 +868,6 @@ genrule { )`, }, }, - { - description: "sh_binary test", - moduleTypeUnderTest: "sh_binary", - moduleTypeUnderTestFactory: sh.ShBinaryFactory, - moduleTypeUnderTestBp2BuildMutator: sh.ShBinaryBp2Build, - bp: `sh_binary { - name: "foo", - src: "foo.sh", - bazel_module: { bp2build_available: true }, -}`, - expectedBazelTargets: []string{`sh_binary( - name = "foo", - srcs = [ - "foo.sh", - ], -)`}, - }, } dir := "." diff --git a/bp2build/cc_conversion_test.go b/bp2build/cc_conversion_test.go new file mode 100644 index 000000000..3cd37628f --- /dev/null +++ b/bp2build/cc_conversion_test.go @@ -0,0 +1,221 @@ +// Copyright 2021 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 bp2build + +import ( + "android/soong/android" + "android/soong/cc" + "strings" + "testing" +) + +const ( + // See cc/testing.go for more context + soongCcLibraryPreamble = ` +cc_defaults { + name: "linux_bionic_supported", +} + +toolchain_library { + name: "libclang_rt.builtins-x86_64-android", + defaults: ["linux_bionic_supported"], + vendor_available: true, + vendor_ramdisk_available: true, + product_available: true, + recovery_available: true, + native_bridge_supported: true, + src: "", +} + +toolchain_library { + name: "libatomic", + defaults: ["linux_bionic_supported"], + vendor_available: true, + vendor_ramdisk_available: true, + product_available: true, + recovery_available: true, + native_bridge_supported: true, + src: "", +}` +) + +func TestCcLibraryHeadersLoadStatement(t *testing.T) { + testCases := []struct { + bazelTargets BazelTargets + expectedLoadStatements string + }{ + { + bazelTargets: BazelTargets{ + BazelTarget{ + name: "cc_library_headers_target", + ruleClass: "cc_library_headers", + // Note: no bzlLoadLocation for native rules + }, + }, + expectedLoadStatements: ``, + }, + } + + for _, testCase := range testCases { + actual := testCase.bazelTargets.LoadStatements() + expected := testCase.expectedLoadStatements + if actual != expected { + t.Fatalf("Expected load statements to be %s, got %s", expected, actual) + } + } + +} + +func TestCcLibraryHeadersBp2Build(t *testing.T) { + testCases := []struct { + description string + moduleTypeUnderTest string + moduleTypeUnderTestFactory android.ModuleFactory + moduleTypeUnderTestBp2BuildMutator func(android.TopDownMutatorContext) + preArchMutators []android.RegisterMutatorFunc + depsMutators []android.RegisterMutatorFunc + bp string + expectedBazelTargets []string + filesystem map[string]string + dir string + }{ + { + description: "cc_library_headers test", + moduleTypeUnderTest: "cc_library_headers", + moduleTypeUnderTestFactory: cc.LibraryHeaderFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryHeadersBp2Build, + filesystem: map[string]string{ + "lib-1/lib1a.h": "", + "lib-1/lib1b.h": "", + "lib-2/lib2a.h": "", + "lib-2/lib2b.h": "", + "dir-1/dir1a.h": "", + "dir-1/dir1b.h": "", + "dir-2/dir2a.h": "", + "dir-2/dir2b.h": "", + }, + bp: soongCcLibraryPreamble + ` +cc_library_headers { + name: "lib-1", + export_include_dirs: ["lib-1"], + bazel_module: { bp2build_available: true }, +} + +cc_library_headers { + name: "lib-2", + export_include_dirs: ["lib-2"], + bazel_module: { bp2build_available: true }, +} + +cc_library_headers { + name: "foo_headers", + export_include_dirs: ["dir-1", "dir-2"], + header_libs: ["lib-1", "lib-2"], + export_header_lib_headers: ["lib-1", "lib-2"], + bazel_module: { bp2build_available: true }, +}`, + expectedBazelTargets: []string{`cc_library_headers( + name = "foo_headers", + deps = [ + ":lib-1", + ":lib-2", + ], + hdrs = [ + "dir-1/dir1a.h", + "dir-1/dir1b.h", + "dir-2/dir2a.h", + "dir-2/dir2b.h", + ], + includes = [ + "dir-1", + "dir-2", + ], +)`, `cc_library_headers( + name = "lib-1", + hdrs = [ + "lib-1/lib1a.h", + "lib-1/lib1b.h", + ], + includes = [ + "lib-1", + ], +)`, `cc_library_headers( + name = "lib-2", + hdrs = [ + "lib-2/lib2a.h", + "lib-2/lib2b.h", + ], + includes = [ + "lib-2", + ], +)`}, + }, + } + + dir := "." + for _, testCase := range testCases { + filesystem := make(map[string][]byte) + toParse := []string{ + "Android.bp", + } + for f, content := range testCase.filesystem { + if strings.HasSuffix(f, "Android.bp") { + toParse = append(toParse, f) + } + filesystem[f] = []byte(content) + } + config := android.TestConfig(buildDir, nil, testCase.bp, filesystem) + ctx := android.NewTestContext(config) + + cc.RegisterCCBuildComponents(ctx) + ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) + + ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) + for _, m := range testCase.depsMutators { + ctx.DepsBp2BuildMutators(m) + } + ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator) + ctx.RegisterForBazelConversion() + + _, errs := ctx.ParseFileList(dir, toParse) + if Errored(t, testCase.description, errs) { + continue + } + _, errs = ctx.ResolveDependencies(config) + if Errored(t, testCase.description, errs) { + continue + } + + checkDir := dir + if testCase.dir != "" { + checkDir = testCase.dir + } + bazelTargets := GenerateBazelTargets(ctx.Context.Context, Bp2Build)[checkDir] + if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount { + t.Errorf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount) + } else { + for i, target := range bazelTargets { + if w, g := testCase.expectedBazelTargets[i], target.content; w != g { + t.Errorf( + "%s: Expected generated Bazel target to be '%s', got '%s'", + testCase.description, + w, + g, + ) + } + } + } + } +} diff --git a/bp2build/sh_conversion_test.go b/bp2build/sh_conversion_test.go new file mode 100644 index 000000000..dcc75bd5c --- /dev/null +++ b/bp2build/sh_conversion_test.go @@ -0,0 +1,134 @@ +// Copyright 2021 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 bp2build + +import ( + "android/soong/android" + "android/soong/sh" + "strings" + "testing" +) + +func TestShBinaryLoadStatement(t *testing.T) { + testCases := []struct { + bazelTargets BazelTargets + expectedLoadStatements string + }{ + { + bazelTargets: BazelTargets{ + BazelTarget{ + name: "sh_binary_target", + ruleClass: "sh_binary", + // Note: no bzlLoadLocation for native rules + // TODO(ruperts): Could open source the existing, experimental Starlark sh_ rules? + }, + }, + expectedLoadStatements: ``, + }, + } + + for _, testCase := range testCases { + actual := testCase.bazelTargets.LoadStatements() + expected := testCase.expectedLoadStatements + if actual != expected { + t.Fatalf("Expected load statements to be %s, got %s", expected, actual) + } + } + +} + +func TestShBinaryBp2Build(t *testing.T) { + testCases := []struct { + description string + moduleTypeUnderTest string + moduleTypeUnderTestFactory android.ModuleFactory + moduleTypeUnderTestBp2BuildMutator func(android.TopDownMutatorContext) + preArchMutators []android.RegisterMutatorFunc + depsMutators []android.RegisterMutatorFunc + bp string + expectedBazelTargets []string + filesystem map[string]string + dir string + }{ + { + description: "sh_binary test", + moduleTypeUnderTest: "sh_binary", + moduleTypeUnderTestFactory: sh.ShBinaryFactory, + moduleTypeUnderTestBp2BuildMutator: sh.ShBinaryBp2Build, + bp: `sh_binary { + name: "foo", + src: "foo.sh", + bazel_module: { bp2build_available: true }, +}`, + expectedBazelTargets: []string{`sh_binary( + name = "foo", + srcs = [ + "foo.sh", + ], +)`}, + }, + } + + dir := "." + for _, testCase := range testCases { + filesystem := make(map[string][]byte) + toParse := []string{ + "Android.bp", + } + for f, content := range testCase.filesystem { + if strings.HasSuffix(f, "Android.bp") { + toParse = append(toParse, f) + } + filesystem[f] = []byte(content) + } + config := android.TestConfig(buildDir, nil, testCase.bp, filesystem) + ctx := android.NewTestContext(config) + ctx.RegisterModuleType(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestFactory) + for _, m := range testCase.depsMutators { + ctx.DepsBp2BuildMutators(m) + } + ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator) + ctx.RegisterForBazelConversion() + + _, errs := ctx.ParseFileList(dir, toParse) + if Errored(t, testCase.description, errs) { + continue + } + _, errs = ctx.ResolveDependencies(config) + if Errored(t, testCase.description, errs) { + continue + } + + checkDir := dir + if testCase.dir != "" { + checkDir = testCase.dir + } + bazelTargets := GenerateBazelTargets(ctx.Context.Context, Bp2Build)[checkDir] + if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount { + t.Errorf("%s: Expected %d bazel target, got %d", testCase.description, expectedCount, actualCount) + } else { + for i, target := range bazelTargets { + if w, g := testCase.expectedBazelTargets[i], target.content; w != g { + t.Errorf( + "%s: Expected generated Bazel target to be '%s', got '%s'", + testCase.description, + w, + g, + ) + } + } + } + } +} diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go index e6024aa45..d083d2a0b 100644 --- a/cc/config/arm64_device.go +++ b/cc/config/arm64_device.go @@ -31,6 +31,10 @@ var ( "armv8-a": []string{ "-march=armv8-a", }, + "armv8-a-branchprot": []string{ + "-march=armv8-a", + "-mbranch-protection=standard", + }, "armv8-2a": []string{ "-march=armv8.2-a", }, @@ -102,6 +106,7 @@ func init() { pctx.StaticVariable("Arm64ClangCppflags", strings.Join(ClangFilterUnknownCflags(arm64Cppflags), " ")) pctx.StaticVariable("Arm64ClangArmv8ACflags", strings.Join(arm64ArchVariantCflags["armv8-a"], " ")) + pctx.StaticVariable("Arm64ClangArmv8ABranchProtCflags", strings.Join(arm64ArchVariantCflags["armv8-a-branchprot"], " ")) pctx.StaticVariable("Arm64ClangArmv82ACflags", strings.Join(arm64ArchVariantCflags["armv8-2a"], " ")) pctx.StaticVariable("Arm64ClangArmv82ADotprodCflags", strings.Join(arm64ArchVariantCflags["armv8-2a-dotprod"], " ")) @@ -124,6 +129,7 @@ func init() { var ( arm64ClangArchVariantCflagsVar = map[string]string{ "armv8-a": "${config.Arm64ClangArmv8ACflags}", + "armv8-a-branchprot": "${config.Arm64ClangArmv8ABranchProtCflags}", "armv8-2a": "${config.Arm64ClangArmv82ACflags}", "armv8-2a-dotprod": "${config.Arm64ClangArmv82ADotprodCflags}", } @@ -202,6 +208,7 @@ func (toolchainArm64) LibclangRuntimeLibraryArch() string { func arm64ToolchainFactory(arch android.Arch) Toolchain { switch arch.ArchVariant { case "armv8-a": + case "armv8-a-branchprot": case "armv8-2a": case "armv8-2a-dotprod": // Nothing extra for armv8-a/armv8-2a diff --git a/cc/config/clang.go b/cc/config/clang.go index 71c7626d9..76186be57 100644 --- a/cc/config/clang.go +++ b/cc/config/clang.go @@ -150,6 +150,8 @@ func init() { "-Wunguarded-availability", // This macro allows the bionic versioning.h to indirectly determine whether the // option -Wunguarded-availability is on or not. + "-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__", + // TODO: remove this once prebuilt SDKs are only using the above macro instead. "-D__ANDROID_UNGUARDED_AVAILABILITY__", }, " ")) diff --git a/cc/config/global.go b/cc/config/global.go index ee4112544..e60bb3d51 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -144,8 +144,8 @@ var ( // prebuilts/clang default settings. ClangDefaultBase = "prebuilts/clang/host" - ClangDefaultVersion = "clang-r407598b" - ClangDefaultShortVersion = "12.0.2" + ClangDefaultVersion = "clang-r412851" + ClangDefaultShortVersion = "12.0.3" // Directories with warnings from Android.bp files. WarningAllowedProjects = []string{ diff --git a/cc/config/tidy.go b/cc/config/tidy.go index 7cc9f438c..7c20dd543 100644 --- a/cc/config/tidy.go +++ b/cc/config/tidy.go @@ -87,27 +87,11 @@ func init() { }, ",") }) - // Give warnings to header files only in selected directories. - // Do not give warnings to external or vendor header files, which contain too - // many warnings. + // To reduce duplicate warnings from the same header files, + // header-filter will contain only the module directory and + // those specified by DEFAULT_TIDY_HEADER_DIRS. pctx.VariableFunc("TidyDefaultHeaderDirs", func(ctx android.PackageVarContext) string { - if override := ctx.Config().Getenv("DEFAULT_TIDY_HEADER_DIRS"); override != "" { - return override - } - return strings.Join([]string{ - "art/", - "bionic/", - "bootable/", - "build/", - "cts/", - "dalvik/", - "developers/", - "development/", - "frameworks/", - "libcore/", - "libnativehelper/", - "system/", - }, "|") + return ctx.Config().Getenv("DEFAULT_TIDY_HEADER_DIRS") }) // Use WTIH_TIDY_FLAGS to pass extra global default clang-tidy flags. diff --git a/cc/library.go b/cc/library.go index 65533bc2b..bdcb8ae04 100644 --- a/cc/library.go +++ b/cc/library.go @@ -27,6 +27,7 @@ import ( "github.com/google/blueprint/pathtools" "android/soong/android" + "android/soong/bazel" "android/soong/cc/config" ) @@ -120,6 +121,9 @@ type LibraryProperties struct { // If this is an LLNDK library, properties to describe the LLNDK stubs. Will be copied from // the module pointed to by llndk_stubs if it is set. Llndk llndkLibraryProperties + + // Properties for Bazel migration purposes. + bazel.Properties } // StaticProperties is a properties stanza to affect only attributes of the "static" variants of a diff --git a/cc/library_headers.go b/cc/library_headers.go index 8b3dbeb8b..448e1444d 100644 --- a/cc/library_headers.go +++ b/cc/library_headers.go @@ -14,13 +14,18 @@ package cc -import "android/soong/android" +import ( + "android/soong/android" + "android/soong/bazel" +) func init() { RegisterLibraryHeadersBuildComponents(android.InitRegistrationContext) // Register sdk member types. android.RegisterSdkMemberType(headersLibrarySdkMemberType) + + android.RegisterBp2BuildMutator("cc_library_headers", CcLibraryHeadersBp2Build) } var headersLibrarySdkMemberType = &librarySdkMemberType{ @@ -55,3 +60,86 @@ func prebuiltLibraryHeaderFactory() android.Module { library.HeaderOnly() return module.Init() } + +type bazelCcLibraryHeadersAttributes struct { + Hdrs bazel.LabelList + Includes bazel.LabelList + Deps bazel.LabelList +} + +type bazelCcLibraryHeaders struct { + android.BazelTargetModuleBase + bazelCcLibraryHeadersAttributes +} + +func BazelCcLibraryHeadersFactory() android.Module { + module := &bazelCcLibraryHeaders{} + module.AddProperties(&module.bazelCcLibraryHeadersAttributes) + android.InitBazelTargetModule(module) + return module +} + +func CcLibraryHeadersBp2Build(ctx android.TopDownMutatorContext) { + module, ok := ctx.Module().(*Module) + if !ok { + // Not a cc module + return + } + + lib, ok := module.linker.(*libraryDecorator) + if !ok { + // Not a cc_library module + return + } + if !lib.header() { + // Not a cc_library_headers module + return + } + + if !lib.Properties.Bazel_module.Bp2build_available { + return + } + + // list of directories that will be added to the include path (using -I) for this + // module and any module that links against this module. + includeDirs := lib.flagExporter.Properties.Export_system_include_dirs + includeDirs = append(includeDirs, lib.flagExporter.Properties.Export_include_dirs...) + includeDirLabels := android.BazelLabelForModuleSrc(ctx, includeDirs) + + var includeDirGlobs []string + for _, includeDir := range includeDirs { + includeDirGlobs = append(includeDirGlobs, includeDir+"/**/*.h") + } + + headerLabels := android.BazelLabelForModuleSrc(ctx, includeDirGlobs) + + // list of modules that should only provide headers for this module. + var headerLibs []string + for _, linkerProps := range lib.linkerProps() { + if baseLinkerProps, ok := linkerProps.(*BaseLinkerProperties); ok { + headerLibs = baseLinkerProps.Export_header_lib_headers + break + } + } + headerLibLabels := android.BazelLabelForModuleDeps(ctx, headerLibs) + + attrs := &bazelCcLibraryHeadersAttributes{ + Includes: includeDirLabels, + Hdrs: headerLabels, + Deps: headerLibLabels, + } + + props := bazel.NewBazelTargetModuleProperties( + module.Name(), + "cc_library_headers", + "//build/bazel/rules:cc_library_headers.bzl", + ) + + ctx.CreateBazelTargetModule(BazelCcLibraryHeadersFactory, props, attrs) +} + +func (m *bazelCcLibraryHeaders) Name() string { + return m.BaseModuleName() +} + +func (m *bazelCcLibraryHeaders) GenerateAndroidBuildActions(ctx android.ModuleContext) {} diff --git a/cc/tidy.go b/cc/tidy.go index 972ad7bc7..251c67b07 100644 --- a/cc/tidy.go +++ b/cc/tidy.go @@ -20,6 +20,7 @@ import ( "github.com/google/blueprint/proptools" + "android/soong/android" "android/soong/cc/config" ) @@ -75,9 +76,17 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags { } esc := proptools.NinjaAndShellEscapeList flags.TidyFlags = append(flags.TidyFlags, esc(tidy.Properties.Tidy_flags)...) - // If TidyFlags is empty, add default header filter. - if len(flags.TidyFlags) == 0 { - headerFilter := "-header-filter=\"(" + ctx.ModuleDir() + "|${config.TidyDefaultHeaderDirs})\"" + // If TidyFlags does not contain -header-filter, add default header filter. + // Find the substring because the flag could also appear as --header-filter=... + // and with or without single or double quotes. + if !android.SubstringInList(flags.TidyFlags, "-header-filter=") { + defaultDirs := ctx.Config().Getenv("DEFAULT_TIDY_HEADER_DIRS") + headerFilter := "-header-filter=" + if defaultDirs == "" { + headerFilter += ctx.ModuleDir() + "/" + } else { + headerFilter += "\"(" + ctx.ModuleDir() + "/|" + defaultDirs + ")\"" + } flags.TidyFlags = append(flags.TidyFlags, headerFilter) } diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go index 850c8f95a..57563eb07 100644 --- a/etc/prebuilt_etc.go +++ b/etc/prebuilt_etc.go @@ -28,6 +28,8 @@ package etc // various `prebuilt_*` mutators. import ( + "fmt" + "github.com/google/blueprint/proptools" "android/soong/android" @@ -208,6 +210,17 @@ func (p *PrebuiltEtc) OutputFile() android.OutputPath { return p.outputFilePath } +var _ android.OutputFileProducer = (*PrebuiltEtc)(nil) + +func (p *PrebuiltEtc) OutputFiles(tag string) (android.Paths, error) { + switch tag { + case "": + return android.Paths{p.outputFilePath}, nil + default: + return nil, fmt.Errorf("unsupported module reference tag %q", tag) + } +} + func (p *PrebuiltEtc) SubDir() string { if subDir := proptools.String(p.properties.Sub_dir); subDir != "" { return subDir diff --git a/filesystem/bootimg.go b/filesystem/bootimg.go index 4bc182396..c90929ae9 100644 --- a/filesystem/bootimg.go +++ b/filesystem/bootimg.go @@ -38,6 +38,9 @@ type bootimg struct { } type bootimgProperties struct { + // Set the name of the output. Defaults to <module_name>.img. + Stem *string + // Path to the linux kernel prebuilt file Kernel_prebuilt *string `android:"arch_variant,path"` @@ -96,7 +99,7 @@ func (b *bootimg) DepsMutator(ctx android.BottomUpMutatorContext) { } func (b *bootimg) installFileName() string { - return b.BaseModuleName() + ".img" + return proptools.StringDefault(b.properties.Stem, b.BaseModuleName()+".img") } func (b *bootimg) partitionName() string { @@ -110,6 +113,7 @@ func (b *bootimg) GenerateAndroidBuildActions(ctx android.ModuleContext) { } else { // TODO(jiyong): fix this ctx.PropertyErrorf("vendor_boot", "only vendor_boot:true is supported") + return } if proptools.Bool(b.properties.Use_avb) { @@ -123,7 +127,8 @@ func (b *bootimg) GenerateAndroidBuildActions(ctx android.ModuleContext) { } func (b *bootimg) buildVendorBootImage(ctx android.ModuleContext) android.OutputPath { - output := android.PathForModuleOut(ctx, "unsigned.img").OutputPath + output := android.PathForModuleOut(ctx, "unsigned", b.installFileName()).OutputPath + builder := android.NewRuleBuilder(pctx, ctx) cmd := builder.Command().BuiltTool("mkbootimg") @@ -182,21 +187,20 @@ func (b *bootimg) buildVendorBootImage(ctx android.ModuleContext) android.Output } func (b *bootimg) signImage(ctx android.ModuleContext, unsignedImage android.OutputPath) android.OutputPath { - signedImage := android.PathForModuleOut(ctx, "signed.img").OutputPath + output := android.PathForModuleOut(ctx, b.installFileName()).OutputPath key := android.PathForModuleSrc(ctx, proptools.String(b.properties.Avb_private_key)) builder := android.NewRuleBuilder(pctx, ctx) - builder.Command().Text("cp").Input(unsignedImage).Output(signedImage) + builder.Command().Text("cp").Input(unsignedImage).Output(output) builder.Command(). BuiltTool("avbtool"). Flag("add_hash_footer"). FlagWithArg("--partition_name ", b.partitionName()). FlagWithInput("--key ", key). - FlagWithOutput("--image ", signedImage) + FlagWithOutput("--image ", output) builder.Build("sign_bootimg", fmt.Sprintf("Signing %s", b.BaseModuleName())) - - return signedImage + return output } var _ android.AndroidMkEntriesProvider = (*bootimg)(nil) diff --git a/java/hiddenapi.go b/java/hiddenapi.go index 1651c1c6d..f8e41c458 100644 --- a/java/hiddenapi.go +++ b/java/hiddenapi.go @@ -221,13 +221,19 @@ func (h *hiddenAPI) hiddenAPIExtractInformation(ctx android.ModuleContext, dexJa return } + classesJars := android.Paths{classesJar} + ctx.VisitDirectDepsWithTag(hiddenApiAnnotationsTag, func(dep android.Module) { + javaInfo := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo) + classesJars = append(classesJars, javaInfo.ImplementationJars...) + }) + stubFlagsCSV := hiddenAPISingletonPaths(ctx).stubFlags flagsCSV := android.PathForModuleOut(ctx, "hiddenapi", "flags.csv") ctx.Build(pctx, android.BuildParams{ Rule: hiddenAPIGenerateCSVRule, Description: "hiddenapi flags", - Input: classesJar, + Inputs: classesJars, Output: flagsCSV, Implicit: stubFlagsCSV, Args: map[string]string{ @@ -241,7 +247,7 @@ func (h *hiddenAPI) hiddenAPIExtractInformation(ctx android.ModuleContext, dexJa ctx.Build(pctx, android.BuildParams{ Rule: hiddenAPIGenerateCSVRule, Description: "hiddenapi metadata", - Input: classesJar, + Inputs: classesJars, Output: metadataCSV, Implicit: stubFlagsCSV, Args: map[string]string{ @@ -255,8 +261,9 @@ func (h *hiddenAPI) hiddenAPIExtractInformation(ctx android.ModuleContext, dexJa rule := android.NewRuleBuilder(pctx, ctx) rule.Command(). BuiltTool("merge_csv"). - FlagWithInput("--zip_input=", classesJar). - FlagWithOutput("--output=", indexCSV) + Flag("--zip_input"). + FlagWithOutput("--output=", indexCSV). + Inputs(classesJars) rule.Build("merged-hiddenapi-index", "Merged Hidden API index") h.indexCSVPath = indexCSV @@ -335,3 +342,16 @@ func hiddenAPIEncodeDex(ctx android.ModuleContext, output android.WritablePath, TransformZipAlign(ctx, output, tmpOutput) } } + +type hiddenApiAnnotationsDependencyTag struct { + blueprint.BaseDependencyTag +} + +// Tag used to mark dependencies on java_library instances that contains Java source files whose +// sole purpose is to provide additional hiddenapi annotations. +var hiddenApiAnnotationsTag hiddenApiAnnotationsDependencyTag + +// Mark this tag so dependencies that use it are excluded from APEX contents. +func (t hiddenApiAnnotationsDependencyTag) ExcludeFromApexContents() {} + +var _ android.ExcludeFromApexContentsTag = hiddenApiAnnotationsTag diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go index df825bb3a..4670d0311 100644 --- a/java/hiddenapi_singleton_test.go +++ b/java/hiddenapi_singleton_test.go @@ -82,6 +82,10 @@ func TestHiddenAPIIndexSingleton(t *testing.T) { name: "foo", srcs: ["a.java"], compile_dex: true, + + hiddenapi_additional_annotations: [ + "foo-hiddenapi-annotations", + ], } java_library { @@ -90,6 +94,12 @@ func TestHiddenAPIIndexSingleton(t *testing.T) { compile_dex: true, } + java_library { + name: "foo-hiddenapi-annotations", + srcs: ["a.java"], + compile_dex: true, + } + java_import { name: "foo", jars: ["a.jar"], @@ -112,6 +122,15 @@ func TestHiddenAPIIndexSingleton(t *testing.T) { .intermediates/foo/android_common/hiddenapi/index.csv `, indexRule) + + // Make sure that the foo-hiddenapi-annotations.jar is included in the inputs to the rules that + // creates the index.csv file. + foo := ctx.ModuleForTests("foo", "android_common") + indexParams := foo.Output("hiddenapi/index.csv") + CheckHiddenAPIRuleInputs(t, ` +.intermediates/foo-hiddenapi-annotations/android_common/javac/foo-hiddenapi-annotations.jar +.intermediates/foo/android_common/javac/foo.jar +`, indexParams) } func TestHiddenAPISingletonWithPrebuilt(t *testing.T) { diff --git a/java/java.go b/java/java.go index 338140bbf..69ec2a442 100644 --- a/java/java.go +++ b/java/java.go @@ -298,6 +298,9 @@ type CompilerProperties struct { // If true, package the kotlin stdlib into the jar. Defaults to true. Static_kotlin_stdlib *bool `android:"arch_variant"` + + // A list of java_library instances that provide additional hiddenapi annotations for the library. + Hiddenapi_additional_annotations []string } type CompilerDeviceProperties struct { @@ -840,6 +843,9 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { libDeps := ctx.AddVariationDependencies(nil, libTag, rewriteSyspropLibs(j.properties.Libs, "libs")...) ctx.AddVariationDependencies(nil, staticLibTag, rewriteSyspropLibs(j.properties.Static_libs, "static_libs")...) + // Add dependency on libraries that provide additional hidden api annotations. + ctx.AddVariationDependencies(nil, hiddenApiAnnotationsTag, j.properties.Hiddenapi_additional_annotations...) + if ctx.DeviceConfig().VndkVersion() != "" && ctx.Config().EnforceInterPartitionJavaSdkLibrary() { // Require java_sdk_library at inter-partition java dependency to ensure stable // interface between partitions. If inter-partition java_library dependency is detected, @@ -2426,7 +2432,7 @@ type testProperties struct { // list of files or filegroup modules that provide data that should be installed alongside // the test - Data []string `android:"path,arch_variant"` + Data []string `android:"path"` // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true diff --git a/rust/config/arm64_device.go b/rust/config/arm64_device.go index 506642861..186e571dd 100644 --- a/rust/config/arm64_device.go +++ b/rust/config/arm64_device.go @@ -26,9 +26,10 @@ var ( Arm64LinkFlags = []string{} Arm64ArchVariantRustFlags = map[string][]string{ - "armv8-a": []string{}, - "armv8-2a": []string{}, - "armv8-2a-dotprod": []string{}, + "armv8-a": []string{}, + "armv8-a-branchprot": []string{}, + "armv8-2a": []string{}, + "armv8-2a-dotprod": []string{}, } ) diff --git a/scripts/hiddenapi/Android.bp b/scripts/hiddenapi/Android.bp index a669cadd4..af7e7fe6b 100644 --- a/scripts/hiddenapi/Android.bp +++ b/scripts/hiddenapi/Android.bp @@ -14,6 +14,10 @@ * limitations under the License. */ +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + python_binary_host { name: "merge_csv", main: "merge_csv.py", diff --git a/scripts/hiddenapi/merge_csv.py b/scripts/hiddenapi/merge_csv.py index 6a5b0e134..5ad61b2f6 100755 --- a/scripts/hiddenapi/merge_csv.py +++ b/scripts/hiddenapi/merge_csv.py @@ -26,7 +26,8 @@ from zipfile import ZipFile args_parser = argparse.ArgumentParser(description='Merge given CSV files into a single one.') args_parser.add_argument('--header', help='Comma separated field names; ' 'if missing determines the header from input files.') -args_parser.add_argument('--zip_input', help='ZIP archive with all CSV files to merge.') +args_parser.add_argument('--zip_input', help='Treat files as ZIP archives containing CSV files to merge.', + action="store_true") args_parser.add_argument('--output', help='Output file for merged CSV.', default='-', type=argparse.FileType('w')) args_parser.add_argument('files', nargs=argparse.REMAINDER) @@ -36,20 +37,16 @@ args = args_parser.parse_args() def dict_reader(input): return csv.DictReader(input, delimiter=',', quotechar='|') - -if args.zip_input and len(args.files) > 0: - raise ValueError('Expecting either a single ZIP with CSV files' - ' or a list of CSV files as input; not both.') - csv_readers = [] -if len(args.files) > 0: +if not(args.zip_input): for file in args.files: csv_readers.append(dict_reader(open(file, 'r'))) -elif args.zip_input: - with ZipFile(args.zip_input) as zip: - for entry in zip.namelist(): - if entry.endswith('.uau'): - csv_readers.append(dict_reader(io.TextIOWrapper(zip.open(entry, 'r')))) +else: + for file in args.files: + with ZipFile(file) as zip: + for entry in zip.namelist(): + if entry.endswith('.uau'): + csv_readers.append(dict_reader(io.TextIOWrapper(zip.open(entry, 'r')))) headers = set() if args.header: |