Merge "Allow Singletons to export Make variables"

This commit is contained in:
Treehugger Robot
2019-02-20 08:38:23 +00:00
committed by Gerrit Code Review
3 changed files with 54 additions and 24 deletions

View File

@@ -90,6 +90,25 @@ func RegisterMakeVarsProvider(pctx PackageContext, provider MakeVarsProvider) {
makeVarsProviders = append(makeVarsProviders, makeVarsProvider{pctx, provider}) makeVarsProviders = append(makeVarsProviders, makeVarsProvider{pctx, provider})
} }
// SingletonMakeVarsProvider is a Singleton with an extra method to provide extra values to be exported to Make.
type SingletonMakeVarsProvider interface {
Singleton
// MakeVars uses a MakeVarsContext to provide extra values to be exported to Make.
MakeVars(ctx MakeVarsContext)
}
// registerSingletonMakeVarsProvider adds a singleton that implements SingletonMakeVarsProvider to the list of
// MakeVarsProviders to run.
func registerSingletonMakeVarsProvider(singleton SingletonMakeVarsProvider) {
makeVarsProviders = append(makeVarsProviders, makeVarsProvider{pctx, SingletonmakeVarsProviderAdapter(singleton)})
}
// SingletonmakeVarsProviderAdapter converts a SingletonMakeVarsProvider to a MakeVarsProvider.
func SingletonmakeVarsProviderAdapter(singleton SingletonMakeVarsProvider) MakeVarsProvider {
return func(ctx MakeVarsContext) { singleton.MakeVars(ctx) }
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
func makeVarsSingletonFunc() Singleton { func makeVarsSingletonFunc() Singleton {

View File

@@ -58,6 +58,9 @@ type SingletonFactory func() Singleton
func SingletonFactoryAdaptor(factory SingletonFactory) blueprint.SingletonFactory { func SingletonFactoryAdaptor(factory SingletonFactory) blueprint.SingletonFactory {
return func() blueprint.Singleton { return func() blueprint.Singleton {
singleton := factory() singleton := factory()
if makevars, ok := singleton.(SingletonMakeVarsProvider); ok {
registerSingletonMakeVarsProvider(makevars)
}
return singletonAdaptor{singleton} return singletonAdaptor{singleton}
} }
} }

View File

@@ -44,13 +44,15 @@ func hiddenAPISingletonPaths(ctx android.PathContext) hiddenAPISingletonPathsStr
} }
func hiddenAPISingletonFactory() android.Singleton { func hiddenAPISingletonFactory() android.Singleton {
return hiddenAPISingleton{} return &hiddenAPISingleton{}
} }
type hiddenAPISingleton struct{} type hiddenAPISingleton struct {
flags, metadata android.Path
}
// hiddenAPI singleton rules // hiddenAPI singleton rules
func (hiddenAPISingleton) GenerateBuildActions(ctx android.SingletonContext) { func (h *hiddenAPISingleton) GenerateBuildActions(ctx android.SingletonContext) {
// Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true
if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
return return
@@ -60,10 +62,24 @@ func (hiddenAPISingleton) GenerateBuildActions(ctx android.SingletonContext) {
// These rules depend on files located in frameworks/base, skip them if running in a tree that doesn't have them. // These rules depend on files located in frameworks/base, skip them if running in a tree that doesn't have them.
if ctx.Config().FrameworksBaseDirExists(ctx) { if ctx.Config().FrameworksBaseDirExists(ctx) {
flagsRule(ctx) h.flags = flagsRule(ctx)
metadataRule(ctx) h.metadata = metadataRule(ctx)
} else { } else {
emptyFlagsRule(ctx) h.flags = emptyFlagsRule(ctx)
}
}
// Export paths to Make. INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/.
// Both paths are used to call dist-for-goals.
func (h *hiddenAPISingleton) MakeVars(ctx android.MakeVarsContext) {
if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
return
}
ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", h.flags.String())
if h.metadata != nil {
ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_GREYLIST_METADATA", h.metadata.String())
} }
} }
@@ -170,7 +186,7 @@ func stubFlagsRule(ctx android.SingletonContext) {
// flagsRule creates a rule to build hiddenapi-flags.csv out of flags.csv files generated for boot image modules and // flagsRule creates a rule to build hiddenapi-flags.csv out of flags.csv files generated for boot image modules and
// the greylists. // the greylists.
func flagsRule(ctx android.SingletonContext) { func flagsRule(ctx android.SingletonContext) android.Path {
var flagsCSV android.Paths var flagsCSV android.Paths
var greylistIgnoreConflicts android.Path var greylistIgnoreConflicts android.Path
@@ -187,7 +203,7 @@ func flagsRule(ctx android.SingletonContext) {
if greylistIgnoreConflicts == nil { if greylistIgnoreConflicts == nil {
ctx.Errorf("failed to find removed_dex_api_filename from hiddenapi-lists-docs module") ctx.Errorf("failed to find removed_dex_api_filename from hiddenapi-lists-docs module")
return return nil
} }
rule := android.NewRuleBuilder() rule := android.NewRuleBuilder()
@@ -216,11 +232,13 @@ func flagsRule(ctx android.SingletonContext) {
commitChangeForRestat(rule, tempPath, outputPath) commitChangeForRestat(rule, tempPath, outputPath)
rule.Build(pctx, ctx, "hiddenAPIFlagsFile", "hiddenapi flags") rule.Build(pctx, ctx, "hiddenAPIFlagsFile", "hiddenapi flags")
return outputPath
} }
// emptyFlagsRule creates a rule to build an empty hiddenapi-flags.csv, which is needed by master-art-host builds that // emptyFlagsRule creates a rule to build an empty hiddenapi-flags.csv, which is needed by master-art-host builds that
// have a partial manifest without frameworks/base but still need to build a boot image. // have a partial manifest without frameworks/base but still need to build a boot image.
func emptyFlagsRule(ctx android.SingletonContext) { func emptyFlagsRule(ctx android.SingletonContext) android.Path {
rule := android.NewRuleBuilder() rule := android.NewRuleBuilder()
outputPath := hiddenAPISingletonPaths(ctx).flags outputPath := hiddenAPISingletonPaths(ctx).flags
@@ -229,11 +247,13 @@ func emptyFlagsRule(ctx android.SingletonContext) {
rule.Command().Text("touch").Output(outputPath.String()) rule.Command().Text("touch").Output(outputPath.String())
rule.Build(pctx, ctx, "emptyHiddenAPIFlagsFile", "empty hiddenapi flags") rule.Build(pctx, ctx, "emptyHiddenAPIFlagsFile", "empty hiddenapi flags")
return outputPath
} }
// metadataRule creates a rule to build hiddenapi-greylist.csv out of the metadata.csv files generated for boot image // metadataRule creates a rule to build hiddenapi-greylist.csv out of the metadata.csv files generated for boot image
// modules. // modules.
func metadataRule(ctx android.SingletonContext) { func metadataRule(ctx android.SingletonContext) android.Path {
var metadataCSV android.Paths var metadataCSV android.Paths
ctx.VisitAllModules(func(module android.Module) { ctx.VisitAllModules(func(module android.Module) {
@@ -255,6 +275,8 @@ func metadataRule(ctx android.SingletonContext) {
Output(outputPath.String()) Output(outputPath.String())
rule.Build(pctx, ctx, "hiddenAPIGreylistMetadataFile", "hiddenapi greylist metadata") rule.Build(pctx, ctx, "hiddenAPIGreylistMetadataFile", "hiddenapi greylist metadata")
return outputPath
} }
// commitChangeForRestat adds a command to a rule that updates outputPath from tempPath if they are different. It // commitChangeForRestat adds a command to a rule that updates outputPath from tempPath if they are different. It
@@ -274,17 +296,3 @@ func commitChangeForRestat(rule *android.RuleBuilder, tempPath, outputPath andro
Text("fi"). Text("fi").
Text(")") Text(")")
} }
func init() {
android.RegisterMakeVarsProvider(pctx, hiddenAPIMakeVars)
}
// Export paths to Make. INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/.
// Both paths are used to call dist-for-goals.
func hiddenAPIMakeVars(ctx android.MakeVarsContext) {
if !ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
singletonPaths := hiddenAPISingletonPaths(ctx)
ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", singletonPaths.flags.String())
ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_GREYLIST_METADATA", singletonPaths.metadata.String())
}
}