diff options
| -rw-r--r-- | android/api_levels.go | 1 | ||||
| -rw-r--r-- | android/neverallow.go | 11 | ||||
| -rw-r--r-- | android/neverallow_test.go | 78 | ||||
| -rw-r--r-- | android/testing.go | 23 | ||||
| -rw-r--r-- | android/visibility_test.go | 18 | ||||
| -rw-r--r-- | cc/config/clang.go | 14 | ||||
| -rw-r--r-- | cc/sanitize.go | 3 | ||||
| -rw-r--r-- | cmd/soong_ui/main.go | 19 | ||||
| -rw-r--r-- | java/config/config.go | 3 | ||||
| -rw-r--r-- | java/java_test.go | 2 | ||||
| -rw-r--r-- | java/robolectric.go | 69 | ||||
| -rw-r--r-- | java/testing.go | 1 |
12 files changed, 177 insertions, 65 deletions
diff --git a/android/api_levels.go b/android/api_levels.go index 961685aa8..4f6efee70 100644 --- a/android/api_levels.go +++ b/android/api_levels.go @@ -71,6 +71,7 @@ func getApiLevelsMap(config Config) map[string]int { "O": 26, "O-MR1": 27, "P": 28, + "Q": 29, } for i, codename := range config.PlatformVersionCombinedCodenames() { apiLevelsMap[codename] = baseApiLevel + i diff --git a/android/neverallow.go b/android/neverallow.go index 8355bb3b8..08e14de38 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -51,6 +51,7 @@ func init() { AddNeverAllowRules(createIncludeDirsRules()...) AddNeverAllowRules(createTrebleRules()...) AddNeverAllowRules(createLibcoreRules()...) + AddNeverAllowRules(createMediaRules()...) AddNeverAllowRules(createJavaDeviceForHostRules()...) } @@ -110,7 +111,7 @@ func createTrebleRules() []Rule { // TODO(b/67974785): always enforce the manifest NeverAllow(). - Without("name", "libhidltransport"). + Without("name", "libhidltransport-impl-internal"). With("product_variables.enforce_vintf_manifest.cflags", "*"). Because("manifest enforcement should be independent of ."), @@ -151,6 +152,14 @@ func createLibcoreRules() []Rule { return rules } +func createMediaRules() []Rule { + return []Rule{ + NeverAllow(). + With("libs", "updatable-media"). + Because("updatable-media includes private APIs. Use updatable_media_stubs instead."), + } +} + func createJavaDeviceForHostRules() []Rule { javaDeviceForHostProjectsWhitelist := []string{ "external/guava", diff --git a/android/neverallow_test.go b/android/neverallow_test.go index 920b9a55c..cfab4f951 100644 --- a/android/neverallow_test.go +++ b/android/neverallow_test.go @@ -28,9 +28,9 @@ func init() { } var neverallowTests = []struct { - name string - fs map[string][]byte - expectedError string + name string + fs map[string][]byte + expectedErrors []string }{ // Test General Functionality @@ -48,7 +48,9 @@ var neverallowTests = []struct { static_libs: ["not_allowed_in_direct_deps"], }`), }, - expectedError: `module "libother": violates neverallow deps:not_allowed_in_direct_deps`, + expectedErrors: []string{ + `module "libother": violates neverallow deps:not_allowed_in_direct_deps`, + }, }, // Test specific rules @@ -63,7 +65,9 @@ var neverallowTests = []struct { include_dirs: ["art/libdexfile/include"], }`), }, - expectedError: "all usages of 'art' have been migrated", + expectedErrors: []string{ + "all usages of 'art' have been migrated", + }, }, { name: "include_dir can reference another location", @@ -88,7 +92,9 @@ var neverallowTests = []struct { }, }`), }, - expectedError: "VNDK can never contain a library that is device dependent", + expectedErrors: []string{ + "VNDK can never contain a library that is device dependent", + }, }, { name: "no vndk.enabled under device directory", @@ -102,7 +108,9 @@ var neverallowTests = []struct { }, }`), }, - expectedError: "VNDK can never contain a library that is device dependent", + expectedErrors: []string{ + "VNDK can never contain a library that is device dependent", + }, }, { name: "vndk-ext under vendor or device directory", @@ -124,7 +132,6 @@ var neverallowTests = []struct { }, }`), }, - expectedError: "", }, { @@ -140,22 +147,9 @@ var neverallowTests = []struct { }, }`), }, - expectedError: "manifest enforcement should be independent", - }, - { - name: "libhidltransport enforce_vintf_manifest.cflags", - fs: map[string][]byte{ - "Blueprints": []byte(` - cc_library { - name: "libhidltransport", - product_variables: { - enforce_vintf_manifest: { - cflags: ["-DSHOULD_NOT_EXIST"], - }, - }, - }`), + expectedErrors: []string{ + "manifest enforcement should be independent", }, - expectedError: "", }, { @@ -171,7 +165,9 @@ var neverallowTests = []struct { }, }`), }, - expectedError: "nothing should care if linker namespaces are enabled or not", + expectedErrors: []string{ + "nothing should care if linker namespaces are enabled or not", + }, }, { name: "libc_bionic_ndk treble_linker_namespaces.cflags", @@ -186,7 +182,19 @@ var neverallowTests = []struct { }, }`), }, - expectedError: "", + }, + { + name: "dependency on updatable-media", + fs: map[string][]byte{ + "Blueprints": []byte(` + java_library { + name: "needs_updatable_media", + libs: ["updatable-media"], + }`), + }, + expectedErrors: []string{ + "updatable-media includes private APIs. Use updatable_media_stubs instead.", + }, }, { name: "java_device_for_host", @@ -197,7 +205,9 @@ var neverallowTests = []struct { libs: ["core-libart"], }`), }, - expectedError: "java_device_for_host can only be used in whitelisted projects", + expectedErrors: []string{ + "java_device_for_host can only be used in whitelisted projects", + }, }, // Libcore rule tests { @@ -219,7 +229,9 @@ var neverallowTests = []struct { sdk_version: "none", }`), }, - expectedError: "module \"outside_core_libraries\": violates neverallow", + expectedErrors: []string{ + "module \"outside_core_libraries\": violates neverallow", + }, }, { name: "sdk_version: \"current\"", @@ -237,19 +249,15 @@ func TestNeverallow(t *testing.T) { config := TestConfig(buildDir, nil) for _, test := range neverallowTests { - t.Run(test.name, func(t *testing.T) { - _, errs := testNeverallow(t, config, test.fs) - if test.expectedError == "" { - FailIfErrored(t, errs) - } else { - FailIfNoMatchingErrors(t, test.expectedError, errs) - } + t.Run(test.name, func(t *testing.T) { + _, errs := testNeverallow(config, test.fs) + CheckErrorsAgainstExpectations(t, errs, test.expectedErrors) }) } } -func testNeverallow(t *testing.T, config Config, fs map[string][]byte) (*TestContext, []error) { +func testNeverallow(config Config, fs map[string][]byte) (*TestContext, []error) { ctx := NewTestContext() ctx.RegisterModuleType("cc_library", ModuleFactoryAdaptor(newMockCcLibraryModule)) ctx.RegisterModuleType("java_library", ModuleFactoryAdaptor(newMockJavaLibraryModule)) diff --git a/android/testing.go b/android/testing.go index b59f399d0..447ffd6d4 100644 --- a/android/testing.go +++ b/android/testing.go @@ -372,6 +372,29 @@ func FailIfNoMatchingErrors(t *testing.T, pattern string, errs []error) { } } +func CheckErrorsAgainstExpectations(t *testing.T, errs []error, expectedErrorPatterns []string) { + t.Helper() + + if expectedErrorPatterns == nil { + FailIfErrored(t, errs) + } else { + for _, expectedError := range expectedErrorPatterns { + FailIfNoMatchingErrors(t, expectedError, errs) + } + if len(errs) > len(expectedErrorPatterns) { + t.Errorf("additional errors found, expected %d, found %d", + len(expectedErrorPatterns), len(errs)) + for i, expectedError := range expectedErrorPatterns { + t.Errorf("expectedErrors[%d] = %s", i, expectedError) + } + for i, err := range errs { + t.Errorf("errs[%d] = %s", i, err) + } + } + } + +} + func AndroidMkEntriesForTest(t *testing.T, config Config, bpPath string, mod blueprint.Module) AndroidMkEntries { var p AndroidMkEntriesProvider var ok bool diff --git a/android/visibility_test.go b/android/visibility_test.go index c44dc9e3c..d13fadf6a 100644 --- a/android/visibility_test.go +++ b/android/visibility_test.go @@ -860,23 +860,7 @@ func TestVisibility(t *testing.T) { t.Run(test.name, func(t *testing.T) { _, errs := testVisibility(buildDir, test.fs) - expectedErrors := test.expectedErrors - if expectedErrors == nil { - FailIfErrored(t, errs) - } else { - for _, expectedError := range expectedErrors { - FailIfNoMatchingErrors(t, expectedError, errs) - } - if len(errs) > len(expectedErrors) { - t.Errorf("additional errors found, expected %d, found %d", len(expectedErrors), len(errs)) - for i, expectedError := range expectedErrors { - t.Errorf("expectedErrors[%d] = %s", i, expectedError) - } - for i, err := range errs { - t.Errorf("errs[%d] = %s", i, err) - } - } - } + CheckErrorsAgainstExpectations(t, errs, test.expectedErrors) }) } } diff --git a/cc/config/clang.go b/cc/config/clang.go index 47b60e713..59c78a620 100644 --- a/cc/config/clang.go +++ b/cc/config/clang.go @@ -101,9 +101,8 @@ func init() { // not emit the table by default on Android since NDK still uses GNU binutils. "-faddrsig", - // Make implicit fallthrough an error in the future. + // -Wimplicit-fallthrough is not enabled by -Wall. "-Wimplicit-fallthrough", - "-Wno-error=implicit-fallthrough", // Help catch common 32/64-bit errors. "-Werror=int-conversion", @@ -171,11 +170,6 @@ func init() { "-Wno-tautological-unsigned-enum-zero-compare", "-Wno-tautological-unsigned-zero-compare", - // http://b/72330874 Disable -Wenum-compare until the instances detected by this new - // warning are fixed. - "-Wno-enum-compare", - "-Wno-enum-compare-switch", - // Disable c++98-specific warning since Android is not concerned with C++98 // compatibility. "-Wno-c++98-compat-extra-semi", @@ -184,9 +178,11 @@ func init() { "-Wno-return-std-move-in-c++11", }, " ")) - // Extra cflags for projects under external/ directory + // Extra cflags for projects under external/ directory to disable warnings that are infeasible + // to fix in all the external projects and their upstream repos. pctx.StaticVariable("ClangExtraExternalCflags", strings.Join([]string{ - // TODO(yikong): Move -Wno flags here + "-Wno-enum-compare", + "-Wno-enum-compare-switch", // http://b/72331524 Allow null pointer arithmetic until the instances detected by // this new warning are fixed. diff --git a/cc/sanitize.go b/cc/sanitize.go index 192b8d964..ac8d0349d 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -56,7 +56,8 @@ var ( minimalRuntimeFlags = []string{"-fsanitize-minimal-runtime", "-fno-sanitize-trap=integer,undefined", "-fno-sanitize-recover=integer,undefined"} - hwasanGlobalOptions = []string{"heap_history_size=1023,stack_history_size=512"} + hwasanGlobalOptions = []string{"heap_history_size=1023", "stack_history_size=512", + "export_memory_stats=0", "max_malloc_fill_size=0"} ) type sanitizerType int diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go index 39303bf2e..ec4f90e06 100644 --- a/cmd/soong_ui/main.go +++ b/cmd/soong_ui/main.go @@ -180,6 +180,11 @@ func main() { } } + // Fix up the source tree due to a repo bug where it doesn't remove + // linkfiles that have been removed + fixBadDanglingLink(buildCtx, "hardware/qcom/sdm710/Android.bp") + fixBadDanglingLink(buildCtx, "hardware/qcom/sdm710/Android.mk") + f := build.NewSourceFinder(buildCtx, config) defer f.Shutdown() build.FindSources(buildCtx, config, f) @@ -187,6 +192,20 @@ func main() { c.run(buildCtx, config, args, logsDir) } +func fixBadDanglingLink(ctx build.Context, name string) { + _, err := os.Lstat(name) + if err != nil { + return + } + _, err = os.Stat(name) + if os.IsNotExist(err) { + err = os.Remove(name) + if err != nil { + ctx.Fatalf("Failed to remove dangling link %q: %v", name, err) + } + } +} + func dumpVar(ctx build.Context, config build.Config, args []string, _ string) { flags := flag.NewFlagSet("dumpvar", flag.ExitOnError) flags.Usage = func() { diff --git a/java/config/config.go b/java/config/config.go index b371cbf9f..6be83c397 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -29,7 +29,7 @@ var ( DefaultBootclasspathLibraries = []string{"core.platform.api.stubs", "core-lambda-stubs"} DefaultSystemModules = "core-platform-api-stubs-system-modules" - DefaultLibraries = []string{"ext", "framework"} + DefaultLibraries = []string{"ext", "framework", "updatable_media_stubs"} DefaultLambdaStubsLibrary = "core-lambda-stubs" SdkLambdaStubsPath = "prebuilts/sdk/tools/core-lambda-stubs.jar" @@ -45,6 +45,7 @@ var ( "core-icu4j", "core-oj", "core-libart", + "updatable-media", } ) diff --git a/java/java_test.go b/java/java_test.go index 5fcdf9670..6a18e5232 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1105,7 +1105,7 @@ func TestPatchModule(t *testing.T) { checkPatchModuleFlag(t, ctx, "foo", "") expected := "java.base=.:" + buildDir checkPatchModuleFlag(t, ctx, "bar", expected) - expected = "java.base=" + strings.Join([]string{".", buildDir, moduleToPath("ext"), moduleToPath("framework")}, ":") + expected = "java.base=" + strings.Join([]string{".", buildDir, moduleToPath("ext"), moduleToPath("framework"), moduleToPath("updatable_media_stubs")}, ":") checkPatchModuleFlag(t, ctx, "baz", expected) }) } diff --git a/java/robolectric.go b/java/robolectric.go index 1de56a5cd..cbe3557bc 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -34,10 +34,17 @@ var robolectricDefaultLibs = []string{ "truth-prebuilt", } +var ( + roboCoverageLibsTag = dependencyTag{name: "roboSrcs"} +) + type robolectricProperties struct { // The name of the android_app module that the tests will run against. Instrumentation_for *string + // Additional libraries for which coverage data should be generated + Coverage_libs []string + Test_options struct { // Timeout in seconds when running the tests. Timeout *int64 @@ -54,6 +61,8 @@ type robolectricTest struct { libs []string tests []string + + roboSrcJar android.Path } func (r *robolectricTest) DepsMutator(ctx android.BottomUpMutatorContext) { @@ -66,11 +75,35 @@ func (r *robolectricTest) DepsMutator(ctx android.BottomUpMutatorContext) { } ctx.AddVariationDependencies(nil, libTag, robolectricDefaultLibs...) + + ctx.AddVariationDependencies(nil, roboCoverageLibsTag, r.robolectricProperties.Coverage_libs...) } func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { + roboTestConfig := android.PathForModuleGen(ctx, "robolectric"). + Join(ctx, "com/android/tools/test_config.properties") + + // TODO: this inserts paths to built files into the test, it should really be inserting the contents. + instrumented := ctx.GetDirectDepsWithTag(instrumentationForTag) + + if len(instrumented) != 1 { + panic(fmt.Errorf("expected exactly 1 instrumented dependency, got %d", len(instrumented))) + } + + instrumentedApp, ok := instrumented[0].(*AndroidApp) + if !ok { + ctx.PropertyErrorf("instrumentation_for", "dependency must be an android_app") + } + + generateRoboTestConfig(ctx, roboTestConfig, instrumentedApp) + r.extraResources = android.Paths{roboTestConfig} + r.Library.GenerateAndroidBuildActions(ctx) + roboSrcJar := android.PathForModuleGen(ctx, "robolectric", ctx.ModuleName()+".srcjar") + r.generateRoboSrcJar(ctx, roboSrcJar, instrumentedApp) + r.roboSrcJar = roboSrcJar + for _, dep := range ctx.GetDirectDepsWithTag(libTag) { r.libs = append(r.libs, ctx.OtherModuleName(dep)) } @@ -109,6 +142,41 @@ func shardTests(paths []string, shards int) [][]string { return ret } +func generateRoboTestConfig(ctx android.ModuleContext, outputFile android.WritablePath, instrumentedApp *AndroidApp) { + manifest := instrumentedApp.mergedManifestFile + resourceApk := instrumentedApp.outputFile + + rule := android.NewRuleBuilder() + + rule.Command().Text("rm -f").Output(outputFile) + rule.Command(). + Textf(`echo "android_merged_manifest=%s" >>`, manifest.String()).Output(outputFile).Text("&&"). + Textf(`echo "android_resource_apk=%s" >>`, resourceApk.String()).Output(outputFile). + // Make it depend on the files to which it points so the test file's timestamp is updated whenever the + // contents change + Implicit(manifest). + Implicit(resourceApk) + + rule.Build(pctx, ctx, "generate_test_config", "generate test_config.properties") +} + +func (r *robolectricTest) generateRoboSrcJar(ctx android.ModuleContext, outputFile android.WritablePath, + instrumentedApp *AndroidApp) { + + srcJarArgs := copyOf(instrumentedApp.srcJarArgs) + srcJarDeps := append(android.Paths(nil), instrumentedApp.srcJarDeps...) + + for _, m := range ctx.GetDirectDepsWithTag(roboCoverageLibsTag) { + if dep, ok := m.(Dependency); ok { + depSrcJarArgs, depSrcJarDeps := dep.SrcJarArgs() + srcJarArgs = append(srcJarArgs, depSrcJarArgs...) + srcJarDeps = append(srcJarDeps, depSrcJarDeps...) + } + } + + TransformResourcesToJar(ctx, outputFile, srcJarArgs, srcJarDeps) +} + func (r *robolectricTest) AndroidMk() android.AndroidMkData { data := r.Library.AndroidMk() @@ -144,6 +212,7 @@ func (r *robolectricTest) writeTestRunner(w io.Writer, module, name string, test fmt.Fprintln(w, "LOCAL_JAVA_LIBRARIES :=", module) fmt.Fprintln(w, "LOCAL_JAVA_LIBRARIES += ", strings.Join(r.libs, " ")) fmt.Fprintln(w, "LOCAL_TEST_PACKAGE :=", String(r.robolectricProperties.Instrumentation_for)) + fmt.Fprintln(w, "LOCAL_INSTRUMENT_SRCJARS :=", r.roboSrcJar.String()) fmt.Fprintln(w, "LOCAL_ROBOTEST_FILES :=", strings.Join(tests, " ")) if t := r.robolectricProperties.Test_options.Timeout; t != nil { fmt.Fprintln(w, "LOCAL_ROBOTEST_TIMEOUT :=", *t) diff --git a/java/testing.go b/java/testing.go index 5d116a787..a37c0a9dc 100644 --- a/java/testing.go +++ b/java/testing.go @@ -38,6 +38,7 @@ func GatherRequiredDepsForTest() string { extraModules := []string{ "core-lambda-stubs", "ext", + "updatable_media_stubs", "android_stubs_current", "android_system_stubs_current", "android_test_stubs_current", |