diff options
author | Colin Cross <ccross@android.com> | 2017-08-10 17:07:28 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2017-08-11 15:24:11 -0700 |
commit | 0f86d186b1d053f67e3f63ffb9ca5ba2a49bd3f5 (patch) | |
tree | 5241066b0592e1676a7a4a018e1b0c55c543b683 /android/androidmk.go | |
parent | a18e9cfa29d22949d2c005fe2b51c5ffa2bf6379 (diff) | |
download | build_soong-0f86d186b1d053f67e3f63ffb9ca5ba2a49bd3f5.tar.gz build_soong-0f86d186b1d053f67e3f63ffb9ca5ba2a49bd3f5.tar.bz2 build_soong-0f86d186b1d053f67e3f63ffb9ca5ba2a49bd3f5.zip |
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
Diffstat (limited to 'android/androidmk.go')
-rw-r--r-- | android/androidmk.go | 104 |
1 files changed, 54 insertions, 50 deletions
diff --git a/android/androidmk.go b/android/androidmk.go index 2732c82e..46e7fcf2 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -43,9 +43,11 @@ type AndroidMkData struct { OutputFile OptionalPath Disabled bool - Custom func(w io.Writer, name, prefix, moduleDir string) + Custom func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData) Extra []AndroidMkExtraFunc + + preamble bytes.Buffer } type AndroidMkExtraFunc func(w io.Writer, outputFile Path) @@ -166,50 +168,32 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b return nil } - if data.SubName != "" { - name += data.SubName - } + prefix := "" + if amod.ArchSpecific() { + switch amod.Os().Class { + case Host: + prefix = "HOST_" + case HostCross: + prefix = "HOST_CROSS_" + case Device: + prefix = "TARGET_" - if data.Custom != nil { - prefix := "" - if amod.ArchSpecific() { - switch amod.Os().Class { - case Host: - prefix = "HOST_" - case HostCross: - prefix = "HOST_CROSS_" - case Device: - prefix = "TARGET_" - - } - - config := ctx.Config().(Config) - if amod.Arch().ArchType != config.Targets[amod.Os().Class][0].Arch.ArchType { - prefix = "2ND_" + prefix - } } - data.Custom(w, name, prefix, filepath.Dir(ctx.BlueprintFile(mod))) - - return nil - } - - if data.Disabled { - return nil - } - - if !data.OutputFile.Valid() { - return nil + config := ctx.Config().(Config) + if amod.Arch().ArchType != config.Targets[amod.Os().Class][0].Arch.ArchType { + prefix = "2ND_" + prefix + } } - 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()) + fmt.Fprintln(&data.preamble, "\ninclude $(CLEAR_VARS)") + fmt.Fprintln(&data.preamble, "LOCAL_PATH :=", filepath.Dir(ctx.BlueprintFile(mod))) + 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 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() @@ -218,48 +202,68 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b case Host: // Make cannot identify LOCAL_MODULE_HOST_ARCH:= common. if archStr != "common" { - fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr) + fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_ARCH :=", archStr) } host = true case HostCross: // Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= 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 case Device: // Make cannot identify LOCAL_MODULE_TARGET_ARCH:= 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 { - 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 { - 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 { - fmt.Fprintln(w, "LOCAL_PROPRIETARY_MODULE := true") + fmt.Fprintln(&data.preamble, "LOCAL_PROPRIETARY_MODULE := true") } if amod.commonProperties.Vendor { - fmt.Fprintln(w, "LOCAL_VENDOR_MODULE := true") + fmt.Fprintln(&data.preamble, "LOCAL_VENDOR_MODULE := true") } 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 { - fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", amod.Os().String()) - fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") + fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_OS :=", amod.Os().String()) + 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 { extra(w, data.OutputFile.Path()) } fmt.Fprintln(w, "include $(BUILD_PREBUILT)") - - return nil } |