MCPcopy Create free account
hub / github.com/doldecomp/mkdd / append_cflags

Function append_cflags

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

Source from the content-addressed store, hash-verified

1888 cflags: list[str] = []
1889
1890 def append_cflags(flags: Iterable[str]) -> None:
1891 # Match a flag against either a set of concrete flags, or a set of prefixes.
1892 def flag_match(
1893 flag: str, concrete: Set[str], prefixes: Tuple[str, ...]
1894 ) -> bool:
1895 if flag in concrete:
1896 return True
1897
1898 for prefix in prefixes:
1899 if flag.startswith(prefix):
1900 return True
1901
1902 return False
1903
1904 # Determine whether a flag should be ignored.
1905 def should_ignore(flag: str) -> bool:
1906 return flag_match(flag, CFLAG_IGNORE, CFLAG_IGNORE_PREFIX)
1907
1908 # Determine whether a flag should be passed through.
1909 def should_passthrough(flag: str) -> bool:
1910 return flag_match(flag, CFLAG_PASSTHROUGH, CFLAG_PASSTHROUGH_PREFIX)
1911
1912 # Attempts replacement for the given flag.
1913 def try_replace(flag: str) -> bool:
1914 replacement = CFLAG_REPLACE.get(flag)
1915 if replacement is not None:
1916 cflags.append(replacement)
1917 return True
1918
1919 for prefix, replacement in CFLAG_REPLACE_PREFIX:
1920 if flag.startswith(prefix):
1921 cflags.append(flag.replace(prefix, replacement, 1))
1922 return True
1923
1924 for prefix, options in CFLAG_REPLACE_OPTIONS:
1925 if not flag.startswith(prefix):
1926 continue
1927
1928 # "-lang c99" and "-lang=c99" are both generally valid option forms
1929 option = flag.removeprefix(prefix).removeprefix("=").lstrip()
1930 replacements = options.get(option)
1931 if replacements is not None:
1932 cflags.extend(replacements)
1933
1934 return True
1935
1936 return False
1937
1938 for flag in flags:
1939 # Ignore flags first
1940 if should_ignore(flag):
1941 continue
1942
1943 # Then find replacements
1944 if try_replace(flag):
1945 continue
1946
1947 # Pass flags through last

Callers 1

add_unitFunction · 0.85

Calls 4

should_ignoreFunction · 0.85
try_replaceFunction · 0.85
should_passthroughFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected