pw_build: Make wrap-ninja remove escape code from action names

pw-wrap-ninja has some tricky parsing logic for the raw output of Ninja.
Crucially, it must maintain Ninja's output mode where it outputs escape
characters, as well as use them as delimiters, without letting them
interfere with the rest of the parsing.

As it turns out, Ninja's output is slightly more complicated than
previously thought. In particular, it sometimes uses different
delimiters (unclear exactly when), which results in escape characters
being left inside the parsed names of actions.

This commit takes the simplest approach -- if an action name ends the
specific known escape string, it just removes it.

Change-Id: Iea2f0339aec3993cc1a4ebea88fd753b291a6268
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/126985
Reviewed-by: Rob Mohr <mohrr@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Eli Lipsitz <elipsitz@google.com>
diff --git a/pw_build/py/pw_build/wrap_ninja.py b/pw_build/py/pw_build/wrap_ninja.py
index 0af55fa..01e6d94 100644
--- a/pw_build/py/pw_build/wrap_ninja.py
+++ b/pw_build/py/pw_build/wrap_ninja.py
@@ -312,6 +312,12 @@
                 actions_total = int(match.group(3))
                 name = match.group(4)
 
+                # Sometimes Ninja delimits lines without \r, which prevents
+                # _monitor_thread from stripping out the final control code,
+                # so just remove it here if it's present.
+                if name.endswith('\x1B[K'):
+                    name = name[:-3]
+
                 did_start = actions_started > self.num_started
                 did_finish = actions_finished > self.num_finished
                 self.num_started = actions_started