Teach the presubmit check to look for checkdeps in other places.

When PDFium source is not part of a standalone checkout, uploading CLs
fail because the presubmit check cannot find the checkdeps tool. Detect
the common case where PDFium is in third_party/pdfium, and look in the
embedder source tree for checkdeps.

BUG=pdfium:999

Change-Id: I972282aef9e62f99dce282d556ca2e68de3acbb0
Reviewed-on: https://pdfium-review.googlesource.com/24910
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index a7db123..ec0f0e4 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -45,8 +45,21 @@
   # eval-ed and thus doesn't have __file__.
   original_sys_path = sys.path
   try:
-    sys.path = sys.path + [input_api.os_path.join(
-        input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')]
+    def GenerateCheckdepsPath(base_path):
+      return input_api.os_path.join(base_path, 'buildtools', 'checkdeps')
+
+    presubmit_path = input_api.PresubmitLocalPath()
+    presubmit_parent_path = input_api.os_path.dirname(presubmit_path)
+    not_standalone_pdfium = \
+        input_api.os_path.basename(presubmit_parent_path) == "third_party" and \
+        input_api.os_path.basename(presubmit_path) == "pdfium"
+
+    sys.path.append(GenerateCheckdepsPath(presubmit_path))
+    if not_standalone_pdfium:
+      presubmit_grandparent_path = input_api.os_path.dirname(
+          presubmit_parent_path)
+      sys.path.append(GenerateCheckdepsPath(presubmit_grandparent_path))
+
     import checkdeps
     from cpp_checker import CppChecker
     from rules import Rule