@@ -104,7 +104,7 @@ def do_add_parser(self, parser_adder):
104
104
"-b" ,
105
105
"--patch-base" ,
106
106
help = f"""
107
- Directory containing patch files (absolute or relative to module dir,
107
+ Directory containing patch files (absolute or relative to project dir,
108
108
default: { WEST_PATCH_BASE } )""" ,
109
109
metavar = "DIR" ,
110
110
type = Path ,
@@ -113,7 +113,7 @@ def do_add_parser(self, parser_adder):
113
113
"-l" ,
114
114
"--patch-yml" ,
115
115
help = f"""
116
- Path to patches.yml file (absolute or relative to module dir,
116
+ Path to patches.yml file (absolute or relative to project dir,
117
117
default: { WEST_PATCH_YAML } )""" ,
118
118
metavar = "FILE" ,
119
119
type = Path ,
@@ -127,26 +127,26 @@ def do_add_parser(self, parser_adder):
127
127
)
128
128
parser .add_argument (
129
129
"-sm" ,
130
- "--src-module " ,
131
- dest = "src_module " ,
132
- metavar = "MODULE " ,
130
+ "--src-project " ,
131
+ dest = "src_project " ,
132
+ metavar = "PROJECT " ,
133
133
type = str ,
134
134
help = """
135
- Zephyr module containing the patch definition (name, absolute path or
135
+ Zephyr project containing the patch definition (name, absolute path or
136
136
path relative to west-workspace)""" ,
137
137
)
138
138
parser .add_argument (
139
139
"-dm" ,
140
- "--dst-module " ,
140
+ "--dst-project " ,
141
141
action = "append" ,
142
- dest = "dst_modules " ,
143
- metavar = "MODULE " ,
142
+ dest = "dst_project " ,
143
+ metavar = "PROJECT " ,
144
144
type = str ,
145
145
help = """
146
- Zephyr module to run the 'patch' command for.
146
+ Zephyr project to run the 'patch' command for.
147
147
Option can be passed multiple times.
148
148
If this option is not given, the 'patch' command will run for Zephyr
149
- and all modules .""" ,
149
+ and all projects .""" ,
150
150
)
151
151
152
152
subparsers = parser .add_subparsers (
@@ -227,13 +227,13 @@ def do_add_parser(self, parser_adder):
227
227
help = "Github Pull Request ID" ,
228
228
)
229
229
gh_fetch_arg_parser .add_argument (
230
- "-m " ,
231
- "--module " ,
230
+ "-p " ,
231
+ "--project " ,
232
232
metavar = "DIR" ,
233
233
action = "store" ,
234
234
required = True ,
235
235
type = Path ,
236
- help = "Module path" ,
236
+ help = "Project path" ,
237
237
)
238
238
gh_fetch_arg_parser .add_argument (
239
239
"-s" ,
@@ -272,15 +272,15 @@ def filter_args(self, args):
272
272
273
273
topdir = Path (self .topdir )
274
274
275
- if args .src_module is not None :
276
- mod_path = self .get_module_path (args .src_module )
277
- if mod_path is None :
278
- self .die (f'Source module "{ args .src_module } " not found' )
275
+ if args .src_project is not None :
276
+ prj_path = self .get_project_path (args .src_project )
277
+ if prj_path is None :
278
+ self .die (f'Source project "{ args .src_project } " not found' )
279
279
if args .patch_base is not None and args .patch_base .is_absolute ():
280
- self .die ("patch-base must not be an absolute path in combination with src-module " )
280
+ self .die ("patch-base must not be an absolute path in combination with src-project " )
281
281
if args .patch_yml is not None and args .patch_yml .is_absolute ():
282
- self .die ("patch-yml must not be an absolute path in combination with src-module " )
283
- manifest_dir = topdir / mod_path
282
+ self .die ("patch-yml must not be an absolute path in combination with src-project " )
283
+ manifest_dir = topdir / prj_path
284
284
else :
285
285
manifest_dir = topdir / manifest_path
286
286
@@ -299,8 +299,8 @@ def filter_args(self, args):
299
299
elif not args .west_workspace .is_absolute ():
300
300
args .west_workspace = topdir / args .west_workspace
301
301
302
- if args .dst_modules is not None :
303
- args .dst_modules = [self .get_module_path (m ) for m in args .dst_modules ]
302
+ if args .dst_project is not None :
303
+ args .dst_project = [self .get_project_path (m ) for m in args .dst_project ]
304
304
305
305
def load_yml (self , args , allow_missing ):
306
306
if not os .path .isfile (args .patch_yml ):
@@ -339,23 +339,24 @@ def do_run(self, args, _):
339
339
"gh-fetch" : self .gh_fetch ,
340
340
}
341
341
342
- method [args .subcommand ](args , yml , args .dst_modules )
342
+ method [args .subcommand ](args , yml , args .dst_project )
343
343
344
- def apply (self , args , yml , dst_mods = None ):
344
+ def apply (self , args , yml , dst_prjs = None ):
345
345
patches = yml .get ("patches" , [])
346
+
346
347
if not patches :
347
348
return
348
349
349
350
patch_count = 0
350
351
failed_patch = None
351
- patched_mods = set ()
352
+ patched_prjs = set ()
352
353
353
354
for patch_info in patches :
354
- mod = self .get_module_path (patch_info ["module" ])
355
- if mod is None :
355
+ prj = self .get_project_path (patch_info ["module" ])
356
+ if prj is None :
356
357
continue
357
358
358
- if dst_mods and mod not in dst_mods :
359
+ if dst_prjs and prj not in dst_prjs :
359
360
continue
360
361
361
362
pth = patch_info ["path" ]
@@ -385,13 +386,13 @@ def apply(self, args, yml, dst_mods=None):
385
386
self .dbg ("OK" )
386
387
patch_count += 1
387
388
388
- mod_path = Path (args .west_workspace ) / mod
389
- patched_mods .add (mod )
389
+ prj_path = Path (args .west_workspace ) / prj
390
+ patched_prjs .add (prj )
390
391
391
- self .dbg (f"patching { mod } ... " , end = "" )
392
+ self .dbg (f"patching { prj } ... " , end = "" )
392
393
apply_cmd += patch_path
393
394
apply_cmd_list .extend ([patch_path ])
394
- proc = subprocess .run (apply_cmd_list , cwd = mod_path )
395
+ proc = subprocess .run (apply_cmd_list , cwd = prj_path )
395
396
if proc .returncode :
396
397
self .dbg ("FAIL" )
397
398
self .err (proc .stderr )
@@ -404,11 +405,11 @@ def apply(self, args, yml, dst_mods=None):
404
405
return
405
406
406
407
if args .roll_back :
407
- self .clean (args , yml , patched_mods )
408
+ self .clean (args , yml , patched_prjs )
408
409
409
410
self .die (f"failed to apply patch { failed_patch } " )
410
411
411
- def clean (self , args , yml , dst_mods = None ):
412
+ def clean (self , args , yml , dst_prjs = None ):
412
413
clean_cmd = yml ["clean-command" ]
413
414
checkout_cmd = yml ["checkout-command" ]
414
415
@@ -419,52 +420,52 @@ def clean(self, args, yml, dst_mods=None):
419
420
clean_cmd_list = shlex .split (clean_cmd )
420
421
checkout_cmd_list = shlex .split (checkout_cmd )
421
422
422
- for mod in yml .get ("patches" , []):
423
- m = self .get_module_path ( mod .get ("module" ))
423
+ for prj in yml .get ("patches" , []):
424
+ m = self .get_project_path ( prj .get ("module" ))
424
425
if m is None :
425
426
continue
426
- if dst_mods and m not in dst_mods :
427
+ if dst_prjs and m not in dst_prjs :
427
428
continue
428
- mod_path = Path (args .west_workspace ) / m
429
+ prj_path = Path (args .west_workspace ) / m
429
430
430
431
try :
431
432
if checkout_cmd :
432
- self .dbg (f"Running '{ checkout_cmd } ' in { mod } .. " , end = "" )
433
- proc = subprocess .run (checkout_cmd_list , capture_output = True , cwd = mod_path )
433
+ self .dbg (f"Running '{ checkout_cmd } ' in { prj } .. " , end = "" )
434
+ proc = subprocess .run (checkout_cmd_list , capture_output = True , cwd = prj_path )
434
435
if proc .returncode :
435
436
self .dbg ("FAIL" )
436
- self .err (f"{ checkout_cmd } failed for { mod } \n { proc .stderr } " )
437
+ self .err (f"{ checkout_cmd } failed for { prj } \n { proc .stderr } " )
437
438
else :
438
439
self .dbg ("OK" )
439
440
440
441
if clean_cmd :
441
- self .dbg (f"Running '{ clean_cmd } ' in { mod } .. " , end = "" )
442
- proc = subprocess .run (clean_cmd_list , capture_output = True , cwd = mod_path )
442
+ self .dbg (f"Running '{ clean_cmd } ' in { prj } .. " , end = "" )
443
+ proc = subprocess .run (clean_cmd_list , capture_output = True , cwd = prj_path )
443
444
if proc .returncode :
444
445
self .dbg ("FAIL" )
445
- self .err (f"{ clean_cmd } failed for { mod } \n { proc .stderr } " )
446
+ self .err (f"{ clean_cmd } failed for { prj } \n { proc .stderr } " )
446
447
else :
447
448
self .dbg ("OK" )
448
449
449
450
except Exception as e :
450
451
# If this fails for some reason, just log it and continue
451
- self .err (f"failed to clean up { mod } : { e } " )
452
+ self .err (f"failed to clean up { prj } : { e } " )
452
453
453
- def list (self , args , yml , dst_mods = None ):
454
+ def list (self , args , yml , dst_prjs = None ):
454
455
patches = yml .get ("patches" , [])
455
456
if not patches :
456
457
return
457
458
458
459
for patch_info in patches :
459
- if dst_mods and self .get_module_path (patch_info ["module " ]) not in dst_mods :
460
+ if dst_prjs and self .get_project_path (patch_info ["project " ]) not in dst_prjs :
460
461
continue
461
462
self .inf (patch_info )
462
463
463
- def gh_fetch (self , args , yml , mods = None ):
464
- if mods :
464
+ def gh_fetch (self , args , yml , prjs = None ):
465
+ if prjs :
465
466
self .die (
466
- "Module filters are not available for the gh-fetch subcommand, "
467
- "pass a single -m/--module argument after the subcommand."
467
+ "project filters are not available for the gh-fetch subcommand, "
468
+ "pass a single -m/--project argument after the subcommand."
468
469
)
469
470
470
471
try :
@@ -487,7 +488,7 @@ def gh_fetch(self, args, yml, mods=None):
487
488
patch_info = {
488
489
"path" : filename ,
489
490
"sha256sum" : self .get_file_sha256sum (args .patch_base / filename ),
490
- "module" : str (args .module ),
491
+ "module" : str (args .project ),
491
492
"author" : cm .commit .author .name or "Hidden" ,
492
493
"email" :
cm .
commit .
author .
email or "[email protected] " ,
493
494
"date" : cm .commit .author .date .strftime ("%Y-%m-%d" ),
@@ -504,7 +505,7 @@ def gh_fetch(self, args, yml, mods=None):
504
505
patch_info = {
505
506
"path" : filename ,
506
507
"sha256sum" : self .get_file_sha256sum (args .patch_base / filename ),
507
- "module" : str (args .module ),
508
+ "module" : str (args .project ),
508
509
"author" : pr .user .name or "Hidden" ,
509
510
"email" :
pr .
user .
email or "[email protected] " ,
510
511
"date" : pr .created_at .strftime ("%Y-%m-%d" ),
@@ -532,23 +533,24 @@ def get_file_sha256sum(filename: Path) -> str:
532
533
533
534
return digest .hexdigest ()
534
535
535
- def get_module_path (self , module_name_or_path ):
536
- if module_name_or_path is None :
536
+ def get_project_path (self , project_name_or_path ):
537
+ if project_name_or_path is None :
537
538
return None
538
539
539
540
topdir = Path (self .topdir )
540
541
541
- if Path (module_name_or_path ).is_absolute ():
542
- if Path (module_name_or_path ).is_dir ():
543
- return Path (module_name_or_path ).resolve ().relative_to (topdir )
542
+ if Path (project_name_or_path ).is_absolute ():
543
+ if Path (project_name_or_path ).is_dir ():
544
+ return Path (project_name_or_path ).resolve ().relative_to (topdir )
544
545
return None
545
546
546
- if (topdir / module_name_or_path ).is_dir ():
547
- return Path (module_name_or_path )
547
+ if (topdir / project_name_or_path ).is_dir ():
548
+ return Path (project_name_or_path )
549
+
550
+ all_projects = zephyr_module .west_projects (self .manifest )['projects' ]
548
551
549
- all_modules = zephyr_module .parse_modules (ZEPHYR_BASE , self .manifest )
550
- for m in all_modules :
551
- if m .meta ['name' ] == module_name_or_path :
552
- return Path (m .project ).relative_to (topdir )
552
+ for p in all_projects :
553
+ if p .name == project_name_or_path :
554
+ return Path (p .abspath ).relative_to (topdir )
553
555
554
556
return None
0 commit comments