| 516 | |
| 517 | |
| 518 | class LinuxSourceManager(SourceManager): |
| 519 | def __init__(self, location: Path | None = None) -> None: |
| 520 | super().__init__(location) |
| 521 | |
| 522 | self.patches: list[Path] = [] |
| 523 | self._version: tuple[int, ...] = () |
| 524 | |
| 525 | def get_kernelversion(self) -> str: |
| 526 | return subprocess.run( |
| 527 | ['make', '-s', 'kernelversion'], |
| 528 | capture_output=True, |
| 529 | check=True, |
| 530 | cwd=self.location, |
| 531 | text=True, |
| 532 | ).stdout.strip() |
| 533 | |
| 534 | # Dynamically get the version of the supplied kernel source as a tuple, |
| 535 | # which can be used to check if a provided kernel source is at least a |
| 536 | # particular version. |
| 537 | def get_version(self) -> tuple[int, ...]: |
| 538 | # elem.split('-')[0] in case we are dealing with an -rc release. |
| 539 | if not self._version: |
| 540 | self._version = tuple( |
| 541 | int(elem.split('-')[0]) for elem in self.get_kernelversion().split('.', 3) |
| 542 | ) |
| 543 | return self._version |
| 544 | |
| 545 | def prepare(self) -> None: |
| 546 | self.tarball.download() |
| 547 | # If patches are specified, remove the source folder, we cannot assume |
| 548 | # it has already been patched. |
| 549 | if self.patches: |
| 550 | shutil.rmtree(self.location, ignore_errors=True) |
| 551 | if not self.location.exists(): |
| 552 | self.tarball.extract(self.location) |
| 553 | for patch in self.patches: |
| 554 | patch_cmd = [ |
| 555 | 'patch', |
| 556 | f"--directory={self.location}", |
| 557 | '--forward', |
| 558 | f"--input={patch}", |
| 559 | '--strip=1', |
| 560 | ] |
| 561 | try: |
| 562 | subprocess.run(patch_cmd, capture_output=True, check=True, text=True) |
| 563 | except subprocess.CalledProcessError as err: |
| 564 | # Turns 'patch -N' into a warning versus a hard error; it is |
| 565 | # not the user's fault if we forget to drop a patch that has |
| 566 | # been applied. |
| 567 | if 'Reversed (or previously applied) patch detected' in err.stdout: |
| 568 | tc_build.utils.print_warning( |
| 569 | f"{patch} has already been applied in {self.location}, consider removing it" |
| 570 | ) |
| 571 | else: |
| 572 | raise |
| 573 | else: |
| 574 | tc_build.utils.print_info(f"Applied {patch} to {self.location}") |
| 575 | tc_build.utils.print_info(f"Source successfully prepared in {self.location}") |
no outgoing calls
no test coverage detected