python = sys.executable
-if sys.platform == 'win32':
- _exe = '.exe'
-else:
- _exe = ''
-
-lex = None
-for dir in string.split(os.environ['PATH'], os.pathsep):
- l = os.path.join(dir, 'lex' + _exe)
- if os.path.exists(l):
- lex = l
- break
-
test = TestSCons.TestSCons()
-test.no_result(not lex)
+test.write('mylex.py', """
+import getopt
+import string
+import sys
+cmd_opts, args = getopt.getopt(sys.argv[1:], 't', [])
+for a in args:
+ contents = open(a, 'rb').read()
+ sys.stdout.write(string.replace(contents, 'LEX', 'mylex.py'))
+sys.exit(0)
+""")
test.write('SConstruct', """
-Environment().CFile(target = 'foo', source = 'foo.l')
-Environment(CFILESUFFIX = '.xyz').CFile(target = 'bar', source = 'bar.l')
-""")
+env = Environment(LEX = r'%s mylex.py')
+env.CFile(target = 'foo', source = 'foo.l')
+env.Copy(CFILESUFFIX = '.xyz').CFile(target = 'bar', source = 'bar.l')
+""" % python)
-lex = r"""
-%%%%
-a printf("A%sA");
-b printf("B%sB");
-%%%%
+input = r"""
int
-yywrap()
-{
- return 1;
-}
-
-main()
+main(int argc, char *argv[])
{
- yylex();
+ argv[argc++] = "--";
+ printf("LEX\n");
+ printf("%s\n");
+ exit (0);
}
"""
-test.write('foo.l', lex % ('foo.l', 'foo.l'))
+test.write('foo.l', input % 'foo.l')
-test.write('bar.l', lex % ('bar.l', 'bar.l'))
+test.write('bar.l', input % 'bar.l')
test.run(arguments = '.')
python = sys.executable
-if sys.platform == 'win32':
- _exe = '.exe'
-else:
- _exe = ''
-
-lex = None
-for dir in string.split(os.environ['PATH'], os.pathsep):
- l = os.path.join(dir, 'lex' + _exe)
- if os.path.exists(l):
- lex = l
- break
-
test = TestSCons.TestSCons()
-test.no_result(not lex)
+test.write('mylex.py', """
+import getopt
+import string
+import sys
+cmd_opts, args = getopt.getopt(sys.argv[1:], 't', [])
+for a in args:
+ contents = open(a, 'rb').read()
+ sys.stdout.write(string.replace(contents, 'LEX', 'mylex.py'))
+sys.exit(0)
+""")
test.write('SConstruct', """
-Environment().CXXFile(target = 'foo', source = 'foo.ll')
-Environment(CXXFILESUFFIX = '.xyz').CXXFile(target = 'bar', source = 'bar.ll')
-""")
+env = Environment(LEX = r'%s mylex.py')
+env.CXXFile(target = 'foo', source = 'foo.ll')
+env.Copy(CXXFILESUFFIX = '.xyz').CXXFile(target = 'bar', source = 'bar.ll')
+""" % python)
-lex = r"""
-%%%%
-a printf("A%sA");
-b printf("B%sB");
-%%%%
+input = r"""
int
-yywrap()
-{
- return 1;
-}
-
-main()
+main(int argc, char *argv[])
{
- yylex();
+ argv[argc++] = "--";
+ printf("LEX\n");
+ printf("%s\n");
+ exit (0);
}
"""
-test.write('foo.ll', lex % ('foo.ll', 'foo.ll'))
+test.write('foo.ll', input % 'foo.ll')
-test.write('bar.ll', lex % ('bar.ll', 'bar.ll'))
+test.write('bar.ll', input % 'bar.ll')
test.run(arguments = '.')
else:
_exe = ''
+test = TestSCons.TestSCons()
+
+
+
+test.write('mylex.py', """
+import getopt
+import string
+import sys
+cmd_opts, args = getopt.getopt(sys.argv[1:], 't', [])
+for a in args:
+ contents = open(a, 'rb').read()
+ sys.stdout.write(string.replace(contents, 'LEX', 'mylex.py'))
+sys.exit(0)
+""")
+
+test.write('SConstruct', """
+env = Environment(LEX = r'%s mylex.py')
+env.Program(target = 'aaa', source = 'aaa.l')
+""" % python)
+
+test.write('aaa.l', r"""
+int
+main(int argc, char *argv[])
+{
+ argv[argc++] = "--";
+ printf("LEX\n");
+ printf("aaa.l\n");
+ exit (0);
+}
+""")
+
+test.run(arguments = 'aaa' + _exe, stderr = None)
+
+test.run(program = test.workpath('aaa' + _exe), stdout = "mylex.py\naaa.l\n")
+
+
+
lex = None
for dir in string.split(os.environ['PATH'], os.pathsep):
l = os.path.join(dir, 'lex' + _exe)
lex = l
break
-test = TestSCons.TestSCons()
+if lex:
-test.no_result(not lex)
-
-test.write("wrapper.py",
-"""import os
+ test.write("wrapper.py", """import os
import string
import sys
open('%s', 'wb').write("wrapper.py\\n")
os.system(string.join(sys.argv[1:], " "))
""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
-test.write('SConstruct', """
+ test.write('SConstruct', """
foo = Environment()
lex = foo.Dictionary('LEX')
bar = Environment(LEX = r'%s wrapper.py ' + lex)
bar.Program(target = 'bar', source = 'bar.l')
""" % python)
-lex = r"""
+ lex = r"""
%%%%
a printf("A%sA");
b printf("B%sB");
}
"""
-test.write('foo.l', lex % ('foo.l', 'foo.l'))
+ test.write('foo.l', lex % ('foo.l', 'foo.l'))
-test.write('bar.l', lex % ('bar.l', 'bar.l'))
+ test.write('bar.l', lex % ('bar.l', 'bar.l'))
-test.run(arguments = 'foo' + _exe, stderr = None)
+ test.run(arguments = 'foo' + _exe, stderr = None)
-test.fail_test(os.path.exists(test.workpath('wrapper.out')))
+ test.fail_test(os.path.exists(test.workpath('wrapper.out')))
-test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "Afoo.lA\n")
+ test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "Afoo.lA\n")
-test.run(arguments = 'bar' + _exe)
+ test.run(arguments = 'bar' + _exe)
-test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
+ test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
-test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "Bbar.lB\n")
+ test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "Bbar.lB\n")
test.pass_test()
else:
_exe = ''
+test = TestSCons.TestSCons()
+
+
+
+test.write('mylex.py', """
+import getopt
+import string
+import sys
+cmd_opts, args = getopt.getopt(sys.argv[1:], 'tx', [])
+opt_string = ''
+for opt, arg in cmd_opts:
+ opt_string = opt_string + ' ' + opt
+for a in args:
+ contents = open(a, 'rb').read()
+ sys.stdout.write(string.replace(contents, 'LEXFLAGS', opt_string))
+sys.exit(0)
+""")
+
+test.write('SConstruct', """
+env = Environment(LEX = r'%s mylex.py', LEXFLAGS = '-x')
+env.Program(target = 'aaa', source = 'aaa.l')
+""" % python)
+
+test.write('aaa.l', r"""
+int
+main(int argc, char *argv[])
+{
+ argv[argc++] = "--";
+ printf("LEXFLAGS\n");
+ printf("aaa.l\n");
+ exit (0);
+}
+""")
+
+test.run(arguments = 'aaa' + _exe, stderr = None)
+
+test.run(program = test.workpath('aaa' + _exe), stdout = " -x -t\naaa.l\n")
+
+
+
lex = None
for dir in string.split(os.environ['PATH'], os.pathsep):
l = os.path.join(dir, 'lex' + _exe)
lex = l
break
-test = TestSCons.TestSCons()
+if lex:
-test.no_result(not lex)
-
-test.write('SConstruct', """
+ test.write('SConstruct', """
foo = Environment()
bar = Environment(LEXFLAGS = '-b')
foo.Program(target = 'foo', source = 'foo.l')
bar.Program(target = 'bar', source = 'bar.l')
""")
-lex = r"""
+ lex = r"""
%%%%
a printf("A%sA");
b printf("B%sB");
}
"""
-test.write('foo.l', lex % ('foo.l', 'foo.l'))
+ test.write('foo.l', lex % ('foo.l', 'foo.l'))
-test.write('bar.l', lex % ('bar.l', 'bar.l'))
+ test.write('bar.l', lex % ('bar.l', 'bar.l'))
-test.run(arguments = 'foo' + _exe, stderr = None)
+ test.run(arguments = 'foo' + _exe, stderr = None)
-test.fail_test(os.path.exists(test.workpath('lex.backup')))
+ test.fail_test(os.path.exists(test.workpath('lex.backup')))
-test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "Afoo.lA\n")
+ test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "Afoo.lA\n")
-test.run(arguments = 'bar' + _exe)
+ test.run(arguments = 'bar' + _exe)
-test.fail_test(not os.path.exists(test.workpath('lex.backup')))
+ test.fail_test(not os.path.exists(test.workpath('lex.backup')))
-test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "Bbar.lB\n")
+ test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "Bbar.lB\n")
test.pass_test()
else:
_exe = ''
+test = TestSCons.TestSCons()
+
+
+
+test.write('myyacc.py', """
+import getopt
+import string
+import sys
+cmd_opts, args = getopt.getopt(sys.argv[1:], 'o:', [])
+output = None
+opt_string = ''
+for opt, arg in cmd_opts:
+ if opt == '-o': output = open(arg, 'wb')
+ else: opt_string = opt_string + ' ' + opt
+for a in args:
+ contents = open(a, 'rb').read()
+ output.write(string.replace(contents, 'YACC', 'myyacc.py'))
+output.close()
+sys.exit(0)
+""")
+
+test.write('SConstruct', """
+env = Environment(YACC = r'%s myyacc.py')
+env.Program(target = 'aaa', source = 'aaa.y')
+""" % python)
+
+test.write('aaa.y', r"""
+int
+main(int argc, char *argv[])
+{
+ argv[argc++] = "--";
+ printf("YACC\n");
+ printf("aaa.y\n");
+ exit (0);
+}
+""")
+
+test.run(arguments = 'aaa' + _exe, stderr = None)
+
+test.run(program = test.workpath('aaa' + _exe), stdout = "myyacc.py\naaa.y\n")
+
+
+
yacc = None
for dir in string.split(os.environ['PATH'], os.pathsep):
y = os.path.join(dir, 'yacc' + _exe)
yacc = y
break
-test = TestSCons.TestSCons()
+if yacc:
-test.no_result(not yacc)
-
-test.write("wrapper.py",
+ test.write("wrapper.py",
"""import os
import string
import sys
os.system(string.join(sys.argv[1:], " "))
""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
-test.write('SConstruct', """
+ test.write('SConstruct', """
foo = Environment()
yacc = foo.Dictionary('YACC')
bar = Environment(YACC = r'%s wrapper.py ' + yacc)
bar.Program(target = 'bar', source = 'bar.y')
""" % python)
-yacc = r"""
+ yacc = r"""
%%{
#include <stdio.h>
newline: '\n';
"""
-test.write('foo.y', yacc % 'foo.y')
+ test.write('foo.y', yacc % 'foo.y')
-test.write('bar.y', yacc % 'bar.y')
+ test.write('bar.y', yacc % 'bar.y')
-test.run(arguments = 'foo' + _exe, stderr = None)
+ test.run(arguments = 'foo' + _exe, stderr = None)
-test.fail_test(os.path.exists(test.workpath('wrapper.out')))
+ test.fail_test(os.path.exists(test.workpath('wrapper.out')))
-test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n")
+ test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n")
-test.run(arguments = 'bar' + _exe)
+ test.run(arguments = 'bar' + _exe)
-test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
+ test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
-test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "bar.y\n")
+ test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "bar.y\n")
test.pass_test()
else:
_exe = ''
+test = TestSCons.TestSCons()
+
+
+
+test.write('myyacc.py', """
+import getopt
+import string
+import sys
+cmd_opts, args = getopt.getopt(sys.argv[1:], 'o:x', [])
+output = None
+opt_string = ''
+for opt, arg in cmd_opts:
+ if opt == '-o': output = open(arg, 'wb')
+ else: opt_string = opt_string + ' ' + opt
+for a in args:
+ contents = open(a, 'rb').read()
+ output.write(string.replace(contents, 'YACCFLAGS', opt_string))
+output.close()
+sys.exit(0)
+""")
+
+test.write('SConstruct', """
+env = Environment(YACC = r'%s myyacc.py', YACCFLAGS = '-x')
+env.Program(target = 'aaa', source = 'aaa.y')
+""" % python)
+
+test.write('aaa.y', r"""
+int
+main(int argc, char *argv[])
+{
+ argv[argc++] = "--";
+ printf("YACCFLAGS\n");
+ printf("aaa.y\n");
+ exit (0);
+}
+""")
+
+test.run(arguments = 'aaa' + _exe, stderr = None)
+
+test.run(program = test.workpath('aaa' + _exe), stdout = " -x\naaa.y\n")
+
+
+
yacc = None
for dir in string.split(os.environ['PATH'], os.pathsep):
y = os.path.join(dir, 'yacc' + _exe)
yacc = y
break
-test = TestSCons.TestSCons()
+if yacc:
-test.no_result(not yacc)
-
-test.write('SConstruct', """
+ test.write('SConstruct', """
foo = Environment()
bar = Environment(YACCFLAGS = '-v')
foo.Program(target = 'foo', source = 'foo.y')
bar.Program(target = 'bar', source = 'bar.y')
""")
-yacc = r"""
+ yacc = r"""
%%{
#include <stdio.h>
newline: '\n';
"""
-test.write('foo.y', yacc % 'foo.y')
+ test.write('foo.y', yacc % 'foo.y')
-test.write('bar.y', yacc % 'bar.y')
+ test.write('bar.y', yacc % 'bar.y')
-test.run(arguments = 'foo' + _exe, stderr = None)
+ test.run(arguments = 'foo' + _exe, stderr = None)
-test.fail_test(os.path.exists(test.workpath('foo.output'))
+ test.fail_test(os.path.exists(test.workpath('foo.output'))
or os.path.exists(test.workpath('y.output')))
-test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n")
+ test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n")
-test.run(arguments = 'bar' + _exe)
+ test.run(arguments = 'bar' + _exe)
-test.fail_test(not os.path.exists(test.workpath('bar.output'))
+ test.fail_test(not os.path.exists(test.workpath('bar.output'))
and not os.path.exists(test.workpath('y.output')))
-test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "bar.y\n")
+ test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "bar.y\n")
test.pass_test()