Merge "rust: Prevent manually defined lib link flags."
diff --git a/android/bazel.go b/android/bazel.go
index 75b13c9..26e7deb 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -163,6 +163,8 @@
 		"system/core/property_service/libpropertyinfoparser": Bp2BuildDefaultTrueRecursively,
 		"system/libbase":                  Bp2BuildDefaultTrueRecursively,
 		"system/logging/liblog":           Bp2BuildDefaultTrueRecursively,
+		"system/timezone/apex":            Bp2BuildDefaultTrueRecursively,
+		"system/timezone/output_data":     Bp2BuildDefaultTrueRecursively,
 		"external/jemalloc_new":           Bp2BuildDefaultTrueRecursively,
 		"external/fmtlib":                 Bp2BuildDefaultTrueRecursively,
 		"external/arm-optimized-routines": Bp2BuildDefaultTrueRecursively,
diff --git a/android/module.go b/android/module.go
index 84e78d1..5e2e06a 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1529,7 +1529,7 @@
 	var installDeps []*installPathsDepSet
 	var packagingSpecs []*packagingSpecsDepSet
 	ctx.VisitDirectDeps(func(dep Module) {
-		if IsInstallDepNeeded(ctx.OtherModuleDependencyTag(dep)) && !dep.IsHideFromMake() {
+		if IsInstallDepNeeded(ctx.OtherModuleDependencyTag(dep)) && !dep.IsHideFromMake() && !dep.IsSkipInstall() {
 			installDeps = append(installDeps, dep.base().installFilesDepSet)
 			packagingSpecs = append(packagingSpecs, dep.base().packagingSpecsDepSet)
 		}
diff --git a/android/packaging_test.go b/android/packaging_test.go
index f91dc5d..ff7446c 100644
--- a/android/packaging_test.go
+++ b/android/packaging_test.go
@@ -18,13 +18,15 @@
 	"testing"
 
 	"github.com/google/blueprint"
+	"github.com/google/blueprint/proptools"
 )
 
 // Module to be packaged
 type componentTestModule struct {
 	ModuleBase
 	props struct {
-		Deps []string
+		Deps         []string
+		Skip_install *bool
 	}
 }
 
@@ -49,6 +51,9 @@
 	builtFile := PathForModuleOut(ctx, m.Name())
 	dir := ctx.Target().Arch.ArchType.Multilib
 	installDir := PathForModuleInstall(ctx, dir)
+	if proptools.Bool(m.props.Skip_install) {
+		m.SkipInstall()
+	}
 	ctx.InstallFile(installDir, m.Name(), builtFile)
 }
 
@@ -365,3 +370,31 @@
 		}
 		`, []string{"lib64/foo"})
 }
+
+func TestPackagingWithSkipInstallDeps(t *testing.T) {
+	// package -[dep]-> foo -[dep]-> bar      -[dep]-> baz
+	//                  OK           SKIPPED
+	multiTarget := false
+	runPackagingTest(t, multiTarget,
+		`
+		component {
+			name: "foo",
+			deps: ["bar"],
+		}
+
+		component {
+			name: "bar",
+			deps: ["baz"],
+			skip_install: true,
+		}
+
+		component {
+			name: "baz",
+		}
+
+		package_module {
+			name: "package",
+			deps: ["foo"],
+		}
+		`, []string{"lib64/foo"})
+}
diff --git a/apex/apex.go b/apex/apex.go
index 0857946..149f782 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -3197,6 +3197,7 @@
 	Installable        bazel.BoolAttribute
 	Native_shared_libs bazel.LabelListAttribute
 	Binaries           bazel.StringListAttribute
+	Prebuilts          bazel.LabelListAttribute
 }
 
 type bazelApexBundle struct {
@@ -3262,6 +3263,10 @@
 	nativeSharedLibsLabelList := android.BazelLabelForModuleDeps(ctx, nativeSharedLibs)
 	nativeSharedLibsLabelListAttribute := bazel.MakeLabelListAttribute(nativeSharedLibsLabelList)
 
+	prebuilts := module.properties.Prebuilts
+	prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
+	prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
+
 	binaries := module.properties.ApexNativeDependencies.Binaries
 	binariesStringListAttribute := bazel.MakeStringListAttribute(binaries)
 
@@ -3286,6 +3291,7 @@
 		Installable:        installableAttribute,
 		Native_shared_libs: nativeSharedLibsLabelListAttribute,
 		Binaries:           binariesStringListAttribute,
+		Prebuilts:          prebuiltsLabelListAttribute,
 	}
 
 	props := bazel.BazelTargetModuleProperties{
diff --git a/apex/key.go b/apex/key.go
index 4bd0dc4..32a7ce1 100644
--- a/apex/key.go
+++ b/apex/key.go
@@ -20,6 +20,7 @@
 	"strings"
 
 	"android/soong/android"
+	"android/soong/bazel"
 
 	"github.com/google/blueprint/proptools"
 )
@@ -33,6 +34,8 @@
 func registerApexKeyBuildComponents(ctx android.RegistrationContext) {
 	ctx.RegisterModuleType("apex_key", ApexKeyFactory)
 	ctx.RegisterSingletonType("apex_keys_text", apexKeysTextFactory)
+
+	android.RegisterBp2BuildMutator("apex_key", ApexKeyBp2Build)
 }
 
 type apexKey struct {
@@ -192,3 +195,68 @@
 func (s *apexKeysText) MakeVars(ctx android.MakeVarsContext) {
 	ctx.Strict("SOONG_APEX_KEYS_FILE", s.output.String())
 }
+
+// For Bazel / bp2build
+
+type bazelApexKeyAttributes struct {
+	Public_key  bazel.LabelAttribute
+	Private_key bazel.LabelAttribute
+}
+
+type bazelApexKey struct {
+	android.BazelTargetModuleBase
+	bazelApexKeyAttributes
+}
+
+func BazelApexKeyFactory() android.Module {
+	module := &bazelApexKey{}
+	module.AddProperties(&module.bazelApexKeyAttributes)
+	android.InitBazelTargetModule(module)
+	return module
+}
+
+func ApexKeyBp2Build(ctx android.TopDownMutatorContext) {
+	module, ok := ctx.Module().(*apexKey)
+	if !ok {
+		// Not an APEX key
+		return
+	}
+	if !module.ConvertWithBp2build(ctx) {
+		return
+	}
+	if ctx.ModuleType() != "apex_key" {
+		return
+	}
+
+	apexKeyBp2BuildInternal(ctx, module)
+}
+
+func apexKeyBp2BuildInternal(ctx android.TopDownMutatorContext, module *apexKey) {
+	var privateKeyLabelAttribute bazel.LabelAttribute
+	if module.properties.Private_key != nil {
+		privateKeyLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Private_key))
+	}
+
+	var publicKeyLabelAttribute bazel.LabelAttribute
+	if module.properties.Public_key != nil {
+		publicKeyLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Public_key))
+	}
+
+	attrs := &bazelApexKeyAttributes{
+		Private_key: privateKeyLabelAttribute,
+		Public_key:  publicKeyLabelAttribute,
+	}
+
+	props := bazel.BazelTargetModuleProperties{
+		Rule_class:        "apex_key",
+		Bzl_load_location: "//build/bazel/rules:apex_key.bzl",
+	}
+
+	ctx.CreateBazelTargetModule(BazelApexKeyFactory, module.Name(), props, attrs)
+}
+
+func (m *bazelApexKey) Name() string {
+	return m.BaseModuleName()
+}
+
+func (m *bazelApexKey) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
diff --git a/bp2build/Android.bp b/bp2build/Android.bp
index dded14b..9ec637a 100644
--- a/bp2build/Android.bp
+++ b/bp2build/Android.bp
@@ -23,12 +23,15 @@
         "soong-bazel",
         "soong-cc",
         "soong-cc-config",
+        "soong-etc",
         "soong-genrule",
         "soong-python",
         "soong-sh",
     ],
     testSrcs: [
+        "android_app_certificate_conversion_test.go",
         "apex_conversion_test.go",
+        "apex_key_conversion_test.go",
         "build_conversion_test.go",
         "bzl_conversion_test.go",
         "cc_library_conversion_test.go",
@@ -36,6 +39,7 @@
         "cc_library_static_conversion_test.go",
         "cc_object_conversion_test.go",
         "conversion_test.go",
+        "prebuilt_etc_conversion_test.go",
         "python_binary_conversion_test.go",
         "sh_conversion_test.go",
         "testing.go",
diff --git a/bp2build/android_app_certificate_conversion_test.go b/bp2build/android_app_certificate_conversion_test.go
new file mode 100644
index 0000000..022c687
--- /dev/null
+++ b/bp2build/android_app_certificate_conversion_test.go
@@ -0,0 +1,49 @@
+// 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/java"
+
+	"testing"
+)
+
+func runAndroidAppCertificateTestCase(t *testing.T, tc bp2buildTestCase) {
+	t.Helper()
+	runBp2BuildTestCase(t, registerAndroidAppCertificateModuleTypes, tc)
+}
+
+func registerAndroidAppCertificateModuleTypes(ctx android.RegistrationContext) {
+}
+
+func TestAndroidAppCertificateSimple(t *testing.T) {
+	runAndroidAppCertificateTestCase(t, bp2buildTestCase{
+		description:                        "Android app certificate - simple example",
+		moduleTypeUnderTest:                "android_app_certificate",
+		moduleTypeUnderTestFactory:         java.AndroidAppCertificateFactory,
+		moduleTypeUnderTestBp2BuildMutator: java.AndroidAppCertificateBp2Build,
+		filesystem:                         map[string]string{},
+		blueprint: `
+android_app_certificate {
+        name: "com.android.apogee.cert",
+        certificate: "chamber_of_secrets_dir",
+}
+`,
+		expectedBazelTargets: []string{`android_app_certificate(
+    name = "com.android.apogee.cert",
+    certificate = "chamber_of_secrets_dir",
+)`}})
+}
diff --git a/bp2build/apex_conversion_test.go b/bp2build/apex_conversion_test.go
index e2e08bd..456f18a 100644
--- a/bp2build/apex_conversion_test.go
+++ b/bp2build/apex_conversion_test.go
@@ -69,6 +69,18 @@
 	bazel_module: { bp2build_available: false },
 }
 
+// TODO(b/194878861): Add bp2build support for prebuilt_etc
+cc_library {
+        name: "pretend_prebuilt_1",
+        bazel_module: { bp2build_available: false },
+}
+
+// TODO(b/194878861): Add bp2build support for prebuilt_etc
+cc_library {
+        name: "pretend_prebuilt_2",
+        bazel_module: { bp2build_available: false },
+}
+
 filegroup {
 	name: "com.android.apogee-file_contexts",
         srcs: [
@@ -95,6 +107,10 @@
             "binary_1",
 	    "binary_2",
 	],
+	prebuilts: [
+	    "pretend_prebuilt_1",
+	    "pretend_prebuilt_2",
+	],
 }
 `,
 		expectedBazelTargets: []string{`apex(
@@ -114,6 +130,10 @@
         ":native_shared_lib_1",
         ":native_shared_lib_2",
     ],
+    prebuilts = [
+        ":pretend_prebuilt_1",
+        ":pretend_prebuilt_2",
+    ],
     updatable = False,
 )`}})
 }
