summaryrefslogtreecommitdiff
path: root/android/module.go
diff options
context:
space:
mode:
author Yu Liu <yudiliu@google.com> 2024-06-11 00:13:02 +0000
committer Yu Liu <yudiliu@google.com> 2024-06-19 00:09:32 +0000
commitfa29764f9f0bd91372fb82b5dcd2250caf38b64b (patch)
treeb6bc66cc8c5ee8de1d366ef83972b0b93152565b /android/module.go
parentd6352efd1a0349a7e58ea48787009e59406ac8a8 (diff)
Experimental code to support build action caching.
Bug: 335718784 Test: build locally Change-Id: Icc1f1fb15f9fe305e95dd51e2e7aff1e9cbf340c
Diffstat (limited to 'android/module.go')
-rw-r--r--android/module.go51
1 files changed, 48 insertions, 3 deletions
diff --git a/android/module.go b/android/module.go
index dc585d295..7e73f70e6 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1913,9 +1913,54 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
return
}
- m.module.GenerateAndroidBuildActions(ctx)
- if ctx.Failed() {
- 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.ModuleId(),
+ InputHash: hash,
+ }
+ }
+
+ restored := false
+ if incrementalAnalysis && cacheKey != nil {
+ restored = ctx.bp.RestoreBuildActions(cacheKey, incrementalModule)
+ }
+
+ if !restored {
+ m.module.GenerateAndroidBuildActions(ctx)
+ if ctx.Failed() {
+ return
+ }
+ }
+
+ if incrementalEnabled && cacheKey != nil {
+ ctx.bp.CacheBuildActions(cacheKey, incrementalModule)
}
// Create the set of tagged dist files after calling GenerateAndroidBuildActions