From ee2096237846c1cae2835c77af4204f1a6ec30a3 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 6 May 2020 10:23:19 +0100 Subject: Detect invalid arch specific properties in snapshot Previously, the snapshot code did not know whether a specific property could be arch specific or not and assumed that they all were which meant that it could generate snapshots containing arch specific values for properties that are not arch specific and so would fail when unpacked. This change requires arch specific fields in SdkMemberProperties to be tagged as such using `android:"arch_variant"` (just as in module input property structures). Any property without that must have properties that are common across all variants. Bug: 155628860 Test: m nothing Change-Id: Ifc8116e11d987cfe7aec2eeaa964f3bbf36b5dc2 --- sdk/sdk_test.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'sdk/sdk_test.go') diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 095f83607..898ecea68 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -226,8 +226,8 @@ func TestSDkInstall(t *testing.T) { } type EmbeddedPropertiesStruct struct { - S_Embedded_Common string - S_Embedded_Different string + S_Embedded_Common string `android:"arch_variant"` + S_Embedded_Different string `android:"arch_variant"` } type testPropertiesStruct struct { @@ -235,11 +235,11 @@ type testPropertiesStruct struct { private string Public_Kept string `sdk:"keep"` S_Common string - S_Different string + S_Different string `android:"arch_variant"` A_Common []string - A_Different []string + A_Different []string `android:"arch_variant"` F_Common *bool - F_Different *bool + F_Different *bool `android:"arch_variant"` EmbeddedPropertiesStruct } @@ -346,3 +346,26 @@ func TestCommonValueOptimization(t *testing.T) { }, structs[1]) } + +func TestCommonValueOptimization_InvalidArchSpecificVariants(t *testing.T) { + common := &testPropertiesStruct{name: "common"} + structs := []propertiesContainer{ + &testPropertiesStruct{ + name: "struct-0", + S_Common: "should-be-but-is-not-common0", + }, + &testPropertiesStruct{ + name: "struct-1", + S_Common: "should-be-but-is-not-common1", + }, + } + + extractor := newCommonValueExtractor(common) + + h := TestHelper{t} + + err := extractor.extractCommonProperties(common, structs) + h.AssertErrorMessageEquals("unexpected error", `field "S_Common" is not tagged as "arch_variant" but has arch specific properties: + "struct-0" has value "should-be-but-is-not-common0" + "struct-1" has value "should-be-but-is-not-common1"`, err) +} -- cgit v1.2.3-59-g8ed1b