Holds arguments of an IWYU invocation.
| 272 | |
| 273 | |
| 274 | class Invocation(object): |
| 275 | """ Holds arguments of an IWYU invocation. """ |
| 276 | def __init__(self, command, cwd, source_file): |
| 277 | self.command = command |
| 278 | self.cwd = cwd |
| 279 | self.source_file = source_file |
| 280 | |
| 281 | def __str__(self): |
| 282 | return ' '.join(self.command) |
| 283 | |
| 284 | @classmethod |
| 285 | def from_compile_command(cls, entry, extra_args): |
| 286 | """ Parse a JSON compilation database entry into new Invocation. """ |
| 287 | if 'arguments' in entry: |
| 288 | # arguments is a command-line in list form. |
| 289 | command = entry['arguments'] |
| 290 | source_file = entry['file'] |
| 291 | elif 'command' in entry: |
| 292 | # command is a command-line in string form, split to list. |
| 293 | command = split_command(entry['command']) |
| 294 | source_file = entry['file'] |
| 295 | else: |
| 296 | raise ValueError('Invalid compilation database entry: %s' % entry) |
| 297 | |
| 298 | # Rewrite the compile command for IWYU |
| 299 | compile_command, compile_args = command[0], command[1:] |
| 300 | if is_msvc_driver(compile_command): |
| 301 | # If the compiler is cl-compatible, let IWYU be cl-compatible. |
| 302 | extra_args = ['--driver-mode=cl'] + extra_args |
| 303 | |
| 304 | command = [IWYU_EXECUTABLE] + extra_args + compile_args |
| 305 | return cls(command, entry['directory'], source_file) |
| 306 | |
| 307 | def start(self, verbose): |
| 308 | """ Run invocation and collect output. """ |
| 309 | if verbose: |
| 310 | print('# %s' % self, file=sys.stderr) |
| 311 | |
| 312 | return Process.start(self) |
| 313 | |
| 314 | |
| 315 | def fixup_compilation_db(compilation_db): |
nothing calls this directly
no outgoing calls
no test coverage detected