Finish cc.Customizer

The Customizer interface now provides a Flags method that takes a
CustomizerFlagsContext and can call AppendCflags to insert extra cflags
on a module.

Change-Id: I821242e7574e8ff653580325d1bef2998a50e29c
diff --git a/cc/cc.go b/cc/cc.go
index 30228fb..60bc4d4 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -494,8 +494,15 @@
 	ModuleContextIntf
 }
 
+type CustomizerFlagsContext interface {
+	BaseModuleContext
+	AppendCflags(...string)
+	AppendLdflags(...string)
+	AppendAsflags(...string)
+}
+
 type Customizer interface {
-	CustomizeProperties(BaseModuleContext)
+	Flags(CustomizerFlagsContext)
 	Properties() []interface{}
 }
 
@@ -508,12 +515,15 @@
 
 type compiler interface {
 	feature
+	appendCflags([]string)
+	appendAsflags([]string)
 	compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths
 }
 
 type linker interface {
 	feature
 	link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles android.Paths) android.Path
+	appendLdflags([]string)
 	installable() bool
 }
 
@@ -562,7 +572,7 @@
 	multilib android.Multilib
 
 	// delegates, initialize before calling Init
-	customizer Customizer
+	Customizer Customizer
 	features   []feature
 	compiler   compiler
 	linker     linker
@@ -579,8 +589,8 @@
 
 func (c *Module) Init() (blueprint.Module, []interface{}) {
 	props := []interface{}{&c.Properties, &c.unused}
-	if c.customizer != nil {
-		props = append(props, c.customizer.Properties()...)
+	if c.Customizer != nil {
+		props = append(props, c.Customizer.Properties()...)
 	}
 	if c.compiler != nil {
 		props = append(props, c.compiler.props()...)
@@ -621,6 +631,21 @@
 	ctx BaseModuleContext
 }
 
+func (ctx *moduleContextImpl) AppendCflags(flags ...string) {
+	CheckBadCompilerFlags(ctx.ctx, "", flags)
+	ctx.mod.compiler.appendCflags(flags)
+}
+
+func (ctx *moduleContextImpl) AppendAsflags(flags ...string) {
+	CheckBadCompilerFlags(ctx.ctx, "", flags)
+	ctx.mod.compiler.appendAsflags(flags)
+}
+
+func (ctx *moduleContextImpl) AppendLdflags(flags ...string) {
+	CheckBadLinkerFlags(ctx.ctx, "", flags)
+	ctx.mod.linker.appendLdflags(flags)
+}
+
 func (ctx *moduleContextImpl) clang() bool {
 	return ctx.mod.clang(ctx.ctx)
 }
@@ -699,6 +724,10 @@
 	}
 	ctx.ctx = ctx
 
+	if c.Customizer != nil {
+		c.Customizer.Flags(ctx)
+	}
+
 	flags := Flags{
 		Toolchain: c.toolchain(ctx),
 		Clang:     c.clang(ctx),
@@ -847,10 +876,6 @@
 	}
 	ctx.ctx = ctx
 
-	if c.customizer != nil {
-		c.customizer.CustomizeProperties(ctx)
-	}
-
 	c.begin(ctx)
 
 	deps := c.deps(ctx)
@@ -1106,6 +1131,14 @@
 
 var _ compiler = (*baseCompiler)(nil)
 
+func (compiler *baseCompiler) appendCflags(flags []string) {
+	compiler.Properties.Cflags = append(compiler.Properties.Cflags, flags...)
+}
+
+func (compiler *baseCompiler) appendAsflags(flags []string) {
+	compiler.Properties.Asflags = append(compiler.Properties.Asflags, flags...)
+}
+
 func (compiler *baseCompiler) props() []interface{} {
 	return []interface{}{&compiler.Properties}
 }
@@ -1317,6 +1350,10 @@
 	}
 }
 
+func (linker *baseLinker) appendLdflags(flags []string) {
+	linker.Properties.Ldflags = append(linker.Properties.Ldflags, flags...)
+}
+
 func (linker *baseLinker) begin(ctx BaseModuleContext) {
 	if ctx.toolchain().Is64Bit() {
 		linker.dynamicProperties.RunPaths = []string{"../lib64", "lib64"}
@@ -1866,6 +1903,10 @@
 	return module.Init()
 }
 
+func (object *objectLinker) appendLdflags(flags []string) {
+	panic(fmt.Errorf("appendLdflags on object Linker not supported"))
+}
+
 func (object *objectLinker) props() []interface{} {
 	return []interface{}{&object.Properties}
 }