Merge "Pass -t epoch to jetifier"
diff --git a/android/arch_list.go b/android/arch_list.go
index cbf8e7a..578904c 100644
--- a/android/arch_list.go
+++ b/android/arch_list.go
@@ -31,6 +31,8 @@
 		"amberlake",
 		"atom",
 		"broadwell",
+		"goldmont",
+		"goldmont-plus",
 		"haswell",
 		"icelake",
 		"ivybridge",
@@ -40,12 +42,15 @@
 		"skylake",
 		"stoneyridge",
 		"tigerlake",
+		"tremont",
 		"whiskeylake",
 		"x86_64",
 	},
 	X86_64: {
 		"amberlake",
 		"broadwell",
+		"goldmont",
+		"goldmont-plus",
 		"haswell",
 		"icelake",
 		"ivybridge",
@@ -55,6 +60,7 @@
 		"skylake",
 		"stoneyridge",
 		"tigerlake",
+		"tremont",
 		"whiskeylake",
 	},
 }
@@ -168,6 +174,24 @@
 			"aes_ni",
 			"popcnt",
 		},
+		"goldmont": {
+			"ssse3",
+			"sse4",
+			"sse4_1",
+			"sse4_2",
+			"aes_ni",
+			"popcnt",
+			"movbe",
+		},
+		"goldmont-plus": {
+			"ssse3",
+			"sse4",
+			"sse4_1",
+			"sse4_2",
+			"aes_ni",
+			"popcnt",
+			"movbe",
+		},
 		"haswell": {
 			"ssse3",
 			"sse4",
@@ -257,6 +281,15 @@
 			"aes_ni",
 			"popcnt",
 		},
+		"tremont": {
+			"ssse3",
+			"sse4",
+			"sse4_1",
+			"sse4_2",
+			"aes_ni",
+			"popcnt",
+			"movbe",
+		},
 		"whiskeylake": {
 			"ssse3",
 			"sse4",
@@ -304,6 +337,22 @@
 			"aes_ni",
 			"popcnt",
 		},
+		"goldmont": {
+			"ssse3",
+			"sse4",
+			"sse4_1",
+			"sse4_2",
+			"aes_ni",
+			"popcnt",
+		},
+		"goldmont-plus": {
+			"ssse3",
+			"sse4",
+			"sse4_1",
+			"sse4_2",
+			"aes_ni",
+			"popcnt",
+		},
 		"haswell": {
 			"ssse3",
 			"sse4",
@@ -390,6 +439,14 @@
 			"aes_ni",
 			"popcnt",
 		},
+		"tremont": {
+			"ssse3",
+			"sse4",
+			"sse4_1",
+			"sse4_2",
+			"aes_ni",
+			"popcnt",
+		},
 		"whiskeylake": {
 			"ssse3",
 			"sse4",
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index 908b2d6..0529f23 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -1103,7 +1103,7 @@
 }
 
 // Register bazel-owned build statements (obtained from the aquery invocation).
-func createCommand(cmd *RuleBuilderCommand, buildStatement bazel.BuildStatement, executionRoot string, bazelOutDir string, ctx PathContext) {
+func createCommand(cmd *RuleBuilderCommand, buildStatement bazel.BuildStatement, executionRoot string, bazelOutDir string, ctx BuilderContext) {
 	// executionRoot is the action cwd.
 	cmd.Text(fmt.Sprintf("cd '%s' &&", executionRoot))
 
@@ -1122,7 +1122,14 @@
 	}
 
 	// The actual Bazel action.
-	cmd.Text(buildStatement.Command)
+	if len(buildStatement.Command) > 16*1024 {
+		commandFile := PathForBazelOut(ctx, buildStatement.OutputPaths[0]+".sh")
+		WriteFileRule(ctx, commandFile, buildStatement.Command)
+
+		cmd.Text("bash").Text(buildStatement.OutputPaths[0] + ".sh").Implicit(commandFile)
+	} else {
+		cmd.Text(buildStatement.Command)
+	}
 
 	for _, outputPath := range buildStatement.OutputPaths {
 		cmd.ImplicitOutput(PathForBazelOut(ctx, outputPath))
diff --git a/android/bazel_handler_test.go b/android/bazel_handler_test.go
index bc16cb5..10bbf31 100644
--- a/android/bazel_handler_test.go
+++ b/android/bazel_handler_test.go
@@ -129,7 +129,8 @@
 		}
 
 		cmd := RuleBuilderCommand{}
-		createCommand(&cmd, got[0], "test/exec_root", "test/bazel_out", PathContextForTesting(TestConfig("out", nil, "", nil)))
+		ctx := builderContextForTests{PathContextForTesting(TestConfig("out", nil, "", nil))}
+		createCommand(&cmd, got[0], "test/exec_root", "test/bazel_out", ctx)
 		if actual, expected := cmd.buf.String(), testCase.command; expected != actual {
 			t.Errorf("expected: [%s], actual: [%s]", expected, actual)
 		}
diff --git a/android/proto.go b/android/proto.go
index 8204f77..09e50c8 100644
--- a/android/proto.go
+++ b/android/proto.go
@@ -234,10 +234,13 @@
 			}
 		}
 
