Skip to content

Commit 78f96a6

Browse files
pdgendtkartben
authored andcommitted
scripts: west_commands: Add module filter argument to patch command
Allow to run the west patch extension for specific modules only. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent bc42004 commit 78f96a6

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

scripts/west_commands/patch.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ def do_add_parser(self, parser_adder):
114114
default=_WEST_TOPDIR,
115115
type=Path,
116116
)
117+
parser.add_argument(
118+
"-m",
119+
"--module",
120+
action="append",
121+
dest="modules",
122+
metavar="DIR",
123+
type=Path,
124+
help="Zephyr module directory to run the 'patch' command for. "
125+
"Option can be passed multiple times. "
126+
"If this option is not given, the 'patch' command will run for Zephyr "
127+
"and all modules.",
128+
)
117129

118130
subparsers = parser.add_subparsers(
119131
dest="subcommand",
@@ -215,9 +227,9 @@ def do_run(self, args, _):
215227
"list": self.list,
216228
}
217229

218-
method[args.subcommand](args, yml)
230+
method[args.subcommand](args, yml, args.modules)
219231

220-
def apply(self, args, yml):
232+
def apply(self, args, yml, mods=None):
221233
patches = yml.get("patches", [])
222234
if not patches:
223235
return
@@ -227,6 +239,10 @@ def apply(self, args, yml):
227239
patched_mods = set()
228240

229241
for patch_info in patches:
242+
mod = Path(patch_info["module"])
243+
if mods and mod not in mods:
244+
continue
245+
230246
pth = patch_info["path"]
231247
patch_path = os.path.realpath(Path(args.patch_base) / pth)
232248

@@ -262,7 +278,6 @@ def apply(self, args, yml):
262278
patch_count += 1
263279
patch_file_data = None
264280

265-
mod = patch_info["module"]
266281
mod_path = Path(args.west_workspace) / mod
267282
patched_mods.add(mod)
268283

@@ -331,12 +346,14 @@ def clean(self, args, yml, mods=None):
331346

332347
os.chdir(origdir)
333348

334-
def list(self, args, yml):
349+
def list(self, args, yml, mods=None):
335350
patches = yml.get("patches", [])
336351
if not patches:
337352
return
338353

339354
for patch_info in patches:
355+
if mods and Path(patch_info["module"]) not in mods:
356+
continue
340357
self.inf(patch_info)
341358

342359
@staticmethod
@@ -347,7 +364,7 @@ def get_mod_paths(args, yml):
347364

348365
mod_paths = {}
349366
for patch_info in patches:
350-
mod = patch_info["module"]
367+
mod = Path(patch_info["module"])
351368
mod_path = os.path.realpath(Path(args.west_workspace) / mod)
352369
mod_paths[mod] = mod_path
353370

0 commit comments

Comments
 (0)