def process_line(root_directory, file_directory, command_prefix, relative_path):
"""A tool for generating compile_commands.json in the Linux kernel."""
_DEFAULT_OUTPUT = 'compile_commands.json'
_DEFAULT_LOG_LEVEL = 'WARNING'
_FILENAME_PATTERN = r'^\..*\.cmd$'
_LINE_PATTERN = r'^cmd_[^ ]*\.o := (.* )([^ ]*\.c)$'
_VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
_LOW_COUNT_THRESHOLD = 500
"""Sets up and parses command-line arguments.
log_level: A logging level to filter log output.
directory: The directory to search for .cmd files.
output: Where to write the compile-commands JSON file.
usage = 'Creates a compile_commands.json database from kernel .cmd files'
parser = argparse.ArgumentParser(description=usage)
directory_help = ('Path to the kernel source directory to search '
'(defaults to the working directory)')
parser.add_argument('-d', '--directory', type=str, help=directory_help)
output_help = ('The location to write compile_commands.json (defaults to '
'compile_commands.json in the search directory)')
parser.add_argument('-o', '--output', type=str, help=output_help)
log_level_help = ('The level of log messages to produce (one of ' +
', '.join(_VALID_LOG_LEVELS) + '; defaults to ' +
_DEFAULT_LOG_LEVEL + ')')
'--log_level', type=str, default=_DEFAULT_LOG_LEVEL,
args = parser.parse_args()
log_level = args.log_level
if log_level not in _VALID_LOG_LEVELS:
raise ValueError('%s is not a valid log level' % log_level)
directory = args.directory or os.getcwd()
output = args.output or os.path.join(directory, _DEFAULT_OUTPUT)
directory = os.path.abspath(directory)