diff options
-rwxr-xr-x | builder_test.py | 38 | ||||
-rwxr-xr-x | environment.py | 2 | ||||
-rwxr-xr-x | generators.py | 18 |
3 files changed, 57 insertions, 1 deletions
diff --git a/builder_test.py b/builder_test.py new file mode 100755 index 0000000..df8781c --- /dev/null +++ b/builder_test.py @@ -0,0 +1,38 @@ +#!/usr/bin/python3 -tt + +# Copyright 2013 Jussi Pakkanen + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys, subprocess + +def run_tests(datafilename): + for line in open(datafilename, 'r'): + line = line.strip() + if line == '': + continue + p = subprocess.Popen(line, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (stdo, stde) = p.communicate() + if p.returncode != 0: + print('Error running test.') + print('Stdout:\n' + stdo) + print('Stderr:\n' + stde) + sys.exit(1) + print('Test "%s": OK' % line) + +if __name__ == '__main__': + if len(sys.argv) != 2: + print('Test runner for builder. Do not run on your own, mmm\'kay?') + print('%s [data file]' % sys.argv[0]) + datafile = sys.argv[1] + run_tests(datafile) diff --git a/environment.py b/environment.py index a1fd4ea..4e415ec 100755 --- a/environment.py +++ b/environment.py @@ -144,7 +144,7 @@ class GnuCXXCompiler(CXXCompiler): class ArLinker(): std_flags = ['csr'] - + def __init__(self, exelist): self.exelist = exelist diff --git a/generators.py b/generators.py index b25cf22..af28eb7 100755 --- a/generators.py +++ b/generators.py @@ -148,8 +148,22 @@ class NinjaGenerator(Generator): self.generate_rules(outfile) outfile.write('# Build rules for targets\n\n') [self.generate_target(t, outfile) for t in self.build.get_targets().values()] + outfile.write('# Test rules\n\n') + self.generate_tests(outfile) outfile.write('# Suffix\n\n') self.generate_ending(outfile) + + def generate_tests(self, outfile): + script_root = '..' # FIXME + test_script = os.path.join(script_root, 'builder_test.py') + test_data = os.path.join(self.environment.get_scratch_dir(), 'builder_test_setup.dat') + outfile.write('build test: CUSTOM_COMMAND\n') + outfile.write(' COMMAND = \'%s\' \'%s\'\n\n' % (ninja_quote(test_script), ninja_quote(test_data))) + datafile = open(test_data, 'w') + for t in self.build.get_tests(): + datafile.write(self.get_target_filename(t.get_exe()) + '\n') + datafile.close() + def generate_rules(self, outfile): outfile.write('# Rules for compiling.\n\n') @@ -157,6 +171,10 @@ class NinjaGenerator(Generator): outfile.write('# Rules for linking.\n\n') self.generate_static_link_rules(outfile) self.generate_dynamic_link_rules(outfile) + outfile.write('# Other rules\n\n') + outfile.write('rule CUSTOM_COMMAND\n') + outfile.write(' command = $COMMAND\n') + outfile.write(' restat = 1\n\n') def generate_static_link_rules(self, outfile): static_linker = self.build.static_linker |