Allow AndroidMkData.Custom handlers to extend normal values

Pass accumulated AndroidMkData to AndroidMkData.Custom handlers
and expose WriteAndroidMkData so that Custom handlers can write
out the normal make variables and then add their own.

Test: No change to out/soong/Android-aosp_sailfish.mk
Change-Id: Id9717132bbd6c5cf3af8596f3eaa9bbb05d98e40
This commit is contained in:
Colin Cross 2017-08-10 17:07:28 -07:00
parent a18e9cfa29
commit 0f86d186b1
3 changed files with 59 additions and 55 deletions

View file

@ -43,9 +43,11 @@ type AndroidMkData struct {
OutputFile OptionalPath OutputFile OptionalPath
Disabled bool Disabled bool
Custom func(w io.Writer, name, prefix, moduleDir string) Custom func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData)
Extra []AndroidMkExtraFunc Extra []AndroidMkExtraFunc
preamble bytes.Buffer
} }
type AndroidMkExtraFunc func(w io.Writer, outputFile Path) type AndroidMkExtraFunc func(w io.Writer, outputFile Path)
@ -166,11 +168,6 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b
return nil return nil
} }
if data.SubName != "" {
name += data.SubName
}
if data.Custom != nil {
prefix := "" prefix := ""
if amod.ArchSpecific() { if amod.ArchSpecific() {
switch amod.Os().Class { switch amod.Os().Class {
@ -189,27 +186,14 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b
} }
} }
data.Custom(w, name, prefix, filepath.Dir(ctx.BlueprintFile(mod))) fmt.Fprintln(&data.preamble, "\ninclude $(CLEAR_VARS)")
fmt.Fprintln(&data.preamble, "LOCAL_PATH :=", filepath.Dir(ctx.BlueprintFile(mod)))
return nil fmt.Fprintln(&data.preamble, "LOCAL_MODULE :=", name+data.SubName)
} fmt.Fprintln(&data.preamble, "LOCAL_MODULE_CLASS :=", data.Class)
fmt.Fprintln(&data.preamble, "LOCAL_PREBUILT_MODULE_FILE :=", data.OutputFile.String())
if data.Disabled {
return nil
}
if !data.OutputFile.Valid() {
return nil
}
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
fmt.Fprintln(w, "LOCAL_PATH :=", filepath.Dir(ctx.BlueprintFile(mod)))
fmt.Fprintln(w, "LOCAL_MODULE :=", name)
fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", data.Class)
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", data.OutputFile.String())
if len(amod.commonProperties.Required) > 0 { if len(amod.commonProperties.Required) > 0 {
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(amod.commonProperties.Required, " ")) fmt.Fprintln(&data.preamble, "LOCAL_REQUIRED_MODULES := "+strings.Join(amod.commonProperties.Required, " "))
} }
archStr := amod.Arch().ArchType.String() archStr := amod.Arch().ArchType.String()
@ -218,48 +202,68 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b
case Host: case Host:
// Make cannot identify LOCAL_MODULE_HOST_ARCH:= common. // Make cannot identify LOCAL_MODULE_HOST_ARCH:= common.
if archStr != "common" { if archStr != "common" {
fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr) fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_ARCH :=", archStr)
} }
host = true host = true
case HostCross: case HostCross:
// Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common. // Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common.
if archStr != "common" { if archStr != "common" {
fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr) fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
} }
host = true host = true
case Device: case Device:
// Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common. // Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common.
if archStr != "common" { if archStr != "common" {
fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr) fmt.Fprintln(&data.preamble, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
} }
if len(amod.commonProperties.Logtags) > 0 { if len(amod.commonProperties.Logtags) > 0 {
fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES := ", strings.Join(amod.commonProperties.Logtags, " ")) fmt.Fprintln(&data.preamble, "LOCAL_LOGTAGS_FILES := ", strings.Join(amod.commonProperties.Logtags, " "))
} }
if len(amod.commonProperties.Init_rc) > 0 { if len(amod.commonProperties.Init_rc) > 0 {
fmt.Fprintln(w, "LOCAL_INIT_RC := ", strings.Join(amod.commonProperties.Init_rc, " ")) fmt.Fprintln(&data.preamble, "LOCAL_INIT_RC := ", strings.Join(amod.commonProperties.Init_rc, " "))
} }
if amod.commonProperties.Proprietary { if amod.commonProperties.Proprietary {
fmt.Fprintln(w, "LOCAL_PROPRIETARY_MODULE := true") fmt.Fprintln(&data.preamble, "LOCAL_PROPRIETARY_MODULE := true")
} }
if amod.commonProperties.Vendor { if amod.commonProperties.Vendor {
fmt.Fprintln(w, "LOCAL_VENDOR_MODULE := true") fmt.Fprintln(&data.preamble, "LOCAL_VENDOR_MODULE := true")
} }
if amod.commonProperties.Owner != nil { if amod.commonProperties.Owner != nil {
fmt.Fprintln(w, "LOCAL_MODULE_OWNER :=", *amod.commonProperties.Owner) fmt.Fprintln(&data.preamble, "LOCAL_MODULE_OWNER :=", *amod.commonProperties.Owner)
} }
} }
if host { if host {
fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", amod.Os().String()) fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_OS :=", amod.Os().String())
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") fmt.Fprintln(&data.preamble, "LOCAL_IS_HOST_MODULE := true")
} }
blueprintDir := filepath.Dir(ctx.BlueprintFile(mod))
if data.Custom != nil {
data.Custom(w, name, prefix, blueprintDir, data)
} else {
WriteAndroidMkData(w, data)
}
return nil
}
func WriteAndroidMkData(w io.Writer, data AndroidMkData) {
if data.Disabled {
return
}
if !data.OutputFile.Valid() {
return
}
w.Write(data.preamble.Bytes())
for _, extra := range data.Extra { for _, extra := range data.Extra {
extra(w, data.OutputFile.Path()) extra(w, data.OutputFile.Path())
} }
fmt.Fprintln(w, "include $(BUILD_PREBUILT)") fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
return nil
} }

