cq_deps: Allow disabling

Change-Id: I3f63724d7187504987122336eef590ffcecef15c
Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/52121
Commit-Queue: Rob Mohr <mohrr@google.com>
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
Reviewed-by: Oliver Newman <olivernewman@google.com>
diff --git a/recipe_modules/cq_deps/__init__.py b/recipe_modules/cq_deps/__init__.py
index cf15bd1..f47c9fb 100644
--- a/recipe_modules/cq_deps/__init__.py
+++ b/recipe_modules/cq_deps/__init__.py
@@ -14,9 +14,13 @@
 
 # pylint: disable=missing-docstring
 
+from PB.recipe_modules.pigweed.cq_deps import properties
+
 DEPS = [
     'fuchsia/gerrit',
     'recipe_engine/context',
     'recipe_engine/json',
     'recipe_engine/step',
 ]
+
+PROPERTIES = properties.InputProperties
diff --git a/recipe_modules/cq_deps/api.py b/recipe_modules/cq_deps/api.py
index 8deb16a..ee27db6 100644
--- a/recipe_modules/cq_deps/api.py
+++ b/recipe_modules/cq_deps/api.py
@@ -68,9 +68,10 @@
 class CqDepsApi(recipe_api.RecipeApi):
     """Find dependencies on pending CLs."""
 
-    def __init__(self, *args, **kwargs):
+    def __init__(self, props, *args, **kwargs):
         super(CqDepsApi, self).__init__(*args, **kwargs)
         self._details = {}
+        self._enabled = not props.disabled
 
     def _lookup_cl(self, gerrit_name, commit):
         query_results = self.m.gerrit.change_query(
@@ -113,6 +114,10 @@
         """
 
         with self.m.step.nest('resolve CL deps', status='last') as pres:
+            if not self._enabled:
+                with self.m.step.nest('dependency processing disabled'):
+                    return ((), ())
+
             with self.m.context(infra_steps=True):
                 if isinstance(number, str):
                     cl = self._lookup_cl(gerrit_name, number)
diff --git a/recipe_modules/cq_deps/properties.proto b/recipe_modules/cq_deps/properties.proto
new file mode 100644
index 0000000..6fc2072
--- /dev/null
+++ b/recipe_modules/cq_deps/properties.proto
@@ -0,0 +1,22 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+//     https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+syntax = "proto3";
+
+package recipe_modules.pigweed.cq_deps;
+
+message InputProperties {
+  // Disable processing of cq_deps. If this is set all queries of deps will
+  // result in empty sequences.
+  bool disabled = 1;
+}
diff --git a/recipe_modules/cq_deps/test_api.py b/recipe_modules/cq_deps/test_api.py
index cb6277b..938aa07 100644
--- a/recipe_modules/cq_deps/test_api.py
+++ b/recipe_modules/cq_deps/test_api.py
@@ -115,3 +115,9 @@
             )
 
         return sum(results[1:], results[0])
+
+    def assert_disabled(self, prefix=''):
+        return self.post_process(
+            post_process.MustRun,
+            '{}resolve CL deps.dependency processing disabled'.format(prefix),
+        )
diff --git a/recipe_modules/cq_deps/tests/full.expected/disabled.json b/recipe_modules/cq_deps/tests/full.expected/disabled.json
new file mode 100644
index 0000000..4244219
--- /dev/null
+++ b/recipe_modules/cq_deps/tests/full.expected/disabled.json
@@ -0,0 +1,20 @@
+[
+  {
+    "cmd": [],
+    "name": "resolve CL deps"
+  },
+  {
+    "cmd": [],
+    "name": "resolve CL deps.dependency processing disabled",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [],
+    "name": "final deps"
+  },
+  {
+    "name": "$result"
+  }
+]
\ No newline at end of file
diff --git a/recipe_modules/cq_deps/tests/full.py b/recipe_modules/cq_deps/tests/full.py
index 69b3c02..334c798 100644
--- a/recipe_modules/cq_deps/tests/full.py
+++ b/recipe_modules/cq_deps/tests/full.py
@@ -69,6 +69,12 @@
     )
 
     yield (
+        api.status_check.test('disabled')
+        + api.properties(**{'$pigweed/cq_deps': {'disabled': True}})
+        + api.cq_deps.assert_disabled()
+    )
+
+    yield (
         api.status_check.test('two')
         + api.cq_deps.details('pigweed:1', 'Requires: pigweed:2, pigweed:3')
         + api.cq_deps.has_deps('pigweed:2', 'pigweed:3')