diff --git a/bp2build/apex_key_conversion_test.go b/bp2build/apex_key_conversion_test.go
new file mode 100644
index 0000000..8e1aa09
--- /dev/null
+++ b/bp2build/apex_key_conversion_test.go
@@ -0,0 +1,51 @@
+// 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/apex"
+
+	"testing"
+)
+
+func runApexKeyTestCase(t *testing.T, tc bp2buildTestCase) {
+	t.Helper()
+	runBp2BuildTestCase(t, registerApexKeyModuleTypes, tc)
+}
+
+func registerApexKeyModuleTypes(ctx android.RegistrationContext) {
+}
+
+func TestApexKeySimple(t *testing.T) {
+	runApexKeyTestCase(t, bp2buildTestCase{
+		description:                        "apex key - simple example",
+		moduleTypeUnderTest:                "apex_key",
+		moduleTypeUnderTestFactory:         apex.ApexKeyFactory,
+		moduleTypeUnderTestBp2BuildMutator: apex.ApexKeyBp2Build,
+		filesystem:                         map[string]string{},
+		blueprint: `
+apex_key {
+        name: "com.android.apogee.key",
+        public_key: "com.android.apogee.avbpubkey",
+        private_key: "com.android.apogee.pem",
+}
+`,
+		expectedBazelTargets: []string{`apex_key(
+    name = "com.android.apogee.key",
+    private_key = "com.android.apogee.pem",
+    public_key = "com.android.apogee.avbpubkey",
+)`}})
+}
diff --git a/bp2build/prebuilt_etc_conversion_test.go b/bp2build/prebuilt_etc_conversion_test.go
new file mode 100644
index 0000000..4e25d1b
--- /dev/null
+++ b/bp2build/prebuilt_etc_conversion_test.go
@@ -0,0 +1,55 @@
+// 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/etc"
+
+	"testing"
+)
+
+func runPrebuiltEtcTestCase(t *testing.T, tc bp2buildTestCase) {
+	t.Helper()
+	runBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc)
+}
+
+func registerPrebuiltEtcModuleTypes(ctx android.RegistrationContext) {
+}
+
+func TestPrebuiltEtcSimple(t *testing.T) {
+	runPrebuiltEtcTestCase(t, bp2buildTestCase{
+		description:                        "prebuilt_etc - simple example",
+		moduleTypeUnderTest:                "prebuilt_etc",
+		moduleTypeUnderTestFactory:         etc.PrebuiltEtcFactory,
+		moduleTypeUnderTestBp2BuildMutator: etc.PrebuiltEtcBp2Build,
+		filesystem:                         map[string]string{},
+		blueprint: `
+prebuilt_etc {
+    name: "apex_tz_version",
+    src: "version/tz_version",
+    filename: "tz_version",
+    sub_dir: "tz",
+    installable: false,
+}
+`,
+		expectedBazelTargets: []string{`prebuilt_etc(
+    name = "apex_tz_version",
+    filename = "tz_version",
+    installable = False,
+    src = "version/tz_version",
+    sub_dir = "tz",
+)`}})
+}
diff --git a/cc/config/x86_darwin_host.go b/cc/config/x86_darwin_host.go
index d8e70e1..23fe1ab 100644
--- a/cc/config/x86_darwin_host.go
+++ b/cc/config/x86_darwin_host.go
@@ -49,6 +49,7 @@
 		"-Wl,-syslibroot,${macSdkRoot}",
 		"-mmacosx-version-min=${macMinVersion}",
 		"-m64",