+		tags := ApexAvailableTags(ctx.Module())
+
 		ctx.CreateBazelTargetModule(
 			bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
-			CommonAttributes{Name: info.Name},
-			&attrs)
+			CommonAttributes{Name: info.Name, Tags: tags},
+			&attrs,
+		)
 
 		protoLibraries.Add(&bazel.Label{
 			Label: ":" + info.Name,
diff --git a/bazel/cquery/request_type.go b/bazel/cquery/request_type.go
index 118a3a9..9feb82b 100644
--- a/bazel/cquery/request_type.go
+++ b/bazel/cquery/request_type.go
@@ -227,7 +227,7 @@
 //   - The function body should not be indented outside of its own scope.
 func (g getApexInfoType) StarlarkFunctionBody() string {
 	return `
-info = providers(target).get("//build/bazel/rules/apex:apex.bzl%ApexInfo")
+info = providers(target).get("//build/bazel/rules/apex:apex_info.bzl%ApexInfo")
 if not info:
   fail("%s did not provide ApexInfo" % id_string)
 bundle_key_info = info.bundle_key_info
diff --git a/cc/cc.go b/cc/cc.go
index 29bb84e..632bdca 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1440,7 +1440,7 @@
 
 func isBionic(name string) bool {
 	switch name {
-	case "libc", "libm", "libdl", "libdl_android", "linker", "linkerconfig":
+	case "libc", "libm", "libdl", "libdl_android", "linker":
 		return true
 	}
 	return false
diff --git a/cc/config/global.go b/cc/config/global.go
index 61151d1..1a358d1 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -311,8 +311,8 @@
 
 	// prebuilts/clang default settings.
 	ClangDefaultBase         = "prebuilts/clang/host"
-	ClangDefaultVersion      = "clang-r475365"
-	ClangDefaultShortVersion = "16.0.1"
+	ClangDefaultVersion      = "clang-r475365b"
+	ClangDefaultShortVersion = "16.0.2"
 
 	// Directories with warnings from Android.bp files.
 	WarningAllowedProjects = []string{
diff --git a/cc/config/x86_64_device.go b/cc/config/x86_64_device.go
index e2b0f06..9f093bb 100644
--- a/cc/config/x86_64_device.go
+++ b/cc/config/x86_64_device.go
@@ -41,6 +41,12 @@
 		"broadwell": []string{
 			"-march=broadwell",
 		},
+		"goldmont": []string{
+			"-march=goldmont",
+		},
+		"goldmont-plus": []string{
+			"-march=goldmont-plus",
+		},
 		"haswell": []string{
 			"-march=core-avx2",
 		},
@@ -59,6 +65,9 @@
 		"stoneyridge": []string{
 			"-march=bdver4",
 		},
+		"tremont": []string{
+			"-march=tremont",
+		},
 	}
 
 	x86_64ArchFeatureCflags = map[string][]string{
diff --git a/cc/config/x86_device.go b/cc/config/x86_device.go
index 3001ab4..c826d3c 100644
--- a/cc/config/x86_device.go
+++ b/cc/config/x86_device.go
@@ -50,6 +50,12 @@
 		"broadwell": []string{
 			"-march=broadwell",
 		},
+		"goldmont": []string{
+			"-march=goldmont",
+		},
+		"goldmont-plus": []string{
+			"-march=goldmont-plus",
+		},
 		"haswell": []string{
 			"-march=core-avx2",
 		},
@@ -68,6 +74,9 @@
 		"stoneyridge": []string{
 			"-march=bdver4",
 		},
+		"tremont": []string{
+			"-march=tremont",
+		},
 	}
 
 	x86ArchFeatureCflags = map[string][]string{
diff --git a/cc/library_headers.go b/cc/library_headers.go
index 1c4f354..4d38068 100644
--- a/cc/library_headers.go
+++ b/cc/library_headers.go
@@ -145,7 +145,12 @@
 		Bzl_load_location: "//build/bazel/rules/cc:cc_library_headers.bzl",
 	}
 
-	ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
+	tags := android.ApexAvailableTags(module)
+
+	ctx.CreateBazelTargetModule(props, android.CommonAttributes{
+		Name: module.Name(),
+		Tags: tags,
+	}, attrs)
 }
 
 // Append .contribution suffix to input labels
diff --git a/cc/linker.go b/cc/linker.go
index 76a60ca..625d89c 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -221,7 +221,7 @@
 	// Generate compact dynamic relocation table, default true.
 	Pack_relocations *bool `android:"arch_variant"`
 
-	// local file name to pass to the linker as --version_script
+	// local file name to pass to the linker as --version-script
 	Version_script *string `android:"path,arch_variant"`
 
 	// local file name to pass to the linker as --dynamic-list
diff --git a/cc/object.go b/cc/object.go
index ff04e87..c3a198d 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -214,7 +214,12 @@
 		Bzl_load_location: "//build/bazel/rules/cc:cc_object.bzl",
 	}
 
-	ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
+	tags := android.ApexAvailableTags(m)
+
+	ctx.CreateBazelTargetModule(props, android.CommonAttributes{
+		Name: m.Name(),
+		Tags: tags,
+	}, attrs)
 }
 
 func (object *objectLinker) appendLdflags(flags []string) {
diff --git a/cc/proto.go b/cc/proto.go
index 27f37cb..97470e5 100644
--- a/cc/proto.go
+++ b/cc/proto.go
@@ -165,7 +165,8 @@
 }
 
 type protoAttributes struct {
-	Deps bazel.LabelListAttribute
+	Deps            bazel.LabelListAttribute
+	Min_sdk_version *string
 }
 
 type bp2buildProtoDeps struct {
@@ -203,6 +204,7 @@
 
 	var protoAttrs protoAttributes
 	protoAttrs.Deps.SetValue(protoInfo.Proto_libs)
+	protoAttrs.Min_sdk_version = m.Properties.Min_sdk_version
 
 	name := m.Name() + suffix
 	tags := android.ApexAvailableTags(m)
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 14895c9..f5da50e 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -940,6 +940,8 @@
 		}
 	}
 
+	tags := android.ApexAvailableTags(m)
+
 	if ctx.ModuleType() == "gensrcs" {
 		// The Output_extension prop is not in an immediately accessible field
 		// in the Module struct, so use GetProperties and cast it
@@ -961,7 +963,10 @@
 			Cmd:              cmd,
 			Tools:            tools,
 		}
-		ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
+		ctx.CreateBazelTargetModule(props, android.CommonAttributes{
+			Name: m.Name(),
+			Tags: tags,
+		}, attrs)
 	} else {
 		// The Out prop is not in an immediately accessible field
 		// in the Module struct, so use GetProperties and cast it
@@ -982,7 +987,10 @@
 		props := bazel.BazelTargetModuleProperties{
 			Rule_class: "genrule",
 		}
-		ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
+		ctx.CreateBazelTargetModule(props, android.CommonAttributes{
+			Name: m.Name(),
+			Tags: tags,
+		}, attrs)
 	}
 }
 
diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go
index c3b192d..705eac3 100644
--- a/mk2rbc/mk2rbc.go
+++ b/mk2rbc/mk2rbc.go
@@ -78,6 +78,7 @@
 	"addprefix":                            &simpleCallParser{name: baseName + ".addprefix", returnType: starlarkTypeList},
 	"addsuffix":                            &simpleCallParser{name: baseName + ".addsuffix", returnType: starlarkTypeList},
 	"and":                                  &andOrParser{isAnd: true},
+	"clear-var-list":                       &simpleCallParser{name: baseName + ".clear_var_list", returnType: starlarkTypeVoid, addGlobals: true, addHandle: true},
 	"copy-files":                           &simpleCallParser{name: baseName + ".copy_files", returnType: starlarkTypeList},
 	"dir":                                  &simpleCallParser{name: baseName + ".dir", returnType: starlarkTypeString},
 	"dist-for-goals":                       &simpleCallParser{name: baseName + ".mkdist_for_goals", returnType: starlarkTypeVoid, addGlobals: true},
diff --git a/rust/config/x86_64_device.go b/rust/config/x86_64_device.go
index 94b719f..3458ec9 100644
--- a/rust/config/x86_64_device.go
+++ b/rust/config/x86_64_device.go
@@ -26,15 +26,18 @@
 	x86_64LinkFlags            = []string{}
 
 	x86_64ArchVariantRustFlags = map[string][]string{
-		"":            []string{},
-		"broadwell":   []string{"-C target-cpu=broadwell"},
-		"haswell":     []string{"-C target-cpu=haswell"},
-		"ivybridge":   []string{"-C target-cpu=ivybridge"},
-		"sandybridge": []string{"-C target-cpu=sandybridge"},
-		"silvermont":  []string{"-C target-cpu=silvermont"},
-		"skylake":     []string{"-C target-cpu=skylake"},
+		"":              []string{},
+		"broadwell":     []string{"-C target-cpu=broadwell"},
+		"goldmont":      []string{"-C target-cpu=goldmont"},
+		"goldmont-plus": []string{"-C target-cpu=goldmont-plus"},
+		"haswell":       []string{"-C target-cpu=haswell"},
+		"ivybridge":     []string{"-C target-cpu=ivybridge"},
+		"sandybridge":   []string{"-C target-cpu=sandybridge"},
+		"silvermont":    []string{"-C target-cpu=silvermont"},
+		"skylake":       []string{"-C target-cpu=skylake"},
 		//TODO: Add target-cpu=stoneyridge when rustc supports it.
 		"stoneyridge": []string{""},
+		"tremont":     []string{"-C target-cpu=tremont"},
 	}
 )
 
diff --git a/rust/config/x86_device.go b/rust/config/x86_device.go
index 5ae30e7..43f7340 100644
--- a/rust/config/x86_device.go
+++ b/rust/config/x86_device.go
@@ -26,16 +26,19 @@
 	x86LinkFlags            = []string{}
 
 	x86ArchVariantRustFlags = map[string][]string{
-		"":            []string{},
-		"atom":        []string{"-C target-cpu=atom"},
-		"broadwell":   []string{"-C target-cpu=broadwell"},
-		"haswell":     []string{"-C target-cpu=haswell"},
-		"ivybridge":   []string{"-C target-cpu=ivybridge"},
-		"sandybridge": []string{"-C target-cpu=sandybridge"},
-		"silvermont":  []string{"-C target-cpu=silvermont"},
-		"skylake":     []string{"-C target-cpu=skylake"},
+		"":              []string{},
+		"atom":          []string{"-C target-cpu=atom"},
+		"broadwell":     []string{"-C target-cpu=broadwell"},
+		"goldmont":      []string{"-C target-cpu=goldmont"},
+		"goldmont-plus": []string{"-C target-cpu=goldmont-plus"},
+		"haswell":       []string{"-C target-cpu=haswell"},
+		"ivybridge":     []string{"-C target-cpu=ivybridge"},
+		"sandybridge":   []string{"-C target-cpu=sandybridge"},
+		"silvermont":    []string{"-C target-cpu=silvermont"},
+		"skylake":       []string{"-C target-cpu=skylake"},
 		//TODO: Add target-cpu=stoneyridge when rustc supports it.
 		"stoneyridge": []string{""},
+		"tremont":     []string{"-C target-cpu=tremont"},
 		// use prescott for x86_64, like cc/config/x86_device.go
 		"x86_64": []string{"-C target-cpu=prescott"},
 	}
diff --git a/tests/lib.sh b/tests/lib.sh
index f68199a..ae8875a 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -119,6 +119,7 @@
   copy_directory build/bazel
   copy_directory build/bazel_common_rules
 
+  symlink_directory packages/modules/common/build
   symlink_directory prebuilts/bazel
   symlink_directory prebuilts/clang
   symlink_directory prebuilts/jdk