Allow exporting filegroups to make
Allow sharing lists of files between make and soong by allowing
filegroups to export them as a make variable.
Test: m -j checkbuild
Change-Id: I27ae2f6d180bf01d69a628dbe59edcdba93da015
diff --git a/genrule/filegroup.go b/genrule/filegroup.go
index 4029134..ed206b0 100644
--- a/genrule/filegroup.go
+++ b/genrule/filegroup.go
@@ -16,6 +16,9 @@
import (
"android/soong/android"
+ "io"
+ "strings"
+ "text/template"
)
func init() {
@@ -33,6 +36,10 @@
// the base path is stripped off the path and the remaining path is used as the
// installation directory.
Path string
+
+ // Create a make variable with the specified name that contains the list of files in the
+ // filegroup, relative to the root of the source tree.
+ Export_to_make_var string
}
type fileGroup struct {
@@ -64,3 +71,24 @@
func (fg *fileGroup) Srcs() android.Paths {
return fg.srcs
}
+
+var androidMkTemplate = template.Must(template.New("filegroup").Parse(`
+ifdef {{.makeVar}}
+ $(error variable {{.makeVar}} set by soong module is already set in make)
+endif
+{{.makeVar}} := {{.value}}
+.KATI_READONLY := {{.makeVar}}
+`))
+
+func (fg *fileGroup) AndroidMk() android.AndroidMkData {
+ return android.AndroidMkData{
+ Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
+ if makeVar := fg.properties.Export_to_make_var; makeVar != "" {
+ androidMkTemplate.Execute(w, map[string]string{
+ "makeVar": makeVar,
+ "value": strings.Join(fg.srcs.Strings(), " "),
+ })
+ }
+ },
+ }
+}