diff options
author | Paul Duffin <paulduffin@google.com> | 2020-03-10 22:17:04 +0000 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2020-04-22 12:51:38 +0100 |
commit | 49096815fe92b68fce5b7a257bf878733cb7e2cc (patch) | |
tree | 13a853fabaf375887e10d99f239a35ac9ba73000 /sdk/sdk_test.go | |
parent | 89937326abd932c3065bf3ee755f81e0a3342d3e (diff) | |
download | build_soong-49096815fe92b68fce5b7a257bf878733cb7e2cc.tar.gz build_soong-49096815fe92b68fce5b7a257bf878733cb7e2cc.tar.bz2 build_soong-49096815fe92b68fce5b7a257bf878733cb7e2cc.zip |
Support extracting common values from embedded structures
This change also added support for excluding properties from common
value extraction by using a struct tag of `sdk:"keep"` That was needed
to prevent the fields in SdkMemberPropertiesBase from having their
values cleared.
The purpose of this change is to make it easier to share functionality
across sdk member types.
Bug: 142935992
Bug: 153306490
Test: m nothing
Merged-In: Ie5160a8f854056920e411801ca20721eab7c8578
Change-Id: Ie5160a8f854056920e411801ca20721eab7c8578
Diffstat (limited to 'sdk/sdk_test.go')
-rw-r--r-- | sdk/sdk_test.go | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 96837e3d..fde92307 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -16,6 +16,8 @@ package sdk import ( "testing" + + "github.com/google/blueprint/proptools" ) // Needed in an _test.go file in this package to ensure tests run correctly, particularly in IDE. @@ -222,3 +224,106 @@ func TestSDkInstall(t *testing.T) { checkAllOtherCopyRules(`.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip`), ) } + +type EmbeddedPropertiesStruct struct { + S_Embedded_Common string + S_Embedded_Different string +} + +type testPropertiesStruct struct { + private string + Public_Kept string `sdk:"keep"` + S_Common string + S_Different string + A_Common []string + A_Different []string + F_Common *bool + F_Different *bool + EmbeddedPropertiesStruct +} + +func TestCommonValueOptimization(t *testing.T) { + common := &testPropertiesStruct{} + structs := []*testPropertiesStruct{ + &testPropertiesStruct{ + private: "common", + Public_Kept: "common", + S_Common: "common", + S_Different: "upper", + A_Common: []string{"first", "second"}, + A_Different: []string{"alpha", "beta"}, + F_Common: proptools.BoolPtr(false), + F_Different: proptools.BoolPtr(false), + EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ + S_Embedded_Common: "embedded_common", + S_Embedded_Different: "embedded_upper", + }, + }, + &testPropertiesStruct{ + private: "common", + Public_Kept: "common", + S_Common: "common", + S_Different: "lower", + A_Common: []string{"first", "second"}, + A_Different: []string{"alpha", "delta"}, + F_Common: proptools.BoolPtr(false), + F_Different: proptools.BoolPtr(true), + EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ + S_Embedded_Common: "embedded_common", + S_Embedded_Different: "embedded_lower", + }, + }, + } + + extractor := newCommonValueExtractor(common) + extractor.extractCommonProperties(common, structs) + + h := TestHelper{t} + h.AssertDeepEquals("common properties not correct", common, + &testPropertiesStruct{ + private: "", + Public_Kept: "", + S_Common: "common", + S_Different: "", + A_Common: []string{"first", "second"}, + A_Different: []string(nil), + F_Common: proptools.BoolPtr(false), + F_Different: nil, + EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ + S_Embedded_Common: "embedded_common", + S_Embedded_Different: "", + }, + }) + + h.AssertDeepEquals("updated properties[0] not correct", structs[0], + &testPropertiesStruct{ + private: "common", + Public_Kept: "common", + S_Common: "", + S_Different: "upper", + A_Common: nil, + A_Different: []string{"alpha", "beta"}, + F_Common: nil, + F_Different: proptools.BoolPtr(false), + EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ + S_Embedded_Common: "", + S_Embedded_Different: "embedded_upper", + }, + }) + + h.AssertDeepEquals("updated properties[1] not correct", structs[1], + &testPropertiesStruct{ + private: "common", + Public_Kept: "common", + S_Common: "", + S_Different: "lower", + A_Common: nil, + A_Different: []string{"alpha", "delta"}, + F_Common: nil, + F_Different: proptools.BoolPtr(true), + EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ + S_Embedded_Common: "", + S_Embedded_Different: "embedded_lower", + }, + }) +} |