From f0c73e0f7141be5d5739f3970e8def0acb7803a2 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Tue, 1 Mar 2016 15:15:26 -0800 Subject: Generate .c for .y and .l Soong port of https://android-review.googlesource.com/195737 Change-Id: I9ab6dc149c258f7642bc36c3fa32f90ff7ee51a4 --- cc/gen.go | 43 ++++++++++++++++++++++--------------------- 1 file 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) } } -- cgit v1.2.3