Merge "Set targetSdkVersion to 10000 for MTS tests targeting current"
diff --git a/android/config.go b/android/config.go
index 8c01bee..84c17de 100644
--- a/android/config.go
+++ b/android/config.go
@@ -18,6 +18,7 @@
 // product variables necessary for soong_build's operation.
 
 import (
+	"bytes"
 	"encoding/json"
 	"errors"
 	"fmt"
@@ -305,6 +306,9 @@
 	if err != nil {
 		return fmt.Errorf("cannot marshal config data: %s", err.Error())
 	}
+	// The backslashes need to be escaped because this text is going to be put
+	// inside a Starlark string literal.
+	configJson = bytes.ReplaceAll(configJson, []byte("\\"), []byte("\\\\"))
 
 	bzl := []string{
 		bazel.GeneratedBazelFileWarning,
@@ -317,11 +321,11 @@
 arch_variant_product_var_constraints = _arch_variant_product_var_constraints
 `,
 	}
-	err = ioutil.WriteFile(filepath.Join(dir, "product_variables.bzl"), []byte(strings.Join(bzl, "\n")), 0644)
+	err = os.WriteFile(filepath.Join(dir, "product_variables.bzl"), []byte(strings.Join(bzl, "\n")), 0644)
 	if err != nil {
 		return fmt.Errorf("Could not write .bzl config file %s", err)
 	}
-	err = ioutil.WriteFile(filepath.Join(dir, "BUILD"), []byte(bazel.GeneratedBazelFileWarning), 0644)
+	err = os.WriteFile(filepath.Join(dir, "BUILD"), []byte(bazel.GeneratedBazelFileWarning), 0644)
 	if err != nil {
 		return fmt.Errorf("Could not write BUILD config file %s", err)
 	}
diff --git a/apex/apex.go b/apex/apex.go
index 09a5784..e9b0815 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -2701,7 +2701,7 @@
 
 var _ android.ModuleWithMinSdkVersionCheck = (*apexBundle)(nil)
 
-// Entures that min_sdk_version of the included modules are equal or less than the min_sdk_version
+// Ensures that min_sdk_version of the included modules are equal or less than the min_sdk_version
 // of this apexBundle.
 func (a *apexBundle) CheckMinSdkVersion(ctx android.ModuleContext) {
 	if a.testApex || a.vndkApex {
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index 415becb..242ea1e 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -320,7 +320,8 @@
 
 				// Handle modules with unconverted deps. By default, emit a warning.
 				if unconvertedDeps := aModule.GetUnconvertedBp2buildDeps(); len(unconvertedDeps) > 0 {
-					msg := fmt.Sprintf("%q depends on unconverted modules: %s", m.Name(), strings.Join(unconvertedDeps, ", "))
+					msg := fmt.Sprintf("%s %s:%s depends on unconverted modules: %s",
+						moduleType, bpCtx.ModuleDir(m), m.Name(), strings.Join(unconvertedDeps, ", "))
 					if ctx.unconvertedDepMode == warnUnconvertedDeps {
 						metrics.moduleWithUnconvertedDepsMsgs = append(metrics.moduleWithUnconvertedDepsMsgs, msg)
 					} else if ctx.unconvertedDepMode == errorModulesUnconvertedDeps {
@@ -329,7 +330,8 @@
 					}
 				}
 				if unconvertedDeps := aModule.GetMissingBp2buildDeps(); len(unconvertedDeps) > 0 {
-					msg := fmt.Sprintf("%q depends on missing modules: %s", m.Name(), strings.Join(unconvertedDeps, ", "))
+					msg := fmt.Sprintf("%s %s:%s depends on missing modules: %s",
+						moduleType, bpCtx.ModuleDir(m), m.Name(), strings.Join(unconvertedDeps, ", "))
 					if ctx.unconvertedDepMode == warnUnconvertedDeps {
 						metrics.moduleWithMissingDepsMsgs = append(metrics.moduleWithMissingDepsMsgs, msg)
 					} else if ctx.unconvertedDepMode == errorModulesUnconvertedDeps {
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index d36d2a9..c5644ed 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -1032,7 +1032,7 @@
     ],
     bazel_module: { bp2build_available: true },
 }`,
-			ExpectedErr: fmt.Errorf(`"foobar" depends on unconverted modules: foo`),
+			ExpectedErr: fmt.Errorf(`filegroup .:foobar depends on unconverted modules: foo`),
 			Filesystem: map[string]string{
 				"other/Android.bp": `filegroup {
     name: "foo",
diff --git a/java/dex.go b/java/dex.go
index c943938..a44d792 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -42,6 +42,9 @@
 		// True if the module containing this has it set by default.
 		EnabledByDefault bool `blueprint:"mutated"`
 
+		// Whether to continue building even if warnings are emitted.  Defaults to true.
+		Ignore_warnings *bool
+
 		// If true, runs R8 in Proguard compatibility mode (default).
 		// Otherwise, runs R8 in full mode.
 		Proguard_compatibility *bool
@@ -293,7 +296,10 @@
 	}
 
 	// TODO(b/180878971): missing classes should be added to the relevant builds.
-	r8Flags = append(r8Flags, "-ignorewarnings")
+	// TODO(b/229727645): do not use true as default for Android platform builds.
+	if proptools.BoolDefault(opt.Ignore_warnings, true) {
+		r8Flags = append(r8Flags, "-ignorewarnings")
+	}
 
 	return r8Flags, r8Deps
 }
diff --git a/java/dex_test.go b/java/dex_test.go
index fbdccb6..a3e2ded 100644
--- a/java/dex_test.go
+++ b/java/dex_test.go
@@ -59,6 +59,36 @@
 		appR8.Args["r8Flags"], libHeader.String())
 	android.AssertStringDoesNotContain(t, "expected no  static_lib header jar in app javac classpath",
 		appR8.Args["r8Flags"], staticLibHeader.String())
+	android.AssertStringDoesContain(t, "expected -ignorewarnings in app r8 flags",
+		appR8.Args["r8Flags"], "-ignorewarnings")
+}
+
+func TestR8Flags(t *testing.T) {
+	result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, `
+		android_app {
+			name: "app",
+			srcs: ["foo.java"],
+			platform_apis: true,
+			optimize: {
+				shrink: false,
+				optimize: false,
+				obfuscate: false,
+				ignore_warnings: false,
+			},
+		}
+	`)
+
+	app := result.ModuleForTests("app", "android_common")
+	appR8 := app.Rule("r8")
+	android.AssertStringDoesContain(t, "expected -dontshrink in app r8 flags",
+		appR8.Args["r8Flags"], "-dontshrink")
+	android.AssertStringDoesContain(t, "expected -dontoptimize in app r8 flags",
+		appR8.Args["r8Flags"], "-dontoptimize")
+	android.AssertStringDoesContain(t, "expected -dontobfuscate in app r8 flags",
+		appR8.Args["r8Flags"], "-dontobfuscate")
+	android.AssertStringDoesNotContain(t, "expected no -ignorewarnings in app r8 flags",
+		appR8.Args["r8Flags"], "-ignorewarnings")
+
 }
 
 func TestD8(t *testing.T) {