diff options
Diffstat (limited to 'buildscripts/idl/gen_all_feature_flag_list.py')
| -rw-r--r-- | buildscripts/idl/gen_all_feature_flag_list.py | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/buildscripts/idl/gen_all_feature_flag_list.py b/buildscripts/idl/gen_all_feature_flag_list.py index 88fee6b367f..518583898cb 100644 --- a/buildscripts/idl/gen_all_feature_flag_list.py +++ b/buildscripts/idl/gen_all_feature_flag_list.py @@ -30,6 +30,7 @@ Generate a file containing a list of disabled feature flags. Used by resmoke.py to run only feature flag tests. """ +import argparse import os import sys @@ -42,49 +43,47 @@ sys.path.append(os.path.normpath(os.path.join(os.path.abspath(__file__), '../../ # pylint: disable=wrong-import-position import buildscripts.idl.lib as lib -from buildscripts.idl.idl import parser -def gen_all_feature_flags(idl_dirs: List[str] = None): - """Generate a list of all feature flags.""" - default_idl_dirs = ["src", "buildscripts"] +def is_third_party_idl(idl_path: str) -> bool: + """Check if an IDL file is under a third party directory.""" + third_party_idl_subpaths = [os.path.join("third_party", "mozjs"), "win32com"] - if not idl_dirs: - idl_dirs = default_idl_dirs + for file_name in third_party_idl_subpaths: + if file_name in idl_path: + return True - all_flags = [] - for idl_dir in idl_dirs: - for idl_path in sorted(lib.list_idls(idl_dir)): - if lib.is_third_party_idl(idl_path): - continue - # Most IDL files do not contain feature flags. - # We can discard these quickly without expensive YAML parsing. - with open(idl_path) as idl_file: - if 'feature_flags' not in idl_file.read(): - continue - with open(idl_path) as idl_file: - doc = parser.parse_file(idl_file, idl_path) - for feature_flag in doc.spec.feature_flags: - if feature_flag.default.literal != "true": - all_flags.append(feature_flag.name) - - with open("buildscripts/resmokeconfig/fully_disabled_feature_flags.yml") as fully_disabled_ffs: - force_disabled_flags = yaml.safe_load(fully_disabled_ffs) + return False - return list(set(all_flags) - set(force_disabled_flags)) +def gen_all_feature_flags(idl_dir: str, import_dirs: List[str]): + """Generate a list of all feature flags.""" + all_flags = [] + for idl_path in sorted(lib.list_idls(idl_dir)): + if is_third_party_idl(idl_path): + continue + for feature_flag in lib.parse_idl(idl_path, import_dirs).spec.feature_flags: + if feature_flag.default.literal != "true": + all_flags.append(feature_flag.name) -def gen_all_feature_flags_file(filename: str = lib.ALL_FEATURE_FLAG_FILE): - """Output generated list of feature flags to specified file.""" - flags = gen_all_feature_flags() - with open(filename, "w") as output_file: - output_file.write("\n".join(flags)) - print("Generated: ", os.path.realpath(output_file.name)) + force_disabled_flags = yaml.safe_load( + open("buildscripts/resmokeconfig/fully_disabled_feature_flags.yml")) + + return list(set(all_flags) - set(force_disabled_flags)) def main(): """Run the main function.""" - gen_all_feature_flags_file() + arg_parser = argparse.ArgumentParser(description=__doc__) + arg_parser.add_argument("--import-dir", dest="import_dirs", type=str, action="append", + help="Directory to search for IDL import files") + + args = arg_parser.parse_args() + + flags = gen_all_feature_flags(os.getcwd(), args.import_dirs) + with open(lib.ALL_FEATURE_FLAG_FILE, "w") as output_file: + for flag in flags: + output_file.write("%s\n" % flag) if __name__ == '__main__': |
