Skip to content

Commit 126ef42

Browse files
committed
chore: use host tool provider
Android's modules after ModuleBase.GenerateBuildActions is finished should use module's providers instead of direct access, cause CleanupAfterBuildActions() is called who frees memory attached to the module. Try to obtain host_bin path trough module providers rather than by direct access of its properties. Changes are done with soong compat layers as there are differences in Soong's versions. Change-Id: If726c22be164ee604ee341fd02b3a8092ed2a35b Signed-off-by: Sebastian Birunt <sebastian.birunt@arm.com>
1 parent 9924cf6 commit 126ef42

6 files changed

Lines changed: 102 additions & 7 deletions

File tree

core/androidbp_backend.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ func getSoongCompatFile(config *BobConfig) string {
310310
text: "a.SetPath(\"LOCAL_SOONG_INSTALLED_MODULE\", base.katiInstalls[len(base.katiInstalls)-1].to)\n",
311311
}
312312

313+
androidHostToolProviderInfoProviderMatcher := codeMatcher{
314+
filename: "build/soong/android/module.go",
315+
text: "\nvar HostToolProviderInfoProvider = blueprint.NewProvider[HostToolProviderInfo]()\n",
316+
}
317+
313318
// List of compatibility layers, ordered from oldest Soong version
314319
// support to newest.
315320
allSoongCompats := []compatVersion{
@@ -337,9 +342,20 @@ func getSoongCompatFile(config *BobConfig) string {
337342
androidMkExtraEntriesContextMatcher,
338343
androidMkSoongInstallTargetsMatcher,
339344
},
340-
[]int{13},
345+
[]int{13, 14, 15},
341346
"soong_compat_02_AndroidMkSoongInstallTargets.go",
342347
},
348+
// Soong HostToolProviderInfoProvider
349+
{
350+
[]codeMatcher{
351+
listOfAndroidMkEntriesMatcher,
352+
androidMkExtraEntriesContextMatcher,
353+
androidMkSoongInstallTargetsMatcher,
354+
androidHostToolProviderInfoProviderMatcher,
355+
},
356+
[]int{16},
357+
"soong_compat_03_HostBinProvider.go",
358+
},
343359
}
344360

345361
android_platform_version := config.Properties.GetInt("android_platform_version")

internal/soong_compat/soong_compat_00_pqr.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package soong_compat
55

66
import (
77
"android/soong/android"
8+
"fmt"
9+
"github.com/google/blueprint"
810
)
911

1012
// This definition is compatible with Soong SHAs _before_ `aa2555387 Add ctx to
@@ -21,3 +23,16 @@ func ConvertAndroidMkExtraEntriesFunc(f AndroidMkExtraEntriesFunc) []android.And
2123
func SoongSupportsMkInstallTargets() bool {
2224
return false
2325
}
26+
27+
// This definition is compatible with Soong SHAs _before_
28+
// `dd9ccb4234dfc88a004e36b2c0500769a5f50ad3
29+
// Add ModuleProxy that should be used when visiting deps.`
30+
func GetHostBinPath(ctx android.ModuleContext, m blueprint.Module, host_bin string) android.OptionalPath {
31+
htp, ok := m.(android.HostToolProvider)
32+
33+
if !ok {
34+
panic(fmt.Errorf("%s is not a host tool", host_bin))
35+
}
36+
37+
return htp.HostToolPath()
38+
}

internal/soong_compat/soong_compat_01_AndroidMkExtraEntries_ctx.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package soong_compat
55

66
import (
77
"android/soong/android"
8+
"fmt"
9+
"github.com/google/blueprint"
810
)
911

