Parse command line arguments and execute tool.
()
| 295 | |
| 296 | |
| 297 | def main() -> int: |
| 298 | """Parse command line arguments and execute tool.""" |
| 299 | parser = argparse.ArgumentParser( |
| 300 | description="A tool to help check binary dependencies and statically included symbols." |
| 301 | ) |
| 302 | parser.add_argument( |
| 303 | "--nm", |
| 304 | metavar="executable", |
| 305 | type=str, |
| 306 | help="Path of the nm tool executable", |
| 307 | default="nm", |
| 308 | ) |
| 309 | parser.add_argument( |
| 310 | "--readelf", |
| 311 | metavar="executable", |
| 312 | type=str, |
| 313 | help="Path of the readelf tool executable", |
| 314 | default="readelf", |
| 315 | ) |
| 316 | parser.add_argument( |
| 317 | "--cxxfilt", |
| 318 | metavar="executable", |
| 319 | type=str, |
| 320 | help="Path of the cxxfilt tool executable", |
| 321 | default="c++filt", |
| 322 | ) |
| 323 | parser.add_argument("--binary", metavar="binary", type=str, help="Binary to check") |
| 324 | parser.add_argument( |
| 325 | "--buck-out", metavar="dir", type=str, help="Buck output directory" |
| 326 | ) |
| 327 | parser.add_argument( |
| 328 | "--check-dependencies", |
| 329 | action="store_true", |
| 330 | help="Check shared library dependencies for a binary", |
| 331 | ) |
| 332 | parser.add_argument( |
| 333 | "--check-disallowed-symbols", |
| 334 | action="store_true", |
| 335 | help="Check for usage of disallowed symbols", |
| 336 | ) |
| 337 | parser.add_argument( |
| 338 | "--check-dynamic", |
| 339 | action="store_true", |
| 340 | help="Check for usage of dynamic symbols", |
| 341 | ) |
| 342 | |
| 343 | args = parser.parse_args() |
| 344 | |
| 345 | exit_status = STATUS_OK |
| 346 | |
| 347 | if args.check_dependencies: |
| 348 | if args.binary is None: |
| 349 | error("--binary flag must be specified when checking dependencies") |
| 350 | status = check_dependencies(args.readelf, Path(args.binary)) |
| 351 | exit_status = bubble_error(exit_status, status) |
| 352 | |
| 353 | if args.check_disallowed_symbols: |
| 354 | if args.buck_out is None: |
no test coverage detected