diff options
author | 2024-10-30 10:43:17 -0700 | |
---|---|---|
committer | 2024-10-30 12:19:10 -0700 | |
commit | 66e6586419c1e75d291380d215ee5fc8022663f3 (patch) | |
tree | 612a0ab378e92c937b07553caa5292c0b8b8f019 | |
parent | 6b321e649d15ce252cf01c5a2b6dbafa600a6f82 (diff) |
Reapply "Only use partial compile on eng builds"
This reverts commit bef36af55ac6f97002eb51ed251bad3cf652ff27, and avoids
reanalysis on every build for eng builds.
Bug: b/365536323
Test: manual, TH
Change-Id: Ie6eafa09494c3c2525434086f281b387da0e270d
-rw-r--r-- | android/config.go | 29 | ||||
-rw-r--r-- | android/config_test.go | 45 |
2 files changed, 62 insertions, 12 deletions
diff --git a/android/config.go b/android/config.go index feed22f6a..1739b01e1 100644 --- a/android/config.go +++ b/android/config.go @@ -413,18 +413,21 @@ type jsonConfigurable interface { // To add a new feature to the list, add the field in the struct // `partialCompileFlags` above, and then add the name of the field in the // switch statement below. -func (c *config) parsePartialCompileFlags() (partialCompileFlags, error) { - defaultFlags := partialCompileFlags{ - // Set any opt-out flags here. Opt-in flags are off by default. - enabled: false, +var defaultPartialCompileFlags = partialCompileFlags{ + // Set any opt-out flags here. Opt-in flags are off by default. + enabled: false, +} + +func (c *config) parsePartialCompileFlags(isEngBuild bool) (partialCompileFlags, error) { + if !isEngBuild { + return partialCompileFlags{}, nil } value := c.Getenv("SOONG_PARTIAL_COMPILE") - if value == "" { - return defaultFlags, nil + return defaultPartialCompileFlags, nil } - ret := defaultFlags + ret := defaultPartialCompileFlags tokens := strings.Split(strings.ToLower(value), ",") makeVal := func(state string, defaultValue bool) bool { switch state { @@ -455,17 +458,17 @@ func (c *config) parsePartialCompileFlags() (partialCompileFlags, error) { } switch tok { case "true": - ret = defaultFlags + ret = defaultPartialCompileFlags ret.enabled = true case "false": // Set everything to false. ret = partialCompileFlags{} case "enabled": - ret.enabled = makeVal(state, defaultFlags.enabled) + ret.enabled = makeVal(state, defaultPartialCompileFlags.enabled) case "use_d8": - ret.use_d8 = makeVal(state, defaultFlags.use_d8) + ret.use_d8 = makeVal(state, defaultPartialCompileFlags.use_d8) default: - return partialCompileFlags{}, fmt.Errorf("Unknown SOONG_PARTIAL_COMPILE value: %v", value) + return partialCompileFlags{}, fmt.Errorf("Unknown SOONG_PARTIAL_COMPILE value: %v", tok) } } return ret, nil @@ -616,6 +619,8 @@ func NewConfig(cmdArgs CmdArgs, availableEnv map[string]string) (Config, error) buildFromSourceStub: cmdArgs.BuildFromSourceStub, } + variant, ok := os.LookupEnv("TARGET_BUILD_VARIANT") + isEngBuild := !ok || variant == "eng" config.deviceConfig = &deviceConfig{ config: config, @@ -657,7 +662,7 @@ func NewConfig(cmdArgs CmdArgs, availableEnv map[string]string) (Config, error) return Config{}, err } - config.partialCompileFlags, err = config.parsePartialCompileFlags() + config.partialCompileFlags, err = config.parsePartialCompileFlags(isEngBuild) if err != nil { return Config{}, err } diff --git a/android/config_test.go b/android/config_test.go index 773216844..adb5ffac5 100644 --- a/android/config_test.go +++ b/android/config_test.go @@ -212,3 +212,48 @@ func TestConfiguredJarList(t *testing.T) { assertStringEquals(t, "apex1:jarA", list5.String()) }) } + +func (p partialCompileFlags) updateEnabled(value bool) partialCompileFlags { + p.enabled = value + return p +} + +func (p partialCompileFlags) updateUseD8(value bool) partialCompileFlags { + p.use_d8 = value + return p +} + +func TestPartialCompile(t *testing.T) { + mockConfig := func(value string) *config { + c := &config{ + env: map[string]string{ + "SOONG_PARTIAL_COMPILE": value, + }, + } + return c + } + tests := []struct { + value string + isEngBuild bool + expected partialCompileFlags + }{ + {"", true, defaultPartialCompileFlags}, + {"false", true, partialCompileFlags{}}, + {"true", true, defaultPartialCompileFlags.updateEnabled(true)}, + {"true", false, partialCompileFlags{}}, + {"true,use_d8", true, defaultPartialCompileFlags.updateEnabled(true).updateUseD8(true)}, + {"true,-use_d8", true, defaultPartialCompileFlags.updateEnabled(true).updateUseD8(false)}, + {"use_d8,false", true, partialCompileFlags{}}, + {"false,+use_d8", true, partialCompileFlags{}.updateUseD8(true)}, + } + + for _, test := range tests { + t.Run(test.value, func(t *testing.T) { + config := mockConfig(test.value) + flags, _ := config.parsePartialCompileFlags(test.isEngBuild) + if flags != test.expected { + t.Errorf("expected %v found %v", test.expected, flags) + } + }) + } +} |