Export make vars using MakeVars method

ed023eca73 introduced a new (better) way
of exporting make vars from singletone. apex_keys_text singletone is
switched to the new method.

Test: inspect out/soong/make_vars-<target>.mk
Check SOONG_SOONG_APEX_KEYS_FILE is set

Change-Id: Ia218852ba9ae40070cb6c99340d97e0c77d19841
This commit is contained in:
Jiyong Park
2019-02-20 22:23:29 +09:00
parent e0233a5bdd
commit 37eb8bbb3a

View File

@@ -29,7 +29,6 @@ var String = proptools.String
func init() { func init() {
android.RegisterModuleType("apex_key", apexKeyFactory) android.RegisterModuleType("apex_key", apexKeyFactory)
android.RegisterSingletonType("apex_keys_text", apexKeysTextFactory) android.RegisterSingletonType("apex_keys_text", apexKeysTextFactory)
android.RegisterMakeVarsProvider(pctx, apexKeysFileProvider)
} }
type apexKey struct { type apexKey struct {
@@ -108,11 +107,12 @@ func (m *apexKey) AndroidMk() android.AndroidMkData {
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// apex_keys_text // apex_keys_text
type apexKeysText struct{} type apexKeysText struct {
output android.OutputPath
}
func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) { func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
output := android.PathForOutput(ctx, "apexkeys.txt") s.output = android.PathForOutput(ctx, "apexkeys.txt")
*apexKeysFile(ctx.Config()) = output.String()
var filecontent strings.Builder var filecontent strings.Builder
ctx.VisitAllModules(func(module android.Module) { ctx.VisitAllModules(func(module android.Module) {
if m, ok := module.(android.Module); ok && !m.Enabled() { if m, ok := module.(android.Module); ok && !m.Enabled() {
@@ -131,27 +131,18 @@ func (s *apexKeysText) GenerateBuildActions(ctx android.SingletonContext) {
}) })
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: android.WriteFile, Rule: android.WriteFile,
Description: "apex_keys.txt", Description: "apexkeys.txt",
Output: output, Output: s.output,
Args: map[string]string{ Args: map[string]string{
"content": filecontent.String(), "content": filecontent.String(),
}, },
}) })
} }
var apexKeysFileKey = android.NewOnceKey("apexKeysFile")
func apexKeysFile(config android.Config) *string {
return config.Once(apexKeysFileKey, func() interface{} {
str := ""
return &str
}).(*string)
}
func apexKeysTextFactory() android.Singleton { func apexKeysTextFactory() android.Singleton {
return &apexKeysText{} return &apexKeysText{}
} }
func apexKeysFileProvider(ctx android.MakeVarsContext) { func (s *apexKeysText) MakeVars(ctx android.MakeVarsContext) {
ctx.Strict("SOONG_APEX_KEYS_FILE", *apexKeysFile(ctx.Config())) ctx.Strict("SOONG_APEX_KEYS_FILE", s.output.String())
} }