+		"-mlinker-version=305",
 	}
 
 	darwinSupportedSdkVersions = []string{
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index d4ab4bc..7a74506 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -49,10 +49,10 @@
 
 	ArtApexJars android.ConfiguredJarList // modules for jars that are in the ART APEX
 
-	SystemServerJars          android.ConfiguredJarList // jars that form the system server
-	SystemServerApps          []string                  // apps that are loaded into system server
-	UpdatableSystemServerJars android.ConfiguredJarList // jars within apex that are loaded into system server
-	SpeedApps                 []string                  // apps that should be speed optimized
+	SystemServerJars     android.ConfiguredJarList // jars that form the system server
+	SystemServerApps     []string                  // apps that are loaded into system server
+	ApexSystemServerJars android.ConfiguredJarList // jars within apex that are loaded into system server
+	SpeedApps            []string                  // apps that should be speed optimized
 
 	BrokenSuboptimalOrderOfSystemServerJars bool // if true, sub-optimal order does not cause a build error
 
@@ -618,7 +618,7 @@
 		ArtApexJars:                        android.EmptyConfiguredJarList(),
 		SystemServerJars:                   android.EmptyConfiguredJarList(),
 		SystemServerApps:                   nil,
-		UpdatableSystemServerJars:          android.EmptyConfiguredJarList(),
+		ApexSystemServerJars:               android.EmptyConfiguredJarList(),
 		SpeedApps:                          nil,
 		PreoptFlags:                        nil,
 		DefaultCompilerFilter:              "",
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go
index da015a3..4c6ae82 100644
--- a/dexpreopt/dexpreopt.go
+++ b/dexpreopt/dexpreopt.go
@@ -111,7 +111,7 @@
 	}
 
 	// Don't preopt system server jars that are updatable.
