Support handling ModuleMakeVarsProvider and SingletonMakeVarsProvider in soong only dist
This change allows modules that set dist goals via `MakeVars(...)` to be
properly handled in collecting dist contributions in Soong only build.
Test: compare dist directories with/without change in soong+make build and soong only build
Bug: 394365683
Change-Id: I8a81ab17195b687297961dc6f1ee7b4b97cec24c
diff --git a/android/androidmk.go b/android/androidmk.go
index f862a96..cf1589d 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -333,6 +333,25 @@
dest string
}
+func (d *distCopy) String() string {
+ if len(d.dest) == 0 {
+ return d.from.String()
+ }
+ return fmt.Sprintf("%s:%s", d.from.String(), d.dest)
+}
+
+type distCopies []distCopy
+
+func (d *distCopies) Strings() (ret []string) {
+ if d == nil {
+ return
+ }
+ for _, dist := range *d {
+ ret = append(ret, dist.String())
+ }
+ return
+}
+
// Compute the contributions that the module makes to the dist.
func (a *AndroidMkEntries) getDistContributions(mod blueprint.Module) *distContributions {
amod := mod.(Module).base()
@@ -821,6 +840,26 @@
}
}
+func getMakeVarsDistContributions(mctx *makeVarsContext) *distContributions {
+ if len(mctx.dists) == 0 {
+ return nil
+ }
+
+ copyGoals := []*copiesForGoals{}
+ for _, dist := range mctx.dists {
+ for _, goal := range dist.goals {
+ copy := &copiesForGoals{}
+ copy.goals = goal
+ copy.copies = dist.paths
+ copyGoals = append(copyGoals, copy)
+ }
+ }
+
+ contribution := &distContributions{}
+ contribution.copiesForGoals = copyGoals
+ return contribution
+}
+
// getSoongOnlyDataFromMods gathers data from the given modules needed in soong-only builds.
// Currently, this is the dist contributions, and the module-info.json contents.
func getSoongOnlyDataFromMods(ctx fillInEntriesContext, mods []blueprint.Module) ([]distContributions, []*ModuleInfoJSON) {
@@ -853,6 +892,11 @@
}
}
} else {
+ mctx := &makeVarsContext{
+ SingletonContext: ctx.(SingletonContext),
+ config: ctx.Config(),
+ pctx: pctx,
+ }
switch x := mod.(type) {
case AndroidMkDataProvider:
data := x.AndroidMk()
@@ -885,6 +929,21 @@
allDistContributions = append(allDistContributions, *contribution)
}
}
+ case ModuleMakeVarsProvider:
+ if !x.Enabled(ctx) {
+ continue
+ }
+ x.MakeVars(mctx)
+ if contribution := getMakeVarsDistContributions(mctx); contribution != nil {
+ allDistContributions = append(allDistContributions, *contribution)
+ }
+
+ case SingletonMakeVarsProvider:
+ x.MakeVars(mctx)
+ if contribution := getMakeVarsDistContributions(mctx); contribution != nil {
+ allDistContributions = append(allDistContributions, *contribution)
+ }
+
default:
// Not exported to make so no make variables to set.
}