diff --git a/tools/configure.py b/tools/configure.py index 74e545e9..35f22033 100644 --- a/tools/configure.py +++ b/tools/configure.py @@ -520,6 +520,18 @@ def main(): copy_and_cquote(license_file, os.path.join(tempdir, 'LICENSE.txt.tmp')) copy_and_cquote(authors_file, os.path.join(tempdir, 'AUTHORS.rst.tmp')) + # Scan used stridx, bidx, config options, etc. + + res = exec_get_stdout([ + sys.executable, + os.path.join(script_path, 'scan_used_stridx_bidx.py') + ] + glob.glob(os.path.join(srcdir, '*.c')) \ + + glob.glob(os.path.join(srcdir, '*.h')) \ + + glob.glob(os.path.join(srcdir, '*.h.in')) + ) + with open(os.path.join(tempdir, 'duk_used_stridx_bidx_defs.json.tmp'), 'wb') as f: + f.write(res) + # Create a duk_config.h. # XXX: might be easier to invoke genconfig directly, but there are a few # options which currently conflict (output file, git commit info, etc). @@ -572,7 +584,8 @@ def main(): sys.executable, os.path.join(script_path, 'genconfig.py'), '--output', os.path.join(tempdir, 'duk_config.h.tmp'), '--output-active-options', os.path.join(tempdir, 'duk_config_active_options.json'), - '--git-commit', git_commit, '--git-describe', git_describe, '--git-branch', git_branch + '--git-commit', git_commit, '--git-describe', git_describe, '--git-branch', git_branch, + '--used-stridx-metadata', os.path.join(tempdir, 'duk_used_stridx_bidx_defs.json.tmp') ] cmd += forward_genconfig_options() cmd += [ @@ -617,16 +630,6 @@ def main(): # There are currently no profile specific variants of strings/builtins, but # this will probably change when functions are added/removed based on profile. - res = exec_get_stdout([ - sys.executable, - os.path.join(script_path, 'scan_used_stridx_bidx.py') - ] + glob.glob(os.path.join(srcdir, '*.c')) \ - + glob.glob(os.path.join(srcdir, '*.h')) \ - + glob.glob(os.path.join(srcdir, '*.h.in')) - ) - with open(os.path.join(tempdir, 'duk_used_stridx_bidx_defs.json.tmp'), 'wb') as f: - f.write(res) - cmd = [ sys.executable, os.path.join(script_path, 'genbuiltins.py'), diff --git a/tools/genconfig.py b/tools/genconfig.py index a7d71907..4bc1046d 100644 --- a/tools/genconfig.py +++ b/tools/genconfig.py @@ -1318,6 +1318,32 @@ def generate_duk_config_header(opts, meta_dir): ret.empty() # for trailing newline return remove_duplicate_newlines(ret.join()), active_opts +# +# Misc +# + +# Validate DUK_USE_xxx config options found in source code against known +# config metadata. Also warn about non-removed config options that are +# not found in the source. +def validate_config_options_in_source(fn): + with open(fn, 'rb') as f: + doc = json.loads(f.read()) + + defs_used = {} + + for opt in doc.get('used_duk_use_options'): + defs_used[opt] = True + if opt == 'DUK_USE_xxx' or opt == 'DUK_USE_XXX': + continue # allow common placeholders + meta = use_defs.get(opt) + if meta is None: + raise Exception('unknown config option in source code: %r' % opt) + + for meta in use_defs_list: + if not defs_used.has_key(meta['define']): + if not meta.has_key('removed'): + logger.info('config option %r not found in source code' % meta['define']) + # # Main # @@ -1393,6 +1419,7 @@ def add_genconfig_optparse_options(parser, direct=False): parser.add_option('--use-cpp-warning', dest='use_cpp_warning', action='store_true', default=False, help='emit a (non-portable) #warning when appropriate') if direct: + parser.add_option('--used-stridx-metadata', dest='used_stridx_metadata', default=None, help='metadata for used stridx, bidx, DUK_USE_xxx') parser.add_option('--git-commit', dest='git_commit', default=None, help='git commit hash to be included in header comments') parser.add_option('--git-describe', dest='git_describe', default=None, help='git describe string to be included in header comments') parser.add_option('--git-branch', dest='git_branch', default=None, help='git branch string to be included in header comments') @@ -1445,6 +1472,9 @@ def genconfig(opts, args): (metadata_src_text, len(use_defs.keys()), len(helper_snippets))) logger.debug('Tags: %r' % use_tags_list) + if opts.used_stridx_metadata is not None: + validate_config_options_in_source(opts.used_stridx_metadata) + if len(args) == 0: raise Exception('missing command') cmd = args[0] diff --git a/tools/scan_used_stridx_bidx.py b/tools/scan_used_stridx_bidx.py index e9631e8d..ff96882e 100644 --- a/tools/scan_used_stridx_bidx.py +++ b/tools/scan_used_stridx_bidx.py @@ -19,10 +19,12 @@ re_str_stridx = re.compile(r'DUK_STRIDX_(\w+)', re.MULTILINE) re_str_heap = re.compile(r'DUK_HEAP_STRING_(\w+)', re.MULTILINE) re_str_hthread = re.compile(r'DUK_HTHREAD_STRING_(\w+)', re.MULTILINE) re_obj_bidx = re.compile(r'DUK_BIDX_(\w+)', re.MULTILINE) +re_duk_use = re.compile(r'DUK_USE_(\w+)', re.MULTILINE) def main(): str_defs = {} obj_defs = {} + opt_defs = {} for fn in sys.argv[1:]: with open(fn, 'rb') as f: @@ -35,20 +37,20 @@ def main(): str_defs[m.group(1)] = True for m in re.finditer(re_obj_bidx, d): obj_defs[m.group(1)] = True + for m in re.finditer(re_duk_use, d): + opt_defs[m.group(1)] = True - str_used = [] - for k in sorted(str_defs.keys()): - str_used.append('DUK_STRIDX_' + k) - - obj_used = [] - for k in sorted(obj_defs.keys()): - obj_used.append('DUK_BIDX_' + k) + str_used = ['DUK_STRIDX_' + x for x in sorted(str_defs.keys())] + obj_used = ['DUK_BIDX_' + x for x in sorted(obj_defs.keys())] + opt_used = ['DUK_USE_' + x for x in sorted(opt_defs.keys())] doc = { 'used_stridx_defines': str_used, 'used_bidx_defines': obj_used, + 'used_duk_use_options': opt_used, 'count_used_stridx_defines': len(str_used), - 'count_used_bidx_defines': len(obj_used) + 'count_used_bidx_defines': len(obj_used), + 'count_duk_use_options': len(opt_used), } print(json.dumps(doc, indent=4))