soong: add support for module specific lexer flags
To support module specific lexer flags, this follows the same strategy
as the yacc flags:
- add LexProperties to the BaseCompilerProperties
- propagate those flags to the generator generation (i.e. genLex)
- add a placeholder for custom flags
- replace the placeholder with the concatenated flags
This might not support escaping very well, but I figured that this is a
very edge case. Support for escaping etc. could be added later on.
Bug: 159682555
Signed-off-by: Matthias Maennich <maennich@google.com>
Change-Id: I31a3b783bb05213fe1621191031952b41b318103
diff --git a/cc/builder.go b/cc/builder.go
index f2bab8c..9f20b87 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -361,6 +361,7 @@
protoOptionsFile bool
yacc *YaccProperties
+ lex *LexProperties
}
type Objects struct {
diff --git a/cc/cc.go b/cc/cc.go
index 9bf9c84..9196d47 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -210,6 +210,7 @@
protoOptionsFile bool // Whether to look for a .options file next to the .proto
Yacc *YaccProperties
+ Lex *LexProperties
}
// Properties used to compile all C or C++ modules
diff --git a/cc/compiler.go b/cc/compiler.go
index e06243b..e938ed7 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -111,6 +111,7 @@
Gnu_extensions *bool
Yacc *YaccProperties
+ Lex *LexProperties
Aidl struct {
// list of directories that will be added to the aidl include paths.
@@ -289,6 +290,7 @@
flags.Local.YasmFlags = append(flags.Local.YasmFlags, esc(compiler.Properties.Asflags)...)
flags.Yacc = compiler.Properties.Yacc
+ flags.Lex = compiler.Properties.Lex
// Include dir cflags
localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs)
diff --git a/cc/gen.go b/cc/gen.go
index b0aadc6..ccc3d0e 100644
--- a/cc/gen.go
+++ b/cc/gen.go
@@ -34,9 +34,9 @@
var (
lex = pctx.AndroidStaticRule("lex",
blueprint.RuleParams{
- Command: "M4=$m4Cmd $lexCmd -o$out $in",
+ Command: "M4=$m4Cmd $lexCmd $flags -o$out $in",
CommandDeps: []string{"$lexCmd", "$m4Cmd"},
- })
+ }, "flags")
sysprop = pctx.AndroidStaticRule("sysprop",
blueprint.RuleParams{
@@ -153,12 +153,23 @@
}
}
-func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.ModuleGenPath) {
+type LexProperties struct {
+ // list of module-specific flags that will be used for .l and .ll compiles
+ Flags []string
+}
+
+func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.ModuleGenPath, props *LexProperties) {
+ var flags []string
+ if props != nil {
+ flags = props.Flags
+ }
+ flagsString := strings.Join(flags[:], " ")
ctx.Build(pctx, android.BuildParams{
Rule: lex,
Description: "lex " + lexFile.Rel(),
Output: outFile,
Input: lexFile,
+ Args: map[string]string{"flags": flagsString},
})
}
@@ -235,11 +246,11 @@
case ".l":
cFile := android.GenPathWithExt(ctx, "lex", srcFile, "c")
srcFiles[i] = cFile
- genLex(ctx, srcFile, cFile)
+ genLex(ctx, srcFile, cFile, buildFlags.lex)
case ".ll":
cppFile := android.GenPathWithExt(ctx, "lex", srcFile, "cpp")
srcFiles[i] = cppFile
- genLex(ctx, srcFile, cppFile)
+ genLex(ctx, srcFile, cppFile, buildFlags.lex)
case ".proto":
ccFile, headerFile := genProto(ctx, srcFile, buildFlags)
srcFiles[i] = ccFile
diff --git a/cc/util.go b/cc/util.go
index af26268..d115886 100644
--- a/cc/util.go
+++ b/cc/util.go
@@ -97,6 +97,7 @@
protoOptionsFile: in.protoOptionsFile,
yacc: in.Yacc,
+ lex: in.Lex,
}
}