Skip to content

Commit

Permalink
Kernel Installer: Add B4 Modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
adityagesh committed Nov 9, 2024
1 parent 9514b6e commit 139ab4f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lisa/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)

from .aria import Aria
from .b4 import B4
from .blkid import Blkid
from .bzip2 import Bzip2
from .cargo import Cargo
Expand Down Expand Up @@ -128,6 +129,7 @@
__all__ = [
"AptAddRepository",
"Aria",
"B4",
"Blkid",
"Bzip2",
"Cargo",
Expand Down
29 changes: 29 additions & 0 deletions lisa/tools/b4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pathlib
import re
from lisa.executable import Tool
from lisa.operating_system import Posix
from lisa.util import get_matched_str


class B4(Tool):
_output_file_pattern = re.compile(r"[\w-]+\.mbx")

@property
def command(self) -> str:
return "b4"

@property
def can_install(self) -> bool:
return True

def _install(self) -> bool:
if isinstance(self.node.os, Posix):
self.node.os.install_packages("b4")
return self._check_exists()

def am(self, message_id: str, output_dir: pathlib.PurePath) -> pathlib.PurePath:
result = self.run(
f"am -o '{output_dir}' '{message_id}'", force_run=True, expected_exit_code=0
)
path_str = get_matched_str(result.stdout, self._output_file_pattern)
return pathlib.PurePath(output_dir, path_str)
11 changes: 11 additions & 0 deletions lisa/tools/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ def apply(
)
result.assert_exit_code(message=f"failed on applying patches. {result.stdout}")

def am(self, cwd: pathlib.PurePath, patch: pathlib.PurePath) -> None:
result = self.run(
f"am {patch}",
shell=True,
cwd=cwd,
force_run=True,
no_info_log=True,
no_error_log=True,
)
result.assert_exit_code(message=f"failed on applying patches. {result.stdout}")

def list_tags(self, cwd: pathlib.PurePath) -> List[str]:
result = self.run(
"--no-pager tag --color=never",
Expand Down
29 changes: 28 additions & 1 deletion lisa/transformers/kernel_source_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from lisa.base_tools import Mv
from lisa.node import Node
from lisa.operating_system import CBLMariner, Redhat, Ubuntu
from lisa.tools import Cp, Echo, Git, Make, Sed, Uname
from lisa.tools import Cp, Echo, Git, Make, Sed, Uname, B4
from lisa.tools.gcc import Gcc
from lisa.tools.lscpu import Lscpu
from lisa.util import LisaException, field_metadata, subclasses
Expand Down Expand Up @@ -75,6 +75,12 @@ class PatchModifierSchema(BaseModifierSchema):
file_pattern: str = "*.patch"


@dataclass_json()
@dataclass
class b4PatchModifierSchema(BaseModifierSchema):
message_id: str = field(default="", metadata=field_metadata(required=True))


@dataclass_json()
@dataclass
class SourceInstallerSchema(BaseInstallerSchema):
Expand Down Expand Up @@ -489,3 +495,24 @@ def _get_code_path(path: str, node: Node, default_name: str) -> PurePath:
code_path = node.working_path / default_name

return code_path


class b4PatchModifier(BaseModifier):
@classmethod
def type_name(cls) -> str:
return "b4_patch"

@classmethod
def type_schema(cls) -> Type[schema.TypedSchema]:
return b4PatchModifierSchema

def modify(self) -> None:
runbook: b4PatchModifierSchema = self.runbook

git = self._node.tools[Git]
b4 = self._node.tools[B4]

message_id = runbook.message_id
patch_file = b4.am(message_id=message_id, output_dir=self._code_path)

git.am(cwd=self._code_path, patch=patch_file)

0 comments on commit 139ab4f

Please sign in to comment.