Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4fecbfe authored by Colin Cross's avatar Colin Cross
Browse files

Do a better job removing tags from arch structs

Remove more android struct tags from runtime created arch structs
to reduce the size of their names, which hit the 64kB limit in
runtime.StructOf if they are too long.

Bug: 146234651
Test: m checkbuild
Change-Id: I6362765275b93c8932eb0b1abbcb4be47031d9b1
parent cbbd13f9
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -1036,11 +1036,20 @@ func filterArchStruct(field reflect.StructField, prefix string) (bool, reflect.S
		// 16-bit limit on structure name length. The name is constructed
		// based on the Go source representation of the structure, so
		// the tag names count towards that length.
		//
		// TODO: handle the uncommon case of other tags being involved
		if field.Tag == `android:"arch_variant"` {
			field.Tag = ""

		androidTag := field.Tag.Get("android")
		values := strings.Split(androidTag, ",")

		if string(field.Tag) != `android:"`+strings.Join(values, ",")+`"` {
			panic(fmt.Errorf("unexpected tag format %q", field.Tag))
		}
		// these tags don't need to be present in the runtime generated struct type.
		values = RemoveListFromList(values, []string{"arch_variant", "variant_prepend", "path"})
		if len(values) > 0 {
			panic(fmt.Errorf("unknown tags %q in field %q", values, prefix+field.Name))
		}

		field.Tag = ""
		return true, field
	}
	return false, field
+18 −0
Original line number Diff line number Diff line
@@ -54,6 +54,24 @@ func TestFilterArchStruct(t *testing.T) {
			}{},
			filtered: true,
		},
		{
			name: "tags",
			in: &struct {
				A *string `android:"arch_variant"`
				B *string `android:"arch_variant,path"`
				C *string `android:"arch_variant,path,variant_prepend"`
				D *string `android:"path,variant_prepend,arch_variant"`
				E *string `android:"path"`
				F *string
			}{},
			out: &struct {
				A *string
				B *string
				C *string
				D *string
			}{},
			filtered: true,
		},
		{
			name: "all filtered",
			in: &struct {