aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2016-03-01 15:15:26 -0800
committerDan Willemsen <dwillemsen@google.com>2016-03-01 17:32:31 -0800
commitf0c73e0f7141be5d5739f3970e8def0acb7803a2 (patch)
tree5f3e158d409b8682987dc82a374f83b53bdd0b3e
parentb77bd796c24ed99827edde94a5fa03297e696f0e (diff)
downloadbuild_soong-f0c73e0f7141be5d5739f3970e8def0acb7803a2.tar.gz
build_soong-f0c73e0f7141be5d5739f3970e8def0acb7803a2.tar.bz2
build_soong-f0c73e0f7141be5d5739f3970e8def0acb7803a2.zip
Generate .c for .y and .l
Soong port of https://android-review.googlesource.com/195737 Change-Id: I9ab6dc149c258f7642bc36c3fa32f90ff7ee51a4
-rw-r--r--cc/gen.go43
1 files changed, 22 insertions, 21 deletions
diff --git a/cc/gen.go b/cc/gen.go
index 035f40ed..94e2304c 100644
--- a/cc/gen.go
+++ b/cc/gen.go
@@ -33,12 +33,11 @@ func init() {
var (
yacc = pctx.StaticRule("yacc",
blueprint.RuleParams{
- Command: "BISON_PKGDATADIR=$yaccDataDir $yaccCmd -d $yaccFlags -o $cppFile $in && " +
- "cp -f $hppFile $hFile",
+ Command: "BISON_PKGDATADIR=$yaccDataDir $yaccCmd -d $yaccFlags --defines=$hFile -o $cFile $in",
CommandDeps: []string{"$yaccCmd"},
Description: "yacc $out",
},
- "yaccFlags", "cppFile", "hppFile", "hFile")
+ "yaccFlags", "cFile", "hFile")
lex = pctx.StaticRule("lex",
blueprint.RuleParams{
@@ -48,36 +47,29 @@ var (
})
)
-func genYacc(ctx common.AndroidModuleContext, yaccFile common.Path, yaccFlags string) (cppFile, headerFile common.ModuleGenPath) {
- cppFile = common.GenPathWithExt(ctx, yaccFile, "cpp")
- hppFile := common.GenPathWithExt(ctx, yaccFile, "hpp")
+func genYacc(ctx common.AndroidModuleContext, yaccFile common.Path, outFile common.ModuleGenPath, yaccFlags string) (headerFile common.ModuleGenPath) {
headerFile = common.GenPathWithExt(ctx, yaccFile, "h")
ctx.ModuleBuild(pctx, common.ModuleBuildParams{
Rule: yacc,
- Outputs: common.WritablePaths{cppFile, headerFile},
+ Outputs: common.WritablePaths{outFile, headerFile},
Input: yaccFile,
Args: map[string]string{
"yaccFlags": yaccFlags,
- "cppFile": cppFile.String(),
- "hppFile": hppFile.String(),
+ "cFile": outFile.String(),
"hFile": headerFile.String(),
},
})
- return cppFile, headerFile
+ return headerFile
}
-func genLex(ctx common.AndroidModuleContext, lexFile common.Path) (cppFile common.ModuleGenPath) {
- cppFile = common.GenPathWithExt(ctx, lexFile, "cpp")
-
+func genLex(ctx common.AndroidModuleContext, lexFile common.Path, outFile common.ModuleGenPath) {
ctx.ModuleBuild(pctx, common.ModuleBuildParams{
Rule: lex,
- Output: cppFile,
+ Output: outFile,
Input: lexFile,
})
-
- return cppFile
}
func genSources(ctx common.AndroidModuleContext, srcFiles common.Paths,
@@ -87,13 +79,22 @@ func genSources(ctx common.AndroidModuleContext, srcFiles common.Paths,
for i, srcFile := range srcFiles {
switch srcFile.Ext() {
- case ".y", ".yy":
- cppFile, headerFile := genYacc(ctx, srcFile, buildFlags.yaccFlags)
+ case ".y":
+ cFile := common.GenPathWithExt(ctx, srcFile, "c")
+ srcFiles[i] = cFile
+ deps = append(deps, genYacc(ctx, srcFile, cFile, buildFlags.yaccFlags))
+ case ".yy":
+ cppFile := common.GenPathWithExt(ctx, srcFile, "cpp")
srcFiles[i] = cppFile
- deps = append(deps, headerFile)
- case ".l", ".ll":
- cppFile := genLex(ctx, srcFile)
+ deps = append(deps, genYacc(ctx, srcFile, cppFile, buildFlags.yaccFlags))
+ case ".l":
+ cFile := common.GenPathWithExt(ctx, srcFile, "c")
+ srcFiles[i] = cFile
+ genLex(ctx, srcFile, cFile)
+ case ".ll":
+ cppFile := common.GenPathWithExt(ctx, srcFile, "cpp")
srcFiles[i] = cppFile
+ genLex(ctx, srcFile, cppFile)
}
}