Merge "Support abi check in bazel."
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 5658503..36fd94c 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -1353,7 +1353,7 @@
 
 	// Bazel prod-mode allowlist. Modules in this list are built by Bazel
 	// in either prod mode or staging mode.
-	ProdMixedBuildsEnabledList = []string{"com.android.tzdata"}
+	ProdMixedBuildsEnabledList = []string{}
 
 	// Staging-mode allowlist. Modules in this list are only built
 	// by Bazel with --bazel-mode-staging. This list should contain modules
diff --git a/android/bazel.go b/android/bazel.go
index 60989f6..3731dfe 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -383,6 +383,9 @@
 // mixedBuildPossible returns true if a module is ready to be replaced by a
 // converted or handcrafted Bazel target.
 func mixedBuildPossible(ctx BaseModuleContext) bool {
+	if !ctx.Config().IsMixedBuildsEnabled() {
+		return false
+	}
 	if ctx.Os() == Windows {
 		// Windows toolchains are not currently supported.
 		return false
diff --git a/android/config.go b/android/config.go
index 1deb7d4..52a8f13 100644
--- a/android/config.go
+++ b/android/config.go
@@ -536,7 +536,17 @@
 // Returns true if "Bazel builds" is enabled. In this mode, part of build
 // analysis is handled by Bazel.
 func (c *config) IsMixedBuildsEnabled() bool {
-	return c.BuildMode == BazelProdMode || c.BuildMode == BazelDevMode || c.BuildMode == BazelStagingMode
+	globalMixedBuildsSupport := c.Once(OnceKey{"globalMixedBuildsSupport"}, func() interface{} {
+		if c.productVariables.DeviceArch != nil && *c.productVariables.DeviceArch == "riscv64" {
+			fmt.Fprintln(os.Stderr, "unsupported device arch 'riscv64' for Bazel: falling back to non-mixed build")
+			return false
+		}
+		// TODO(b/253664931): Add other fallback criteria below.
+		return true
+	}).(bool)
+
+	bazelModeEnabled := c.BuildMode == BazelProdMode || c.BuildMode == BazelDevMode || c.BuildMode == BazelStagingMode
+	return globalMixedBuildsSupport && bazelModeEnabled
 }
 
 func (c *config) SetAllowMissingDependencies() {
diff --git a/android/module.go b/android/module.go
index b41a898..681f724 100644
--- a/android/module.go
+++ b/android/module.go
@@ -2053,7 +2053,7 @@
 }
 
 func (m *ModuleBase) InstallInVendor() bool {
-	return Bool(m.commonProperties.Vendor)
+	return Bool(m.commonProperties.Vendor) || Bool(m.commonProperties.Soc_specific) || Bool(m.commonProperties.Proprietary)
 }
 
 func (m *ModuleBase) InstallInRoot() bool {
diff --git a/android/test_config.go b/android/test_config.go
index de546c4..70c319a 100644
--- a/android/test_config.go
+++ b/android/test_config.go
@@ -62,6 +62,7 @@
 		TestAllowNonExistentPaths: true,
 
 		BazelContext:              noopBazelContext{},
+		BuildMode:                 BazelProdMode,
 		mixedBuildDisabledModules: make(map[string]struct{}),
 		mixedBuildEnabledModules:  make(map[string]struct{}),
 	}
diff --git a/bp2build/java_library_conversion_test.go b/bp2build/java_library_conversion_test.go
index 00056f8..e37fa62 100644
--- a/bp2build/java_library_conversion_test.go
+++ b/bp2build/java_library_conversion_test.go
@@ -53,11 +53,13 @@
 		ExpectedBazelTargets: []string{
 			MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
 				"srcs": `["a.java"]`,
-				"deps": `[":java-lib-2"]`,
+				"deps": `[":java-lib-2-neverlink"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
 			MakeBazelTarget("java_library", "java-lib-2", AttrNameToString{
 				"srcs": `["b.java"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-2"),
 		},
 	})
 }
@@ -87,11 +89,12 @@
 			MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
 				"srcs": `["a.java"]`,
 				"deps": `[
-        ":java-lib-2",
+        ":java-lib-2-neverlink",
         ":java-lib-3",
     ]`,
 				"exports": `[":java-lib-3"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
 		},
 	})
 }
@@ -113,6 +116,7 @@
 			MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
 				"exports": `[":java-lib-2"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
 		},
 	})
 }
@@ -152,6 +156,7 @@
 			MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
 				"plugins": `[":java-plugin-1"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
 		},
 	}, func(ctx android.RegistrationContext) {
 		ctx.RegisterModuleType("java_plugin", java.PluginFactory)
@@ -170,6 +175,7 @@
 				"srcs":      `["a.java"]`,
 				"javacopts": `["-source 11 -target 11"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
 		},
 	})
 }
@@ -193,6 +199,7 @@
     ]`,
 				"srcs": `["a.java"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
 		},
 	})
 }
