From 85dcff9a3feaab9497bc947d6b73f8b0145a6195 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Wed, 2 Jul 2003 04:39:48 +0000 Subject: [PATCH] When an input yacc file ends in .yy and the yacc -d flag is used, expect a generated .hpp file, not a .h file. git-svn-id: http://scons.tigris.org/svn/scons/trunk@731 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 5 +++++ src/engine/SCons/Defaults.py | 21 +++++++++++++-------- test/YACC.py | 26 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 5ef9a7f2..03bd9dea 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -12,6 +12,11 @@ RELEASE 0.XX - XXX From Steven Knight: + - Tighten up the scons -H help output. + + - When the input yacc file ends in .yy and the -d flag is specified, + recognize that a .hpp file (not a .h file) will be created. + RELEASE 0.90 - Wed, 25 Jun 2003 14:24:52 -0500 diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index 6fa053d2..e2bb3b43 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -69,14 +69,19 @@ CScan = SCons.Scanner.C.CScan() FortranScan = SCons.Scanner.Fortran.FortranScan() def yaccEmitter(target, source, env, **kw): - # Yacc can be configured to emit a .h file as well - # as a .c file, if -d is specified on the command line. - if len(source) and \ - os.path.splitext(SCons.Util.to_String(source[0]))[1] in \ - [ '.y', '.yy'] and \ - '-d' in string.split(env.subst("$YACCFLAGS")): - target.append(os.path.splitext(SCons.Util.to_String(target[0]))[0] + \ - '.h') + # If -d is specified on the command line, yacc will emit a .h + # or .hpp file as well as a .c or .cpp file, depending on whether + # the input file is a .y or .yy, respectively. + if len(source) and '-d' in string.split(env.subst("$YACCFLAGS")): + suff = os.path.splitext(SCons.Util.to_String(source[0]))[1] + h = None + if suff == '.y': + h = '.h' + elif suff == '.yy': + h = '.hpp' + if h: + base = os.path.splitext(SCons.Util.to_String(target[0]))[0] + target.append(base + h) return (target, source) def CFile(): diff --git a/test/YACC.py b/test/YACC.py index 68a0ba52..a93b9688 100644 --- a/test/YACC.py +++ b/test/YACC.py @@ -103,6 +103,8 @@ yacc = foo.Dictionary('YACC') bar = Environment(YACC = r'%s wrapper.py ' + yacc) foo.Program(target = 'foo', source = 'foo.y') bar.Program(target = 'bar', source = 'bar.y') +foo.Program(target = 'hello', source = ['hello.cpp']) +foo.CXXFile(target = 'file.cpp', source = ['file.yy'], YACCFLAGS='-d') """ % python) yacc = r""" @@ -135,6 +137,26 @@ letter: 'a' | 'b'; newline: '\n'; """ + test.write("file.yy", """\ +%token GRAPH_T NODE_T EDGE_T DIGRAPH_T EDGEOP_T SUBGRAPH_T + +%pure_parser + +%% +graph: GRAPH_T + ; + +%% +""") + + test.write("hello.cpp", """\ +#include "file.hpp" + +int main() +{ +} +""") + test.write('foo.y', yacc % 'foo.y') test.write('bar.y', yacc % 'bar.y') @@ -161,4 +183,8 @@ newline: '\n'; test.fail_test(os.path.exists(test.workpath('foo.h'))) + test.run(arguments = '.') + + test.up_to_date(arguments = '.') + test.pass_test() -- 2.26.2