-	if global.UpdatableSystemServerJars.ContainsJar(module.Name) {
+	if global.ApexSystemServerJars.ContainsJar(module.Name) {
 		return true
 	}
 
@@ -234,7 +234,7 @@
 
 	invocationPath := odexPath.ReplaceExtension(ctx, "invocation")
 
-	systemServerJars := NonUpdatableSystemServerJars(ctx, global)
+	systemServerJars := NonApexSystemServerJars(ctx, global)
 
 	rule.Command().FlagWithArg("mkdir -p ", filepath.Dir(odexPath.String()))
 	rule.Command().FlagWithOutput("rm -f ", odexPath)
@@ -523,13 +523,13 @@
 	}
 }
 
-var nonUpdatableSystemServerJarsKey = android.NewOnceKey("nonUpdatableSystemServerJars")
+var nonApexSystemServerJarsKey = android.NewOnceKey("nonApexSystemServerJars")
 
 // TODO: eliminate the superficial global config parameter by moving global config definition
 // from java subpackage to dexpreopt.
-func NonUpdatableSystemServerJars(ctx android.PathContext, global *GlobalConfig) []string {
-	return ctx.Config().Once(nonUpdatableSystemServerJarsKey, func() interface{} {
-		return android.RemoveListFromList(global.SystemServerJars.CopyOfJars(), global.UpdatableSystemServerJars.CopyOfJars())
+func NonApexSystemServerJars(ctx android.PathContext, global *GlobalConfig) []string {
+	return ctx.Config().Once(nonApexSystemServerJarsKey, func() interface{} {
+		return android.RemoveListFromList(global.SystemServerJars.CopyOfJars(), global.ApexSystemServerJars.CopyOfJars())
 	}).([]string)
 }
 
@@ -556,7 +556,7 @@
 	mctx, isModule := ctx.(android.ModuleContext)
 	if isModule {
 		config := GetGlobalConfig(ctx)
-		jars := NonUpdatableSystemServerJars(ctx, config)
+		jars := NonApexSystemServerJars(ctx, config)
 		mctx.WalkDeps(func(dep android.Module, parent android.Module) bool {
 			depIndex := android.IndexList(dep.Name(), jars)
 			if jarIndex < depIndex && !config.BrokenSuboptimalOrderOfSystemServerJars {
diff --git a/etc/Android.bp b/etc/Android.bp
index 06a2fa1..c670236 100644
--- a/etc/Android.bp
+++ b/etc/Android.bp
@@ -13,9 +13,11 @@
     ],
     srcs: [
         "prebuilt_etc.go",
+        "snapshot_etc.go",
     ],
     testSrcs: [
         "prebuilt_etc_test.go",
+        "snapshot_etc_test.go",
     ],
     pluginFor: ["soong_build"],
 }
diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go
index 4107916..8aeb0dd 100644
--- a/etc/prebuilt_etc.go
+++ b/etc/prebuilt_etc.go
@@ -36,6 +36,7 @@
 	"github.com/google/blueprint/proptools"
 
 	"android/soong/android"
+	"android/soong/bazel"
 	"android/soong/snapshot"
 )
 
@@ -61,6 +62,8 @@
 	ctx.RegisterModuleType("prebuilt_rfsa", PrebuiltRFSAFactory)
 
 	ctx.RegisterModuleType("prebuilt_defaults", defaultsFactory)
+
+	android.RegisterBp2BuildMutator("prebuilt_etc", PrebuiltEtcBp2Build)
 }
 
 var PrepareForTestWithPrebuiltEtc = android.FixtureRegisterWithContext(RegisterPrebuiltEtcBuildComponents)
@@ -131,6 +134,7 @@
 type PrebuiltEtc struct {
 	android.ModuleBase
 	android.DefaultableModuleBase
+	android.BazelModuleBase
 
 	snapshot.VendorSnapshotModuleInterface
 	snapshot.RecoverySnapshotModuleInterface
@@ -406,6 +410,7 @@
 	// This module is device-only
 	android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
 	android.InitDefaultableModule(module)
+	android.InitBazelModule(module)
 	return module
 }
 
@@ -647,3 +652,82 @@
 
 	return snapshotOutputs
 }
+
+// For Bazel / bp2build
+
+type bazelPrebuiltEtcAttributes struct {
+	Src         bazel.LabelAttribute
+	Filename    string
+	Sub_dir     string
+	Installable bazel.BoolAttribute
+}
+
+type bazelPrebuiltEtc struct {
+	android.BazelTargetModuleBase
+	bazelPrebuiltEtcAttributes
+}
+
+func BazelPrebuiltEtcFactory() android.Module {
+	module := &bazelPrebuiltEtc{}
+	module.AddProperties(&module.bazelPrebuiltEtcAttributes)
+	android.InitBazelTargetModule(module)
+	return module
+}
+
+func PrebuiltEtcBp2Build(ctx android.TopDownMutatorContext) {
+	module, ok := ctx.Module().(*PrebuiltEtc)
+	if !ok {
+		// Not an prebuilt_etc
+		return
+	}
+	if !module.ConvertWithBp2build(ctx) {
+		return
+	}
+	if ctx.ModuleType() != "prebuilt_etc" {
+		return
+	}
+
+	prebuiltEtcBp2BuildInternal(ctx, module)
+}
+
+func prebuiltEtcBp2BuildInternal(ctx android.TopDownMutatorContext, module *PrebuiltEtc) {
+	var srcLabelAttribute bazel.LabelAttribute
+	if module.properties.Src != nil {
+		srcLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *module.properties.Src))
+	}
+
+	var filename string
+	if module.properties.Filename != nil {
+		filename = *module.properties.Filename
+	}
+
+	var subDir string
+	if module.subdirProperties.Sub_dir != nil {
+		subDir = *module.subdirProperties.Sub_dir
+	}
+
+	var installableBoolAttribute bazel.BoolAttribute
+	if module.properties.Installable != nil {
+		installableBoolAttribute.Value = module.properties.Installable
+	}
+
+	attrs := &bazelPrebuiltEtcAttributes{
+		Src:         srcLabelAttribute,
+		Filename:    filename,
+		Sub_dir:     subDir,
+		Installable: installableBoolAttribute,
+	}
+
+	props := bazel.BazelTargetModuleProperties{
+		Rule_class:        "prebuilt_etc",
+		Bzl_load_location: "//build/bazel/rules:prebuilt_etc.bzl",
+	}
+
+	ctx.CreateBazelTargetModule(BazelPrebuiltEtcFactory, module.Name(), props, attrs)
+}
+
+func (m *bazelPrebuiltEtc) Name() string {
+	return m.BaseModuleName()
+}
+
+func (m *bazelPrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
diff --git a/etc/snapshot_etc.go b/etc/snapshot_etc.go
new file mode 100644
index 0000000..9a25d5a
--- /dev/null
+++ b/etc/snapshot_etc.go
@@ -0,0 +1,186 @@
+// Copyright 2021 The Android Open Source Project
+//
+// 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 etc
+
+// This file implements snapshot module of 'prebuilt_etc' type
+// 'snapshot_etc' module defines android.PrebuiltInterface so it can be handled
+// as prebuilt of 'prebuilt_etc' type.
+// Properties of 'snapshot_etc' follows properties from snapshotJsonFlags type
+
+import (
+	"android/soong/android"
+	"fmt"
+	"strings"
+
+	"github.com/google/blueprint"
+	"github.com/google/blueprint/proptools"
+)
+
+func RegisterSnapshotEtcModule(ctx android.RegistrationContext) {
+	ctx.RegisterModuleType("snapshot_etc", SnapshotEtcFactory)
+}
+
+func init() {
+	RegisterSnapshotEtcModule(android.InitRegistrationContext)
+}
+
+// snapshot_etc is a prebuilt module type to be installed under etc which is auto-generated by
+// development/vendor_snapshot/update.py. This module will override prebuilt_etc module with same
+// name when 'prefer' property is true.
+func SnapshotEtcFactory() android.Module {
+	module := &SnapshotEtc{}
+	module.AddProperties(&module.properties)
+
+	var srcsSupplier = func(_ android.BaseModuleContext, prebuilt android.Module) []string {
+		s, ok := prebuilt.(*SnapshotEtc)
+		if !ok || s.properties.Src == nil {
+			return []string{}
+		}
+
+		return []string{*s.properties.Src}
+	}
+
+	android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst)
+	android.InitPrebuiltModuleWithSrcSupplier(module, srcsSupplier, "src")
+	return module
+}
+
+type snapshotEtcProperties struct {
+	Src                   *string `android:"path,arch_variant"` // Source of snapshot_etc file
+	Filename              *string `android:"arch_variant"`      // Target file name when it differs from module name
+	Relative_install_path *string `android:"arch_variant"`      // Relative install path when it should be installed subdirectory of etc
+}
+
+type SnapshotEtc struct {
+	android.ModuleBase
+	prebuilt   android.Prebuilt
+	properties snapshotEtcProperties
+
+	outputFilePath android.OutputPath
+	installDirPath android.InstallPath
+}
+
+func (s *SnapshotEtc) Prebuilt() *android.Prebuilt {
+	return &s.prebuilt
+}
+
+func (s *SnapshotEtc) Name() string {
+	return s.prebuilt.Name(s.BaseModuleName())
+}
+
+func (s *SnapshotEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+	if s.properties.Src == nil {
+		ctx.PropertyErrorf("src", "missing prebuilt source file")
+		return
+	}
+
+	sourceFilePath := s.prebuilt.SingleSourcePath(ctx)
+
+	// Determine the output file basename.
+	// If Filename is set, use the name specified by the property.
+	// Otherwise use the module name.
+	filename := proptools.String(s.properties.Filename)
+	if filename == "" {
+		filename = ctx.ModuleName()
+	}
+
+	s.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
+
+	if strings.Contains(filename, "/") {
+		ctx.PropertyErrorf("filename", "filename cannot contain separator '/'")
+		return
+	}
+
+	subDir := ""
+	if s.properties.Relative_install_path != nil {
+		subDir = *s.properties.Relative_install_path
+	}
+
+	s.installDirPath = android.PathForModuleInstall(ctx, "etc", subDir)
+
+	// This ensures that outputFilePath has the correct name for others to
+	// use, as the source file may have a different name.
+	ctx.Build(pctx, android.BuildParams{
+		Rule:        android.Cp,
+		Input:       sourceFilePath,
+		Output:      s.outputFilePath,
+		Description: "Install snapshot etc module " + s.BaseModuleName(),
+	})
+
+	ctx.InstallFile(s.installDirPath, s.outputFilePath.Base(), sourceFilePath)
+}
+
+func (p *SnapshotEtc) AndroidMkEntries() []android.AndroidMkEntries {
+	return []android.AndroidMkEntries{{
+		Class:      "ETC",
+		OutputFile: android.OptionalPathForPath(p.outputFilePath),
+		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
+			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
+				entries.SetString("LOCAL_MODULE_TAGS", "optional")
+				entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String())
+				entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
+			},
+		},
+	}}
+}
+
+type snapshotEtcDependencyTag struct {
+	blueprint.DependencyTag
+}
+
+var tag = snapshotEtcDependencyTag{}
+
+func (s *SnapshotEtc) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
+	return !s.ModuleBase.InstallInRecovery() && !s.ModuleBase.InstallInRamdisk() &&
+		!s.ModuleBase.InstallInVendorRamdisk() && !s.ModuleBase.InstallInDebugRamdisk()
+}
+
+func (p *SnapshotEtc) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
+	return p.ModuleBase.InstallInRamdisk()
+}
+
+func (p *SnapshotEtc) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
+	return p.ModuleBase.InstallInVendorRamdisk()
+}
+
+func (p *SnapshotEtc) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
+	return p.ModuleBase.InstallInDebugRamdisk()
+}
+
+func (p *SnapshotEtc) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
+	return p.ModuleBase.InstallInRecovery()
+}
+
+func (p *SnapshotEtc) ExtraImageVariations(ctx android.BaseModuleContext) []string {
+	return nil
+}
+
+func (p *SnapshotEtc) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
+}
+
+func (p *SnapshotEtc) ImageMutatorBegin(ctx android.BaseModuleContext) {}
+
+func (p *SnapshotEtc) 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)
+	}
+
+}
+
+var _ android.PrebuiltInterface = (*SnapshotEtc)(nil)
+var _ android.ImageInterface = (*SnapshotEtc)(nil)
+var _ android.OutputFileProducer = (*SnapshotEtc)(nil)
diff --git a/etc/snapshot_etc_test.go b/etc/snapshot_etc_test.go
new file mode 100644
index 0000000..b9d5504
--- /dev/null
+++ b/etc/snapshot_etc_test.go
@@ -0,0 +1,185 @@
+// Copyright 2021 The Android Open Source Project
+//
+// 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 etc
+
+import (
+	"android/soong/android"
+	"testing"
+
+	"github.com/google/blueprint"
+)
+
+var registerSourceModule = func(ctx android.RegistrationContext) {
+	ctx.RegisterModuleType("source", newSourceModule)
+}
+
+type sourceModuleProperties struct {
+	Deps []string `android:"path,arch_variant"`
+}
+
+type sourceModule struct {
+	android.ModuleBase
+	android.OverridableModuleBase
+
+	properties                                     sourceModuleProperties
+	dependsOnSourceModule, dependsOnPrebuiltModule bool
+	deps                                           android.Paths
+	src                                            android.Path
+}
+
+func newSourceModule() android.Module {
+	m := &sourceModule{}
+	m.AddProperties(&m.properties)
+	android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibFirst)
+	android.InitOverridableModule(m, nil)
+	return m
+}
+
+func (s *sourceModule) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
+	// s.properties.Deps are annotated with android:path, so they are
+	// automatically added to the dependency by pathDeps mutator
+}
+
+func (s *sourceModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+	s.deps = android.PathsForModuleSrc(ctx, s.properties.Deps)
+	s.src = android.PathForModuleSrc(ctx, "source_file")
+}
+
+func (s *sourceModule) Srcs() android.Paths {
+	return android.Paths{s.src}
+}
+
+var prepareForSnapshotEtcTest = android.GroupFixturePreparers(
+	android.PrepareForTestWithArchMutator,
+	android.PrepareForTestWithPrebuilts,
+	PrepareForTestWithPrebuiltEtc,
+	android.FixtureRegisterWithContext(RegisterSnapshotEtcModule),
+	android.FixtureRegisterWithContext(registerSourceModule),
+	android.FixtureMergeMockFs(android.MockFS{
+		"foo.conf": nil,
+		"bar.conf": nil,
+	}),
+)
+
+func TestSnapshotWithFilename(t *testing.T) {
+	var androidBp = `
+	snapshot_etc {
+		name: "etc_module",
+		src: "foo.conf",
+		filename: "bar.conf",
+	}
+	`
+
+	result := prepareForSnapshotEtcTest.RunTestWithBp(t, androidBp)
+	for _, variant := range result.ModuleVariantsForTests("etc_module") {
+		module := result.ModuleForTests("etc_module", variant)
+		s, ok := module.Module().(*SnapshotEtc)
+		if !ok {
+			t.Errorf("Expected snapshot_etc module type")
+		}
+		if s.outputFilePath.Base() != "bar.conf" {
+			t.Errorf("Output file path does not match with specified filename")
+		}
+	}
+}
+
+func TestSnapshotEtcWithOrigin(t *testing.T) {
+	var androidBp = `
+	prebuilt_etc {
+		name: "etc_module",
+		src: "foo.conf",
+	}
+
+	snapshot_etc {
+		name: "etc_module",
+		src: "bar.conf",
+	}
+
+	source {
+		name: "source",
+		deps: [":etc_module"],
+	}
+	`
+
+	result := prepareForSnapshotEtcTest.RunTestWithBp(t, androidBp)
+
+	for _, variant := range result.ModuleVariantsForTests("source") {
+		source := result.ModuleForTests("source", variant)
+
+		result.VisitDirectDeps(source.Module(), func(m blueprint.Module) {
+			if _, ok := m.(*PrebuiltEtc); !ok {
+				t.Errorf("Original prebuilt_etc module expected.")
+			}
+		})
+	}
+}
+
+func TestSnapshotEtcWithOriginAndPrefer(t *testing.T) {
+	var androidBp = `
+	prebuilt_etc {
+		name: "etc_module",
+		src: "foo.conf",
+	}
+
+	snapshot_etc {
+		name: "etc_module",
+		src: "bar.conf",
+		prefer: true,
+	}
+
+	source {
+		name: "source",
+		deps: [":etc_module"],
+	}
+	`
+
+	result := prepareForSnapshotEtcTest.RunTestWithBp(t, androidBp)
+
+	for _, variant := range result.ModuleVariantsForTests("source") {
+		source := result.ModuleForTests("source", variant)
+
+		result.VisitDirectDeps(source.Module(), func(m blueprint.Module) {
+			if _, ok := m.(*SnapshotEtc); !ok {
+				t.Errorf("Preferred snapshot_etc module expected.")
+			}
+		})
+	}
+}
+
+func TestSnapshotEtcWithoutOrigin(t *testing.T) {
+	var androidBp = `
+	snapshot_etc {
+		name: "etc_module",
+		src: "bar.conf",
+	}
+
+	source {
+		name: "source",
+		deps: [":etc_module"],
+	}
+	`
+
+	result := prepareForSnapshotEtcTest.RunTestWithBp(t, androidBp)
+
+	for _, variant := range result.ModuleVariantsForTests("source") {
+		source := result.ModuleForTests("source", variant)
+
+		result.VisitDirectDeps(source.Module(), func(m blueprint.Module) {
+			if _, ok := m.(*SnapshotEtc); !ok {
+				t.Errorf("Only source snapshot_etc module expected.")
+			}
+		})
+	}
+}
diff --git a/java/Android.bp b/java/Android.bp
index e5b8f96..9ffa123 100644
--- a/java/Android.bp
+++ b/java/Android.bp
@@ -10,6 +10,7 @@
         "blueprint-pathtools",
         "soong",
         "soong-android",