@@ -212,6 +219,7 @@
 				"javacopts": `["-Xsuper-fast"]`,
 				"srcs":      `["a.java"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
 		},
 	})
 }
@@ -232,6 +240,7 @@
 				"javacopts": `["-Xsuper-fast"]`,
 				"srcs":      `["a.java"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
 		},
 	})
 }
@@ -265,6 +274,7 @@
         ":example_lib_logtags",
     ]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "example_lib"),
 		}})
 }
 
@@ -286,6 +296,7 @@
         "res/b.res",
     ]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
 		},
 	})
 }
@@ -310,6 +321,7 @@
         "res/dir1/b.res",
     ]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
 		},
 	})
 }
@@ -330,6 +342,7 @@
 				"resource_strip_prefix": `"res"`,
 				"resources":             `["res/a.res"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
 		},
 	})
 }
@@ -354,6 +367,7 @@
         "res/dir1/b.res",
     ]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
 		},
 	})
 }
@@ -406,6 +420,7 @@
         "b.java",
     ]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "example_lib"),
 		}})
 }
 
@@ -435,6 +450,7 @@
 				"exports": `[":example_lib_java_aidl_library"]`,
 				"srcs":    `["a.java"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "example_lib"),
 		},
 	}, func(ctx android.RegistrationContext) {
 		ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
@@ -490,6 +506,7 @@
         ":random_other_files",
     ]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "example_lib"),
 			MakeBazelTargetNoRestrictions("filegroup", "random_other_files", AttrNameToString{
 				"srcs": `[
         "a.java",
@@ -529,6 +546,7 @@
 			MakeBazelTarget("java_library", "foo", AttrNameToString{
 				"exports": `[":foo_java_aidl_library"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "foo"),
 		},
 	}, func(ctx android.RegistrationContext) {
 		ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
diff --git a/bp2build/java_library_host_conversion_test.go b/bp2build/java_library_host_conversion_test.go
index edd8690..14854c0 100644
--- a/bp2build/java_library_host_conversion_test.go
+++ b/bp2build/java_library_host_conversion_test.go
@@ -48,7 +48,15 @@
 		ExpectedBazelTargets: []string{
 			MakeBazelTarget("java_library", "java-lib-host-1", AttrNameToString{
 				"srcs": `["a.java"]`,
-				"deps": `[":java-lib-host-2"]`,
+				"deps": `[":java-lib-host-2-neverlink"]`,
+				"target_compatible_with": `select({
+        "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
+        "//conditions:default": [],
+    })`,
+			}),
+			MakeBazelTarget("java_library", "java-lib-host-1-neverlink", AttrNameToString{
+				"exports":   `[":java-lib-host-1"]`,
+				"neverlink": `True`,
 				"target_compatible_with": `select({
         "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
         "//conditions:default": [],
@@ -62,6 +70,14 @@
         "//conditions:default": [],
     })`,
 			}),
+			MakeBazelTarget("java_library", "java-lib-host-2-neverlink", AttrNameToString{
+				"exports":   `[":java-lib-host-2"]`,
+				"neverlink": `True`,
+				"target_compatible_with": `select({
+        "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
+        "//conditions:default": [],
+    })`,
+			}),
 		},
 	})
 }
diff --git a/bp2build/java_proto_conversion_test.go b/bp2build/java_proto_conversion_test.go
index df0df2f..d25b7c4 100644
--- a/bp2build/java_proto_conversion_test.go
+++ b/bp2build/java_proto_conversion_test.go
@@ -91,6 +91,7 @@
 				MakeBazelTarget("java_library", "java-protos", AttrNameToString{
 					"exports": fmt.Sprintf(`[":%s"]`, javaLibraryName),
 				}),
+				MakeNeverlinkDuplicateTarget("java_library", "java-protos"),
 			},
 		})
 	}
@@ -119,6 +120,7 @@
 				"exports":   `[":java-protos_java_proto_lite"]`,
 				"javacopts": `["-source 1.7 -target 1.7"]`,
 			}),
+			MakeNeverlinkDuplicateTarget("java_library", "java-protos"),
 		},
 	})
 }
diff --git a/bp2build/testing.go b/bp2build/testing.go
index 0f1a8b2..4e63d19 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -532,3 +532,10 @@
 	}
 	return MakeBazelTarget("cc_stub_suite", name+"_stub_libs", stubSuiteAttrs)
 }
+
+func MakeNeverlinkDuplicateTarget(moduleType string, name string) string {
+	return MakeBazelTarget(moduleType, name+"-neverlink", AttrNameToString{
+		"neverlink": `True`,
+		"exports":   `[":` + name + `"]`,
+	})
+}
diff --git a/cc/config/global.go b/cc/config/global.go
index e5c0a8e..8047d8e 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -240,7 +240,6 @@
 		// New warnings to be fixed after clang-r458507
 		"-Wno-error=unqualified-std-cast-call", // http://b/239662094
 		// New warnings to be fixed after clang-r468909
