wscript (1925B)
1 #! /usr/bin/env python 2 # encoding: utf-8 3 # Alibek Omarov, 2019 (a1batross) 4 5 import os 6 from waflib import ConfigSet, Logs 7 8 VERSION='0.0.1' 9 APPNAME='clang_compilation_database_test' 10 11 top = '.' 12 out = 'build' 13 14 INCLUDES_TO_TEST = ['common'] # check if include flag appeared in result json 15 DEFINES_TO_TEST = ['TEST'] # check if definition flag will appear in result json 16 SOURCE_FILES_TO_TEST = ['a.c', 'b.cpp'] # check if source files are persist in database 17 18 def actual_test(bld): 19 db = bld.bldnode.find_node('compile_commands.json').read_json() 20 21 for entry in db: 22 env = ConfigSet.ConfigSet() 23 line = ' '.join(entry['arguments'][1:]) # ignore compiler exe, unneeded 24 directory = entry['directory'] 25 srcname = entry['file'].split(os.sep)[-1] # file name only 26 27 bld.parse_flags(line, 'test', env) # ignore unhandled flag, it's harmless for test 28 29 if bld.bldnode.abspath() in directory: 30 Logs.info('Directory test passed') 31 else: 32 Logs.error('Directory test failed') 33 34 if srcname in SOURCE_FILES_TO_TEST: 35 Logs.info('Source file test passed') 36 else: 37 Logs.error('Source file test failed') 38 39 passed = True 40 for inc in INCLUDES_TO_TEST: 41 if inc not in env.INCLUDES_test: 42 passed = False 43 44 if passed: Logs.info('Includes test passed') 45 else: Logs.error('Includes test failed') 46 47 passed = True 48 for define in DEFINES_TO_TEST: 49 if define not in env.DEFINES_test: 50 passed = False 51 if passed: Logs.info('Defines test passed') 52 else: Logs.error('Defines test failed') 53 54 def options(opt): 55 # check by ./waf clangdb 56 opt.load('compiler_c compiler_cxx clang_compilation_database') 57 58 def configure(conf): 59 # check if database always generated before build 60 conf.load('compiler_c compiler_cxx clang_compilation_database') 61 62 def build(bld): 63 bld.shlib(features = 'c cxx', source = SOURCE_FILES_TO_TEST, 64 defines = DEFINES_TO_TEST, 65 includes = INCLUDES_TO_TEST, 66 target = 'test') 67 68 bld.add_post_fun(actual_test)