+        "soong-bazel",
         "soong-cc",
         "soong-dexpreopt",
         "soong-genrule",
diff --git a/java/app.go b/java/app.go
index c69210f..35ed27f 100755
--- a/java/app.go
+++ b/java/app.go
@@ -26,6 +26,7 @@
 	"github.com/google/blueprint/proptools"
 
 	"android/soong/android"
+	"android/soong/bazel"
 	"android/soong/cc"
 	"android/soong/dexpreopt"
 	"android/soong/tradefed"
@@ -42,6 +43,8 @@
 	ctx.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory)
 	ctx.RegisterModuleType("override_android_app", OverrideAndroidAppModuleFactory)
 	ctx.RegisterModuleType("override_android_test", OverrideAndroidTestModuleFactory)
+
+	android.RegisterBp2BuildMutator("android_app_certificate", AndroidAppCertificateBp2Build)
 }
 
 // AndroidManifest.xml merging
@@ -1371,3 +1374,61 @@
 	outputFile := android.PathForModuleOut(ctx, "verify_uses_libraries", apk.Base())
 	return outputFile
 }
+
+// For Bazel / bp2build
+
+type bazelAndroidAppCertificateAttributes struct {
+	Certificate string
+}
+
+type bazelAndroidAppCertificate struct {
+	android.BazelTargetModuleBase
+	bazelAndroidAppCertificateAttributes
+}
+
+func BazelAndroidAppCertificateFactory() android.Module {
+	module := &bazelAndroidAppCertificate{}
+	module.AddProperties(&module.bazelAndroidAppCertificateAttributes)
+	android.InitBazelTargetModule(module)
+	return module
+}
+
+func AndroidAppCertificateBp2Build(ctx android.TopDownMutatorContext) {
+	module, ok := ctx.Module().(*AndroidAppCertificate)
+	if !ok {
+		// Not an Android app certificate
+		return
+	}
+	if !module.ConvertWithBp2build(ctx) {
+		return
+	}
+	if ctx.ModuleType() != "android_app_certificate" {
+		return
+	}
+
+	androidAppCertificateBp2BuildInternal(ctx, module)
+}
+
+func androidAppCertificateBp2BuildInternal(ctx android.TopDownMutatorContext, module *AndroidAppCertificate) {
+	var certificate string
+	if module.properties.Certificate != nil {
+		certificate = *module.properties.Certificate
+	}
+
+	attrs := &bazelAndroidAppCertificateAttributes{
+		Certificate: certificate,
+	}
+
+	props := bazel.BazelTargetModuleProperties{
+		Rule_class:        "android_app_certificate",
+		Bzl_load_location: "//build/bazel/rules:android_app_certificate.bzl",
+	}
+
+	ctx.CreateBazelTargetModule(BazelAndroidAppCertificateFactory, module.Name(), props, attrs)
+}
+
+func (m *bazelAndroidAppCertificate) Name() string {
+	return m.BaseModuleName()
+}
+
+func (m *bazelAndroidAppCertificate) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go
index dfe90ba..6c2a5b5 100644
--- a/java/systemserver_classpath_fragment.go
+++ b/java/systemserver_classpath_fragment.go
@@ -107,7 +107,7 @@
 	global := dexpreopt.GetGlobalConfig(ctx)
 
 	possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Contents, systemServerClasspathFragmentContentDepTag)