-		"-Wno-error=array-parameter",     // http://b/241941550
 		"-Wno-error=deprecated-builtins", // http://b/241601211
 		"-Wno-error=deprecated",          // in external/googletest/googletest
 	}
@@ -253,6 +252,8 @@
 		"-Wno-bitwise-instead-of-logical",
 		// http://b/232926688
 		"-Wno-misleading-indentation",
+		// http://b/241941550
+		"-Wno-array-parameter",
 	}
 
 	// Extra cflags for external third-party projects to disable warnings that
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index bc2d5cb..3bc311b 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -276,6 +276,7 @@
 			src != "BUILD" &&
 			src != "BUILD.bazel" &&
 			!strings.HasPrefix(src, "build/bazel") &&
+			!strings.HasPrefix(src, "external/bazel-skylib") &&
 			!strings.HasPrefix(src, "prebuilts/clang") {
 			ret = append(ret, src)
 		}
@@ -578,6 +579,17 @@
 	// FIXME: 'frameworks/compile/slang' has a filegroup error due to an escaping issue
 	excludes = append(excludes, "frameworks/compile/slang")
 
+	// FIXME(b/260809113): 'prebuilts/clang/host/linux-x86/clang-dev' is a tool-generated symlink directory that contains a BUILD file.
+	// The bazel files finder code doesn't traverse into symlink dirs, and hence is not aware of this BUILD file and exclude it accordingly
+	// during symlink forest generation when checking against keepExistingBuildFiles allowlist.
+	//
+	// This is necessary because globs in //prebuilts/clang/host/linux-x86/BUILD
+	// currently assume no subpackages (keepExistingBuildFile is not recursive for that directory).
+	//
+	// This is a bandaid until we the symlink forest logic can intelligently exclude BUILD files found in source symlink dirs according
+	// to the keepExistingBuildFile allowlist.
+	excludes = append(excludes, "prebuilts/clang/host/linux-x86/clang-dev")
+
 	return excludes
 }
 
diff --git a/java/java.go b/java/java.go
index 6eeb95d..e37a77e 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1662,7 +1662,7 @@
 	var srcFiles []android.Path
 	ctx.VisitDirectDepsWithTag(javaApiContributionTag, func(dep android.Module) {
 		provider := ctx.OtherModuleProvider(dep, JavaApiImportProvider).(JavaApiImportInfo)
-		srcFiles = append(srcFiles, android.PathForModuleSrc(ctx, provider.ApiFile.String()))
+		srcFiles = append(srcFiles, android.PathForSource(ctx, provider.ApiFile.String()))
 	})
 
 	cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir)
@@ -1687,6 +1687,8 @@
 
 	TransformJavaToClasses(ctx, al.stubsJar, 0, android.Paths{},
 		android.Paths{al.stubsSrcJar}, flags, android.Paths{})
+
+	ctx.Phony(ctx.ModuleName(), al.stubsJar)
 }
 
 //
@@ -2620,7 +2622,7 @@
 	if m.properties.Libs != nil {
 
 		// TODO 244210934 ALIX Check if this else statement breaks presubmits get rid of it if it doesn't
-		if strings.HasPrefix(ctx.ModuleType(), "java_binary") {
+		if strings.HasPrefix(ctx.ModuleType(), "java_binary") || strings.HasPrefix(ctx.ModuleType(), "java_library") {
 			for _, d := range m.properties.Libs {
 				neverlinkLabel := android.BazelLabelForModuleDepSingle(ctx, d)
 				neverlinkLabel.Label = neverlinkLabel.Label + "-neverlink"
@@ -2688,12 +2690,21 @@
 		Deps:                 deps,
 		Exports:              depLabels.StaticDeps,
 	}
+	name := m.Name()
 
 	if !bp2BuildInfo.hasKotlinSrcs && len(m.properties.Common_srcs) == 0 {
 		props = bazel.BazelTargetModuleProperties{
 			Rule_class:        "java_library",
 			Bzl_load_location: "//build/bazel/rules/java:library.bzl",
 		}
+
+		ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
+		neverlinkProp := true
+		neverLinkAttrs := &javaLibraryAttributes{
+			Exports:   bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}),
+			Neverlink: bazel.BoolAttribute{Value: &neverlinkProp},
+		}
+		ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name + "-neverlink"}, neverLinkAttrs)
 	} else {
 		attrs.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs))
 
@@ -2701,10 +2712,10 @@
 			Rule_class:        "kt_jvm_library",
 			Bzl_load_location: "@rules_kotlin//kotlin:jvm_library.bzl",
 		}
+		// TODO (b/244210934): create neverlink-duplicate target once kt_jvm_library supports neverlink attribute
+		ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
 	}
 
-	name := m.Name()
-	ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
 }
 
 type javaBinaryHostAttributes struct {