pw_presubmit: Add resultdb integration

Bug: 247857184
Change-Id: I2acab93ba4462716eba5dd71aabe0664521c15a9
Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/111451
Reviewed-by: Rob Mohr <mohrr@google.com>
Commit-Queue: Ted Pudlik <tpudlik@google.com>
diff --git a/recipe_modules/pw_presubmit/__init__.py b/recipe_modules/pw_presubmit/__init__.py
index 51ce412..aba7054 100644
--- a/recipe_modules/pw_presubmit/__init__.py
+++ b/recipe_modules/pw_presubmit/__init__.py
@@ -21,6 +21,7 @@
     'recipe_engine/file',
     'recipe_engine/path',
     'recipe_engine/raw_io',
+    'recipe_engine/resultdb',
     'recipe_engine/step',
     'recipe_engine/time',
 ]
diff --git a/recipe_modules/pw_presubmit/api.py b/recipe_modules/pw_presubmit/api.py
index 57787ec..4e9c8ec 100644
--- a/recipe_modules/pw_presubmit/api.py
+++ b/recipe_modules/pw_presubmit/api.py
@@ -156,7 +156,12 @@
 
         with self.m.step.nest('timeout {}'.format(nice_duration(timeout))):
             pass
-        return self.m.step(name, cmd, timeout=timeout, **kwargs)
+        if self.m.resultdb.enabled:
+            return self.m.step(
+                name, self.m.resultdb.wrap(cmd), timeout=timeout, **kwargs
+            )
+        else:
+            return self.m.step(name, cmd, timeout=timeout, **kwargs)
 
     def _process_metadata(self, step):
         if not step.export_dir:
diff --git a/recipe_modules/pw_presubmit/tests/full.expected/long.json b/recipe_modules/pw_presubmit/tests/full.expected/long.json
index 15e45f8..b9555c5 100644
--- a/recipe_modules/pw_presubmit/tests/full.expected/long.json
+++ b/recipe_modules/pw_presubmit/tests/full.expected/long.json
@@ -12,6 +12,9 @@
   },
   {
     "cmd": [
+      "rdb",
+      "stream",
+      "--",
       "python",
       "-m",
       "pw_cli",
@@ -497,6 +500,9 @@
   },
   {
     "cmd": [
+      "rdb",
+      "stream",
+      "--",
       "python",
       "-m",
       "pw_cli",
diff --git a/recipe_modules/pw_presubmit/tests/full.expected/medium.json b/recipe_modules/pw_presubmit/tests/full.expected/medium.json
index e79bf38..b6afc9d 100644
--- a/recipe_modules/pw_presubmit/tests/full.expected/medium.json
+++ b/recipe_modules/pw_presubmit/tests/full.expected/medium.json
@@ -12,6 +12,9 @@
   },
   {
     "cmd": [
+      "rdb",
+      "stream",
+      "--",
       "python",
       "-m",
       "pw_cli",
@@ -497,6 +500,9 @@
   },
   {
     "cmd": [
+      "rdb",
+      "stream",
+      "--",
       "python",
       "-m",
       "pw_cli",
diff --git a/recipe_modules/pw_presubmit/tests/full.expected/pigweed.json b/recipe_modules/pw_presubmit/tests/full.expected/pigweed.json
index a3d7145..52851c2 100644
--- a/recipe_modules/pw_presubmit/tests/full.expected/pigweed.json
+++ b/recipe_modules/pw_presubmit/tests/full.expected/pigweed.json
@@ -12,6 +12,9 @@
   },
   {
     "cmd": [
+      "rdb",
+      "stream",
+      "--",
       "foo",
       "--directory",
       "[START_DIR]/checkout",
@@ -56,6 +59,9 @@
   },
   {
     "cmd": [
+      "rdb",
+      "stream",
+      "--",
       "foo",
       "--directory",
       "[START_DIR]/checkout",
@@ -541,6 +547,9 @@
   },
   {
     "cmd": [
+      "rdb",
+      "stream",
+      "--",
       "foo",
       "--directory",
       "[START_DIR]/checkout",
diff --git a/recipe_modules/pw_presubmit/tests/full.expected/step.json b/recipe_modules/pw_presubmit/tests/full.expected/step.json
index 6ebe24d..0ad2994 100644
--- a/recipe_modules/pw_presubmit/tests/full.expected/step.json
+++ b/recipe_modules/pw_presubmit/tests/full.expected/step.json
@@ -12,6 +12,9 @@
   },
   {
     "cmd": [
+      "rdb",
+      "stream",
+      "--",
       "python",
       "-m",
       "pw_cli",
@@ -497,6 +500,9 @@
   },
   {
     "cmd": [
+      "rdb",
+      "stream",
+      "--",
       "python",
       "-m",
       "pw_cli",
diff --git a/recipes/pw_presubmit.expected/sign.json b/recipes/pw_presubmit.expected/sign.json
index dad3325..21502a4 100644
--- a/recipes/pw_presubmit.expected/sign.json
+++ b/recipes/pw_presubmit.expected/sign.json
@@ -1298,6 +1298,9 @@
   },
   {
     "cmd": [
+      "rdb",
+      "stream",
+      "--",
       "python",
       "-m",
       "pw_cli",
diff --git a/recipes/pw_presubmit.expected/step.json b/recipes/pw_presubmit.expected/step.json
index 07af603..c999cfb 100644
--- a/recipes/pw_presubmit.expected/step.json
+++ b/recipes/pw_presubmit.expected/step.json
@@ -1562,6 +1562,9 @@
   },
   {
     "cmd": [
+      "rdb",
+      "stream",
+      "--",
       "python",
       "-m",
       "pw_cli",
@@ -2045,6 +2048,9 @@
   },
   {
     "cmd": [
+      "rdb",
+      "stream",
+      "--",
       "python",
       "-m",
       "pw_cli",