summaryrefslogtreecommitdiff
path: root/android/module.go
diff options
context:
space:
mode:
author Yu Liu <yudiliu@google.com> 2024-08-30 23:40:32 +0000
committer Yu Liu <yudiliu@google.com> 2024-09-04 19:59:55 +0000
commit26a716d5e596a574ac3b7d38ffc8ae7056e14330 (patch)
tree1e1ced2638fa5f9737612e91043b1d29cc400e08 /android/module.go
parentc965be6ca209c5623a978a29de31c037da4b29cf (diff)
Move the caching/restoring code from soong to blueprint to fully skip build actions.
Bug: 358425833 Test: Manually verified the generated ninja and mk files and CI. Change-Id: Ieebb822c46f37c0ff55fad08531e9870a76cbd7b
Diffstat (limited to 'android/module.go')
-rw-r--r--android/module.go114
1 files changed, 61 insertions, 53 deletions
diff --git a/android/module.go b/android/module.go
index 7ce4e0535..29d2dbab5 100644
--- a/android/module.go
+++ b/android/module.go
@@ -15,6 +15,9 @@
package android
import (
+ "bytes"
+ "encoding/gob"
+ "errors"
"fmt"
"net/url"
"path/filepath"
@@ -1879,61 +1882,16 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
return
}
- incrementalAnalysis := false
- incrementalEnabled := false
- var cacheKey *blueprint.BuildActionCacheKey = nil
- var incrementalModule *blueprint.Incremental = nil
- if ctx.bp.GetIncrementalEnabled() {
- if im, ok := m.module.(blueprint.Incremental); ok {
- incrementalModule = &im
- incrementalEnabled = im.IncrementalSupported()
- incrementalAnalysis = ctx.bp.GetIncrementalAnalysis() && incrementalEnabled
- }
- }
- if incrementalEnabled {
- hash, err := proptools.CalculateHash(m.GetProperties())
- if err != nil {
- ctx.ModuleErrorf("failed to calculate properties hash: %s", err)
- return
- }
- cacheInput := new(blueprint.BuildActionCacheInput)
- cacheInput.PropertiesHash = hash
- ctx.VisitDirectDeps(func(module Module) {
- cacheInput.ProvidersHash =
- append(cacheInput.ProvidersHash, ctx.bp.OtherModuleProviderInitialValueHashes(module))
- })
- hash, err = proptools.CalculateHash(&cacheInput)
- if err != nil {
- ctx.ModuleErrorf("failed to calculate cache input hash: %s", err)
- return
- }
- cacheKey = &blueprint.BuildActionCacheKey{
- Id: ctx.bp.ModuleCacheKey(),
- InputHash: hash,
- }
- }
-
- restored := false
- if incrementalAnalysis && cacheKey != nil {
- restored = ctx.bp.RestoreBuildActions(cacheKey)
- }
-
- if !restored {
- m.module.GenerateAndroidBuildActions(ctx)
- if ctx.Failed() {
- return
- }
-
- if x, ok := m.module.(IDEInfo); ok {
- var result IdeInfo
- x.IDEInfo(ctx, &result)
- result.BaseModuleName = x.BaseModuleName()
- SetProvider(ctx, IdeInfoProviderKey, result)
- }
+ m.module.GenerateAndroidBuildActions(ctx)
+ if ctx.Failed() {
+ return
}
- if incrementalEnabled && cacheKey != nil {
- ctx.bp.CacheBuildActions(cacheKey, incrementalModule)
+ if x, ok := m.module.(IDEInfo); ok {
+ var result IdeInfo
+ x.IDEInfo(ctx, &result)
+ result.BaseModuleName = x.BaseModuleName()
+ SetProvider(ctx, IdeInfoProviderKey, result)
}
// Create the set of tagged dist files after calling GenerateAndroidBuildActions
@@ -2116,11 +2074,61 @@ type katiInstall struct {
absFrom string
}
+func (p *katiInstall) GobEncode() ([]byte, error) {
+ w := new(bytes.Buffer)
+ encoder := gob.NewEncoder(w)
+ err := errors.Join(encoder.Encode(p.from), encoder.Encode(p.to),
+ encoder.Encode(p.implicitDeps), encoder.Encode(p.orderOnlyDeps),
+ encoder.Encode(p.executable), encoder.Encode(p.extraFiles),
+ encoder.Encode(p.absFrom))
+ if err != nil {
+ return nil, err
+ }
+
+ return w.Bytes(), nil
+}
+
+func (p *katiInstall) GobDecode(data []byte) error {
+ r := bytes.NewBuffer(data)
+ decoder := gob.NewDecoder(r)
+ err := errors.Join(decoder.Decode(&p.from), decoder.Decode(&p.to),
+ decoder.Decode(&p.implicitDeps), decoder.Decode(&p.orderOnlyDeps),
+ decoder.Decode(&p.executable), decoder.Decode(&p.extraFiles),
+ decoder.Decode(&p.absFrom))
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
type extraFilesZip struct {
zip Path
dir InstallPath
}
+func (p *extraFilesZip) GobEncode() ([]byte, error) {
+ w := new(bytes.Buffer)
+ encoder := gob.NewEncoder(w)
+ err := errors.Join(encoder.Encode(p.zip), encoder.Encode(p.dir))
+ if err != nil {
+ return nil, err
+ }
+
+ return w.Bytes(), nil
+}
+
+func (p *extraFilesZip) GobDecode(data []byte) error {
+ r := bytes.NewBuffer(data)
+ decoder := gob.NewDecoder(r)
+ err := errors.Join(decoder.Decode(&p.zip), decoder.Decode(&p.dir))
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
type katiInstalls []katiInstall
// BuiltInstalled returns the katiInstalls in the form used by $(call copy-many-files) in Make, a