Bläddra i källkod

Add script to check for absl reference from Firestore/core/api (#8309)

* Add script to check for absl reference from Firestore/core/api

* Feedback

* More feedback
wu-hui 4 år sedan
förälder
incheckning
a0f054e51b
3 ändrade filer med 87 tillägg och 0 borttagningar
  1. 1 0
      scripts/check.sh
  2. 85 0
      scripts/check_firestore_core_api_absl.py
  3. 1 0
      scripts/check_imports.swift

+ 1 - 0
scripts/check.sh

@@ -292,6 +292,7 @@ python --version
 "${top_dir}/scripts/check_no_module_imports.sh"
 "${top_dir}/scripts/check_test_inclusion.py"
 "${top_dir}/scripts/check_imports.swift"
+"${top_dir}/scripts/check_firestore_core_api_absl.py"
 
 # Google C++ style
 lint_cmd=("${top_dir}/scripts/check_lint.py")

+ 85 - 0
scripts/check_firestore_core_api_absl.py

@@ -0,0 +1,85 @@
+#! /usr/bin/env python
+
+# Copyright 2021 Google LLC
+#
+# 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
+#
+# http:  // 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.
+"""Check no absl reference are added to Firestore/core/src/api header files.
+
+Absl references in core/src/api public interface will cause link error for
+the Unity SDK, when it is built from google3.
+"""
+
+# TODO(b/192129206) : Remove this check once Unity SDK is built from Github.
+import argparse
+import logging
+import six
+import subprocess
+
+from lib import command_trace
+
+_logger = logging.getLogger('absl_check')
+
+
+def diff_with_absl(revision, patterns):
+  """Finds diffs containing 'absl' since a revision from specified path
+  pattern.
+  """
+  # git command to print all diffs that has 'absl' in it.
+  command = ['git', 'diff', '-G', 'absl', revision, '--']
+  command.extend(patterns)
+  _logger.debug(command)
+  return six.ensure_text(subprocess.check_output(command))
+
+
+def main():
+  patterns = ['Firestore/core/src/api/*.h']
+  parser = argparse.ArgumentParser(
+      description='Check Absl usage in %s' % patterns)
+  parser.add_argument(
+      '--dry-run',
+      '-n',
+      action='store_true',
+      help='Show what the linter would do without doing it')
+  parser.add_argument(
+      'rev',
+      nargs='?',
+      help='A single revision that specifies a point in time '
+      'from which to look for changes. Defaults to '
+      'origin/master.')
+  args = command_trace.parse_args(parser)
+
+  dry_run = False
+  if args.dry_run:
+    dry_run = True
+    _logger.setLevel(logging.DEBUG)
+
+  revision = 'origin/master' if not args.rev else args.rev
+  _logger.debug('Checking %s absl usage against %s' %
+                (patterns, revision))
+  diff = diff_with_absl(revision, patterns)
+
+  # Check for changes adding new absl references only.
+  lines = [line for line in diff.splitlines()
+           if line.startswith('+') and 'absl::' in line]
+  if lines:
+      _logger.error(
+          'Found a change introducing reference to absl under %s'
+          % patterns)
+      for line in lines:
+          _logger.error(' %s' % line)
+      if not dry_run:
+          exit(-1)
+
+
+if __name__ == '__main__':
+  main()

+ 1 - 0
scripts/check_imports.swift

@@ -29,6 +29,7 @@ let skipDirPatterns = ["/Sample/", "/Pods/", "FirebaseStorage/Tests/Integration"
                        "FirebaseInAppMessaging/Tests/Integration/",
                        "SymbolCollisionTest/", "/gen/",
                        "CocoapodsIntegrationTest/", "FirebasePerformance/Tests/TestApp/",
+                       "cmake-build-debug/", "build/",
                        "FirebasePerformance/Tests/FIRPerfE2E/"] +
   [
     "CoreOnly/Sources", // Skip Firebase.h.