Parse a line in a ``Setup.*`` file.
(line: bytes, python_version: str)
| 156 | |
| 157 | |
| 158 | def parse_setup_line(line: bytes, python_version: str): |
| 159 | """Parse a line in a ``Setup.*`` file.""" |
| 160 | if b"#" in line: |
| 161 | line = line[: line.index(b"#")].rstrip() |
| 162 | |
| 163 | if not line: |
| 164 | return |
| 165 | |
| 166 | words = line.split() |
| 167 | |
| 168 | extension = words[0].decode("ascii") |
| 169 | |
| 170 | objs = set() |
| 171 | links = set() |
| 172 | frameworks = set() |
| 173 | |
| 174 | for i, word in enumerate(words): |
| 175 | # Arguments looking like C source files are converted to object files. |
| 176 | if word.endswith(b".c"): |
| 177 | # Object files are named according to the basename: parent |
| 178 | # directories they may happen to reside in are stripped out. |
| 179 | source_path = pathlib.Path(word.decode("ascii")) |
| 180 | |
| 181 | # Python 3.11 changed the path of the object file. |
| 182 | if meets_python_minimum_version(python_version, "3.11") and b"/" in word: |
| 183 | obj_path = ( |
| 184 | pathlib.Path("Modules") |
| 185 | / source_path.parent |
| 186 | / source_path.with_suffix(".o").name |
| 187 | ) |
| 188 | else: |
| 189 | obj_path = pathlib.Path("Modules") / source_path.with_suffix(".o").name |
| 190 | |
| 191 | objs.add(obj_path) |
| 192 | |
| 193 | # Arguments looking like link libraries are converted to library |
| 194 | # dependencies. |
| 195 | elif word.startswith(b"-l"): |
| 196 | links.add(word[2:].decode("ascii")) |
| 197 | |
| 198 | elif word.startswith(b"-hidden-l"): |
| 199 | links.add(word[len("-hidden-l") :].decode("ascii")) |
| 200 | |
| 201 | elif word == b"-framework": |
| 202 | frameworks.add(words[i + 1].decode("ascii")) |
| 203 | |
| 204 | return { |
| 205 | "extension": extension, |
| 206 | "line": line, |
| 207 | "posix_obj_paths": objs, |
| 208 | "links": links, |
| 209 | "frameworks": frameworks, |
| 210 | "variant": "default", |
| 211 | } |
| 212 | |
| 213 | |
| 214 | def link_for_target(lib: str, target_triple: str) -> str: |
no test coverage detected