View file

@ -136,10 +136,10 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
ret.Class = "SHARED_LIBRARIES" ret.Class = "SHARED_LIBRARIES"
} else if library.header() { } else if library.header() {
ret.Custom = func(w io.Writer, name, prefix, moduleDir string) { ret.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
fmt.Fprintln(w, "LOCAL_MODULE :=", name) fmt.Fprintln(w, "LOCAL_MODULE :=", name+data.SubName)
archStr := ctx.Target().Arch.ArchType.String() archStr := ctx.Target().Arch.ArchType.String()
var host bool var host bool
@ -194,10 +194,10 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
} }
func (object *objectLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { func (object *objectLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
ret.Custom = func(w io.Writer, name, prefix, moduleDir string) { ret.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
out := ret.OutputFile.Path() out := ret.OutputFile.Path()
fmt.Fprintln(w, "\n$("+prefix+"OUT_INTERMEDIATE_LIBRARIES)/"+name+objectExtension+":", out.String()) fmt.Fprintln(w, "\n$("+prefix+"OUT_INTERMEDIATE_LIBRARIES)/"+name+data.SubName+objectExtension+":", out.String())
fmt.Fprintln(w, "\t$(copy-file-to-target)") fmt.Fprintln(w, "\t$(copy-file-to-target)")
} }
} }

View file

@ -50,7 +50,7 @@ func (p *phony) GenerateAndroidBuildActions(ctx android.ModuleContext) {
func (p *phony) AndroidMk() android.AndroidMkData { func (p *phony) AndroidMk() android.AndroidMkData {
return android.AndroidMkData{ return android.AndroidMkData{
Custom: func(w io.Writer, name, prefix, moduleDir string) { Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
fmt.Fprintln(w, "LOCAL_MODULE :=", name) fmt.Fprintln(w, "LOCAL_MODULE :=", name)