MCPcopy Create free account
hub / github.com/bfbbdecomp/bfbb / append_cflags

Function append_cflags

tools/project.py:1681–1741  ·  view source on GitHub ↗
(flags: Iterable[str])

Source from the content-addressed store, hash-verified

1679 cflags: list[str] = []
1680
1681 def append_cflags(flags: Iterable[str]) -> None:
1682 # Match a flag against either a set of concrete flags, or a set of prefixes.
1683 def flag_match(
1684 flag: str, concrete: Set[str], prefixes: Tuple[str, ...]
1685 ) -> bool:
1686 if flag in concrete:
1687 return True
1688
1689 for prefix in prefixes:
1690 if flag.startswith(prefix):
1691 return True
1692
1693 return False
1694
1695 # Determine whether a flag should be ignored.
1696 def should_ignore(flag: str) -> bool:
1697 return flag_match(flag, CFLAG_IGNORE, CFLAG_IGNORE_PREFIX)
1698
1699 # Determine whether a flag should be passed through.
1700 def should_passthrough(flag: str) -> bool:
1701 return flag_match(flag, CFLAG_PASSTHROUGH, CFLAG_PASSTHROUGH_PREFIX)
1702
1703 # Attempts replacement for the given flag.
1704 def try_replace(flag: str) -> bool:
1705 replacement = CFLAG_REPLACE.get(flag)
1706 if replacement is not None:
1707 cflags.append(replacement)
1708 return True
1709
1710 for prefix, replacement in CFLAG_REPLACE_PREFIX:
1711 if flag.startswith(prefix):
1712 cflags.append(flag.replace(prefix, replacement, 1))
1713 return True
1714
1715 for prefix, options in CFLAG_REPLACE_OPTIONS:
1716 if not flag.startswith(prefix):
1717 continue
1718
1719 # "-lang c99" and "-lang=c99" are both generally valid option forms
1720 option = flag.removeprefix(prefix).removeprefix("=").lstrip()
1721 replacements = options.get(option)
1722 if replacements is not None:
1723 cflags.extend(replacements)
1724
1725 return True
1726
1727 return False
1728
1729 for flag in flags:
1730 # Ignore flags first
1731 if should_ignore(flag):
1732 continue
1733
1734 # Then find replacements
1735 if try_replace(flag):
1736 continue
1737
1738 # Pass flags through last

Callers 1

add_unitFunction · 0.85

Calls 3

should_ignoreFunction · 0.85
try_replaceFunction · 0.85
should_passthroughFunction · 0.85

Tested by

no test coverage detected