(
config: ProjectConfig,
objects: Dict[str, Object],
build_config: Optional[BuildConfig],
)
| 1571 | |
| 1572 | |
| 1573 | def generate_compile_commands( |
| 1574 | config: ProjectConfig, |
| 1575 | objects: Dict[str, Object], |
| 1576 | build_config: Optional[BuildConfig], |
| 1577 | ) -> None: |
| 1578 | if build_config is None or not config.generate_compile_commands: |
| 1579 | return |
| 1580 | |
| 1581 | # The following code attempts to convert mwcc flags to clang flags |
| 1582 | # for use with clangd. |
| 1583 | |
| 1584 | # Flags to ignore explicitly |
| 1585 | CFLAG_IGNORE: Set[str] = { |
| 1586 | # Search order modifier |
| 1587 | # Has a different meaning to Clang, and would otherwise |
| 1588 | # be picked up by the include passthrough prefix |
| 1589 | "-I-", |
| 1590 | "-i-", |
| 1591 | } |
| 1592 | CFLAG_IGNORE_PREFIX: Tuple[str, ...] = ( |
| 1593 | # Recursive includes are not supported by modern compilers |
| 1594 | "-ir ", |
| 1595 | ) |
| 1596 | |
| 1597 | # Flags to replace |
| 1598 | CFLAG_REPLACE: Dict[str, str] = {} |
| 1599 | CFLAG_REPLACE_PREFIX: Tuple[Tuple[str, str], ...] = ( |
| 1600 | # Includes |
| 1601 | ("-i ", "-I"), |
| 1602 | ("-I ", "-I"), |
| 1603 | ("-I+", "-I"), |
| 1604 | # Defines |
| 1605 | ("-d ", "-D"), |
| 1606 | ("-D ", "-D"), |
| 1607 | ("-D+", "-D"), |
| 1608 | ) |
| 1609 | |
| 1610 | # Flags with a finite set of options |
| 1611 | CFLAG_REPLACE_OPTIONS: Tuple[Tuple[str, Dict[str, Tuple[str, ...]]], ...] = ( |
| 1612 | # Exceptions |
| 1613 | ( |
| 1614 | "-Cpp_exceptions", |
| 1615 | { |
| 1616 | "off": ("-fno-cxx-exceptions",), |
| 1617 | "on": ("-fcxx-exceptions",), |
| 1618 | }, |
| 1619 | ), |
| 1620 | # RTTI |
| 1621 | ( |
| 1622 | "-RTTI", |
| 1623 | { |
| 1624 | "off": ("-fno-rtti",), |
| 1625 | "on": ("-frtti",), |
| 1626 | }, |
| 1627 | ), |
| 1628 | # Language configuration |
| 1629 | ( |
| 1630 | "-lang", |
no test coverage detected