bp2build: group shared/static attrs into a struct.

This makes bp2build generate these attrs into a Starlark dictionary,
passed into the cc_library macro directly. This makes the BUILD target
representation more similar to the Android.bp one, and also makes
it more legible.

Test: TH
Change-Id: I42b427cc4b22c6376d3d24e40b9af1692bb0c692
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 7c6ee0a..76c5f3b 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -142,15 +142,14 @@
 // staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties --
 // properties which apply to either the shared or static version of a cc_library module.
 type staticOrSharedAttributes struct {
-	srcs    bazel.LabelListAttribute
-	srcs_c  bazel.LabelListAttribute
-	srcs_as bazel.LabelListAttribute
+	Srcs    bazel.LabelListAttribute
+	Srcs_c  bazel.LabelListAttribute
+	Srcs_as bazel.LabelListAttribute
+	Copts   bazel.StringListAttribute
 
-	copts bazel.StringListAttribute
-
-	staticDeps       bazel.LabelListAttribute
-	dynamicDeps      bazel.LabelListAttribute
-	wholeArchiveDeps bazel.LabelListAttribute
+	Static_deps        bazel.LabelListAttribute
+	Dynamic_deps       bazel.LabelListAttribute
+	Whole_archive_deps bazel.LabelListAttribute
 }
 
 func groupSrcsByExtension(ctx android.TopDownMutatorContext, srcs bazel.LabelListAttribute) (cppSrcs, cSrcs, asSrcs bazel.LabelListAttribute) {
@@ -251,19 +250,19 @@
 	}
 
 	attrs := staticOrSharedAttributes{
-		copts:            bazel.StringListAttribute{Value: props.Cflags},
-		srcs:             bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, props.Srcs)),
-		staticDeps:       bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, props.Static_libs)),
-		dynamicDeps:      bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, props.Shared_libs)),
-		wholeArchiveDeps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleWholeDeps(ctx, props.Whole_static_libs)),
+		Copts:              bazel.StringListAttribute{Value: props.Cflags},
+		Srcs:               bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, props.Srcs)),
+		Static_deps:        bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, props.Static_libs)),
+		Dynamic_deps:       bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, props.Shared_libs)),
+		Whole_archive_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleWholeDeps(ctx, props.Whole_static_libs)),
 	}
 
 	setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) {
-		attrs.copts.SetSelectValue(axis, config, props.Cflags)
-		attrs.srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs))
-		attrs.staticDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.Static_libs))
-		attrs.dynamicDeps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.Shared_libs))
-		attrs.wholeArchiveDeps.SetSelectValue(axis, config, android.BazelLabelForModuleWholeDeps(ctx, props.Whole_static_libs))
+		attrs.Copts.SetSelectValue(axis, config, props.Cflags)
+		attrs.Srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs))
+		attrs.Static_deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.Static_libs))
+		attrs.Dynamic_deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, props.Shared_libs))
+		attrs.Whole_archive_deps.SetSelectValue(axis, config, android.BazelLabelForModuleWholeDeps(ctx, props.Whole_static_libs))
 	}
 
 	if isStatic {
@@ -284,10 +283,10 @@
 		}
 	}
 
-	cppSrcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, attrs.srcs)
-	attrs.srcs = cppSrcs
-	attrs.srcs_c = cSrcs
-	attrs.srcs_as = asSrcs
+	cppSrcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, attrs.Srcs)
+	attrs.Srcs = cppSrcs
+	attrs.Srcs_c = cSrcs
+	attrs.Srcs_as = asSrcs
 
 	return attrs
 }
diff --git a/cc/library.go b/cc/library.go
index 3061be4..6ab8300 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -237,29 +237,12 @@
 	Linkopts            bazel.StringListAttribute
 	Use_libcrt          bazel.BoolAttribute
 
-	// Attributes pertaining to shared variant.
-	Shared_srcs    bazel.LabelListAttribute
-	Shared_srcs_c  bazel.LabelListAttribute
-	Shared_srcs_as bazel.LabelListAttribute
-	Shared_copts   bazel.StringListAttribute
+	// This is shared only.
+	Version_script bazel.LabelAttribute
 
-	Exported_deps_for_shared      bazel.LabelListAttribute
-	Static_deps_for_shared        bazel.LabelListAttribute
-	Dynamic_deps_for_shared       bazel.LabelListAttribute
-	Whole_archive_deps_for_shared bazel.LabelListAttribute
-	User_link_flags               bazel.StringListAttribute
-	Version_script                bazel.LabelAttribute
-
-	// Attributes pertaining to static variant.
-	Static_srcs    bazel.LabelListAttribute
-	Static_srcs_c  bazel.LabelListAttribute
-	Static_srcs_as bazel.LabelListAttribute
-	Static_copts   bazel.StringListAttribute
-
-	Exported_deps_for_static      bazel.LabelListAttribute
-	Static_deps_for_static        bazel.LabelListAttribute
-	Dynamic_deps_for_static       bazel.LabelListAttribute
-	Whole_archive_deps_for_static bazel.LabelListAttribute
+	// Common properties shared between both shared and static variants.
+	Shared staticOrSharedAttributes
+	Static staticOrSharedAttributes
 
 	Strip stripAttributes
 }
@@ -334,6 +317,8 @@
 		Linkopts:            linkerAttrs.linkopts,
 		Use_libcrt:          linkerAttrs.useLibcrt,
 
+		Version_script: linkerAttrs.versionScript,
+
 		Strip: stripAttributes{
 			Keep_symbols:                 linkerAttrs.stripKeepSymbols,
 			Keep_symbols_and_debug_frame: linkerAttrs.stripKeepSymbolsAndDebugFrame,
@@ -342,22 +327,9 @@
 			None:                         linkerAttrs.stripNone,
 		},
 
-		Shared_srcs:                   sharedAttrs.srcs,
-		Shared_srcs_c:                 sharedAttrs.srcs_c,
-		Shared_srcs_as:                sharedAttrs.srcs_as,
-		Shared_copts:                  sharedAttrs.copts,
-		Static_deps_for_shared:        sharedAttrs.staticDeps,
-		Whole_archive_deps_for_shared: sharedAttrs.wholeArchiveDeps,
-		Dynamic_deps_for_shared:       sharedAttrs.dynamicDeps,
-		Version_script:                linkerAttrs.versionScript,
+		Shared: sharedAttrs,
 
-		Static_srcs:                   staticAttrs.srcs,
-		Static_srcs_c:                 staticAttrs.srcs_c,
-		Static_srcs_as:                staticAttrs.srcs_as,
-		Static_copts:                  staticAttrs.copts,
-		Static_deps_for_static:        staticAttrs.staticDeps,
-		Whole_archive_deps_for_static: staticAttrs.wholeArchiveDeps,
-		Dynamic_deps_for_static:       staticAttrs.dynamicDeps,
+		Static: staticAttrs,
 	}
 
 	props := bazel.BazelTargetModuleProperties{