Skip to content

Commit 039013f

Browse files
mshinjojhedberg
authored andcommitted
scripts: west_commands: patch: treat all subprocess output as text
Pass 'encoding="utf-8"' to all 'subprocess.run()' calls. This treats the captured stdout and stderr streams as text rather than byte sequences. Example without this patch: west patch apply --roll-back ERROR: b'error: patch failed: examples/csp_server_client.py:32\n error: examples/csp_server_client.py: patch does not apply\n' FATAL ERROR: failed to apply patch libcsp/test.patch Example with this patch: west patch apply --roll-back ERROR: error: patch failed: examples/csp_server_client.py:32 error: examples/csp_server_client.py: patch does not apply FATAL ERROR: failed to apply patch libcsp/test.patch Signed-off-by: Mirai SHINJO <oss@mshinjo.com>
1 parent 634b45e commit 039013f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

scripts/west_commands/patch.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ def apply(self, args, yml, dst_mods=None):
391391
self.dbg(f"patching {mod}... ", end="")
392392
apply_cmd += patch_path
393393
apply_cmd_list.extend([patch_path])
394-
proc = subprocess.run(apply_cmd_list, capture_output=True, cwd=mod_path)
394+
proc = subprocess.run(
395+
apply_cmd_list, capture_output=True, cwd=mod_path, encoding="utf-8"
396+
)
395397
if proc.returncode:
396398
self.dbg("FAIL")
397399
self.err(proc.stderr)
@@ -430,7 +432,9 @@ def clean(self, args, yml, dst_mods=None):
430432
try:
431433
if checkout_cmd:
432434
self.dbg(f"Running '{checkout_cmd}' in {mod}.. ", end="")
433-
proc = subprocess.run(checkout_cmd_list, capture_output=True, cwd=mod_path)
435+
proc = subprocess.run(
436+
checkout_cmd_list, capture_output=True, cwd=mod_path, encoding="utf-8"
437+
)
434438
if proc.returncode:
435439
self.dbg("FAIL")
436440
self.err(f"{checkout_cmd} failed for {mod}\n{proc.stderr}")
@@ -439,7 +443,9 @@ def clean(self, args, yml, dst_mods=None):
439443

440444
if clean_cmd:
441445
self.dbg(f"Running '{clean_cmd}' in {mod}.. ", end="")
442-
proc = subprocess.run(clean_cmd_list, capture_output=True, cwd=mod_path)
446+
proc = subprocess.run(
447+
clean_cmd_list, capture_output=True, cwd=mod_path, encoding="utf-8"
448+
)
443449
if proc.returncode:
444450
self.dbg("FAIL")
445451
self.err(f"{clean_cmd} failed for {mod}\n{proc.stderr}")

0 commit comments

Comments
 (0)