-	return global.UpdatableSystemServerJars.Filter(possibleUpdatableModules)
+	return global.ApexSystemServerJars.Filter(possibleUpdatableModules)
 }
 
 type systemServerClasspathFragmentContentDependencyTag struct {
diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go
index 317b40d..86e647d 100644
--- a/mk2rbc/mk2rbc.go
+++ b/mk2rbc/mk2rbc.go
@@ -1079,7 +1079,7 @@
 	if expr.name == "call" {
 		words = args.SplitN(",", 2)
 		if words[0].Empty() || !words[0].Const() {
-			return ctx.newBadExpr(nil, "cannot handle %s", refDump)
+			return ctx.newBadExpr(node, "cannot handle %s", refDump)
 		}
 		expr.name = words[0].Dump()
 		if len(words) < 2 {
diff --git a/rust/builder.go b/rust/builder.go
index 523428d..6c44166 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -332,6 +332,9 @@
 	rustdocFlags = append(rustdocFlags, makeLibFlags(deps)...)
 	docTimestampFile := android.PathForModuleOut(ctx, "rustdoc.timestamp")
 
+	// Silence warnings about renamed lints
+	rustdocFlags = append(rustdocFlags, " -A renamed_and_removed_lints")
+
 	// Yes, the same out directory is used simultaneously by all rustdoc builds.
 	// This is what cargo does. The docs for individual crates get generated to
 	// a subdirectory named for the crate, and rustdoc synchronizes writes to
diff --git a/rust/config/allowed_list.go b/rust/config/allowed_list.go
index f568f27..ca110a2 100644
--- a/rust/config/allowed_list.go
+++ b/rust/config/allowed_list.go
@@ -28,6 +28,7 @@
 		"system/security",
 		"system/tools/aidl",
 		"tools/security/fuzzing/example_rust_fuzzer",
+		"vendor/",
 	}
 
 	DownstreamRustAllowedPaths = []string{
diff --git a/rust/config/global.go b/rust/config/global.go
index 39ed992..c390711 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -24,7 +24,7 @@
 var pctx = android.NewPackageContext("android/soong/rust/config")
 
 var (
-	RustDefaultVersion = "1.52.1"
+	RustDefaultVersion = "1.53.0"
 	RustDefaultBase    = "prebuilts/rust/"
 	DefaultEdition     = "2018"
 	Stdlibs            = []string{
diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go
index f3c442e..3d16073 100644
--- a/ui/build/dumpvars.go
+++ b/ui/build/dumpvars.go
@@ -261,6 +261,12 @@
 		"BUILD_BROKEN_USES_BUILD_STATIC_LIBRARY",
 	}, exportEnvVars...), BannerVars...)
 
+	// We need Roboleaf converter and runner in the mixed mode
+	runMicrofactory(ctx, config, ".bootstrap/bin/mk2rbc", "android/soong/mk2rbc/cmd",
+		map[string]string{"android/soong": "build/soong"})
+	runMicrofactory(ctx, config, ".bootstrap/bin/rbcrun", "rbcrun/cmd",
+		map[string]string{"go.starlark.net": "external/starlark-go", "rbcrun": "build/make/tools/rbcrun"})
+
 	makeVars, err := dumpMakeVars(ctx, config, config.Arguments(), allVars, true, "")
 	if err != nil {
 		ctx.Fatalln("Error dumping make vars:", err)
diff --git a/ui/build/soong.go b/ui/build/soong.go
index a40457f..3fe7b0a 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -265,20 +265,8 @@
 		}
 	}()
 
-	var cfg microfactory.Config
-	cfg.Map("github.com/google/blueprint", "build/blueprint")
-
-	cfg.TrimPath = absPath(ctx, ".")
-
-	func() {
-		ctx.BeginTrace(metrics.RunSoong, "bpglob")
-		defer ctx.EndTrace()
-
-		bpglob := filepath.Join(config.SoongOutDir(), ".minibootstrap/bpglob")
-		if _, err := microfactory.Build(&cfg, bpglob, "github.com/google/blueprint/bootstrap/bpglob"); err != nil {
-			ctx.Fatalln("Failed to build bpglob:", err)
-		}
-	}()
+	runMicrofactory(ctx, config, ".minibootstrap/bpglob", "github.com/google/blueprint/bootstrap/bpglob",
+		map[string]string{"github.com/google/blueprint": "build/blueprint"})
 
 	ninja := func(name, file string) {
 		ctx.BeginTrace(metrics.RunSoong, name)
@@ -332,6 +320,25 @@
 	}
 }
 
+func runMicrofactory(ctx Context, config Config, relExePath string, pkg string, mapping map[string]string) {
+	name := filepath.Base(relExePath)
+	ctx.BeginTrace(metrics.RunSoong, name)
+	defer ctx.EndTrace()
+	cfg := microfactory.Config{TrimPath: absPath(ctx, ".")}
+	for pkgPrefix, pathPrefix := range mapping {
+		cfg.Map(pkgPrefix, pathPrefix)
+	}
+
+	exePath := filepath.Join(config.SoongOutDir(), relExePath)
+	dir := filepath.Dir(exePath)
+	if err := os.MkdirAll(dir, 0777); err != nil {
+		ctx.Fatalf("cannot create %s: %s", dir, err)
+	}
+	if _, err := microfactory.Build(&cfg, exePath, pkg); err != nil {
+		ctx.Fatalf("failed to build %s: %s", name, err)
+	}
+}
+
 func shouldCollectBuildSoongMetrics(config Config) bool {
 	// Do not collect metrics protobuf if the soong_build binary ran as the
 	// bp2build converter or the JSON graph dump.