1012
// This definition is compatible with Soong SHAs after `aa2555387 Add ctx to
@@ -20,3 +22,16 @@ func ConvertAndroidMkExtraEntriesFunc(f AndroidMkExtraEntriesFunc) []android.And
2022
func SoongSupportsMkInstallTargets() bool {
2123
return false
2224
}
25+
26+
// This definition is compatible with Soong SHAs _before_
27+
// `dd9ccb4234dfc88a004e36b2c0500769a5f50ad3
28+
// Add ModuleProxy that should be used when visiting deps.`
29+
func GetHostBinPath(ctx android.ModuleContext, m blueprint.Module, host_bin string) android.OptionalPath {
30+
htp, ok := m.(android.HostToolProvider)
31+
32+
if !ok {
33+
panic(fmt.Errorf("%s is not a host tool", host_bin))
34+
}
35+
36+
return htp.HostToolPath()
37+
}

internal/soong_compat/soong_compat_02_AndroidMkSoongInstallTargets.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package soong_compat
55

66
import (
77
"android/soong/android"
8+
"fmt"
9+
"github.com/google/blueprint"
810
)
911

1012
// This definition is compatible with Soong SHAs after `aa2555387 Add ctx to
@@ -20,3 +22,16 @@ func ConvertAndroidMkExtraEntriesFunc(f AndroidMkExtraEntriesFunc) []android.And
2022
func SoongSupportsMkInstallTargets() bool {
2123
return true
2224
}
25+
26+
// This definition is compatible with Soong SHAs _before_
27+
// `dd9ccb4234dfc88a004e36b2c0500769a5f50ad3
28+
// Add ModuleProxy that should be used when visiting deps.`
29+
func GetHostBinPath(ctx android.ModuleContext, m blueprint.Module, host_bin string) android.OptionalPath {
30+
htp, ok := m.(android.HostToolProvider)
31+
32+
if !ok {
33+
panic(fmt.Errorf("%s is not a host tool", host_bin))
34+
}
35+
36+
return htp.HostToolPath()
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//go:build soong
2+
// +build soong
3+
4+
package soong_compat
5+
6+
import (
7+
"android/soong/android"
8+
"fmt"
9+
"github.com/google/blueprint"
10+
)
11+
12+
// This definition is compatible with Soong SHAs after `aa2555387 Add ctx to
13+
// AndroidMkExtraEntriesFunc`
14+
func ConvertAndroidMkExtraEntriesFunc(f AndroidMkExtraEntriesFunc) []android.AndroidMkExtraEntriesFunc {
15+
return []android.AndroidMkExtraEntriesFunc{
16+
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
17+
f(entries)
18+
},
19+
}
20+
}
21+
22+
func SoongSupportsMkInstallTargets() bool {
23+
return true
24+
}
25+
26+
// This definition is compatible with Soong SHAs _after_
27+
// `dd9ccb4234dfc88a004e36b2c0500769a5f50ad3
28+
// Add ModuleProxy that should be used when visiting deps.`
29+
func GetHostBinPath(ctx android.ModuleContext, m blueprint.Module, host_bin string) android.OptionalPath {
30+
htp, ok := android.OtherModuleProvider(ctx, m, android.HostToolProviderInfoProvider)
31+
32+
if !ok {
33+
panic(fmt.Errorf("No HostToolProviderInfoProvider for %s module!", host_bin))
34+
}
35+
36+
return htp.HostToolPath
37+
}

plugins/genrulebob/genrule.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package genrulebob
55

66
import (
7-
"fmt"
87
"path/filepath"
98
"regexp"
109
"strconv"
@@ -258,12 +257,10 @@ func (m *genrulebobCommon) getHostBin(ctx android.ModuleContext) android.Optiona
258257
if m.Properties.Host_bin == "" {
259258
return android.OptionalPath{}
260259
}
260+
261261
hostBinModule := ctx.GetDirectDepWithTag(m.Properties.Host_bin, hostToolBinTag)
262-
htp, ok := hostBinModule.(genrule.HostToolProvider)
263-
if !ok {
264-
panic(fmt.Errorf("%s is not a host tool", m.Properties.Host_bin))
265-
}
266-
return htp.HostToolPath()
262+
263+
return soong_compat.GetHostBinPath(ctx, hostBinModule, m.Properties.Host_bin)
267264
}
268265

269266
// Previous Soong version does not contain yet `android.OutputFilesProvider` interface

0 commit comments

Comments
 (0)