Skip to content

Commit a0f054e

Browse files
authored
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
1 parent 2d4e139 commit a0f054e

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

scripts/check.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ python --version
292292
"${top_dir}/scripts/check_no_module_imports.sh"
293293
"${top_dir}/scripts/check_test_inclusion.py"
294294
"${top_dir}/scripts/check_imports.swift"
295+
"${top_dir}/scripts/check_firestore_core_api_absl.py"
295296

296297
# Google C++ style
297298
lint_cmd=("${top_dir}/scripts/check_lint.py")
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#! /usr/bin/env python
2+
3+
# Copyright 2021 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0(the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http: // www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
"""Check no absl reference are added to Firestore/core/src/api header files.
17+
18+
Absl references in core/src/api public interface will cause link error for
19+
the Unity SDK, when it is built from google3.
20+
"""
21+
22+
# TODO(b/192129206) : Remove this check once Unity SDK is built from Github.
23+
import argparse
24+
import logging
25+
import six
26+
import subprocess
27+
28+
from lib import command_trace
29+
30+
_logger = logging.getLogger('absl_check')
31+
32+
33+
def diff_with_absl(revision, patterns):
34+
"""Finds diffs containing 'absl' since a revision from specified path
35+
pattern.
36+
"""
37+
# git command to print all diffs that has 'absl' in it.
38+
command = ['git', 'diff', '-G', 'absl', revision, '--']
39+
command.extend(patterns)
40+
_logger.debug(command)
41+
return six.ensure_text(subprocess.check_output(command))
42+
43+
44+
def main():
45+
patterns = ['Firestore/core/src/api/*.h']
46+
parser = argparse.ArgumentParser(
47+
description='Check Absl usage in %s' % patterns)
48+
parser.add_argument(
49+
'--dry-run',
50+
'-n',
51+
action='store_true',
52+
help='Show what the linter would do without doing it')
53+
parser.add_argument(
54+
'rev',
55+
nargs='?',
56+
help='A single revision that specifies a point in time '
57+
'from which to look for changes. Defaults to '
58+
'origin/master.')
59+
args = command_trace.parse_args(parser)
60+
61+
dry_run = False
62+
if args.dry_run:
63+
dry_run = True
64+
_logger.setLevel(logging.DEBUG)
65+
66+
revision = 'origin/master' if not args.rev else args.rev
67+
_logger.debug('Checking %s absl usage against %s' %
68+
(patterns, revision))
69+
diff = diff_with_absl(revision, patterns)
70+
71+
# Check for changes adding new absl references only.
72+
lines = [line for line in diff.splitlines()
73+
if line.startswith('+') and 'absl::' in line]
74+
if lines:
75+
_logger.error(
76+
'Found a change introducing reference to absl under %s'
77+
% patterns)
78+
for line in lines:
79+
_logger.error(' %s' % line)
80+
if not dry_run:
81+
exit(-1)
82+
83+
84+
if __name__ == '__main__':
85+
main()

scripts/check_imports.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ let skipDirPatterns = ["/Sample/", "/Pods/", "FirebaseStorage/Tests/Integration"
2929
"FirebaseInAppMessaging/Tests/Integration/",
3030
"SymbolCollisionTest/", "/gen/",
3131
"CocoapodsIntegrationTest/", "FirebasePerformance/Tests/TestApp/",
32+
"cmake-build-debug/", "build/",
3233
"FirebasePerformance/Tests/FIRPerfE2E/"] +
3334
[
3435
"CoreOnly/Sources", // Skip Firebase.h.

0 commit comments

Comments
 (0)