Skip to content

Commit 020990b

Browse files
committed
Merge branch 'dconeybe/FirestorePrepForIosSdkM115' into other/test_ios_900_pods
2 parents c44adef + a43089b commit 020990b

File tree

10 files changed

+420
-1126
lines changed

10 files changed

+420
-1126
lines changed

cmake/external/firestore.cmake

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
include(ExternalProject)
16+
include(FindPythonInterp)
1617

1718
if(TARGET firestore)
1819
return()
@@ -27,8 +28,10 @@ function(GetReleasedDep)
2728
ExternalProject_Add(
2829
firestore
2930

30-
DOWNLOAD_DIR ${FIREBASE_DOWNLOAD_DIR}
31-
URL https://github.com/firebase/firebase-ios-sdk/archive/${version}.tar.gz
31+
DOWNLOAD_DIR ${FIREBASE_DOWNLOAD_DIR}
32+
GIT_REPOSITORY https://github.com/firebase/firebase-ios-sdk
33+
GIT_TAG 70aa8b82a2ed36dd14448174bea0fd7e575d4d49
34+
GIT_SHALLOW ON
3235

3336
PREFIX ${PROJECT_BINARY_DIR}
3437

@@ -73,3 +76,10 @@ else()
7376
endif()
7477
endif()
7578

79+
CONFIGURE_COMMAND ""
80+
BUILD_COMMAND ""
81+
INSTALL_COMMAND ""
82+
TEST_COMMAND ""
83+
PATCH_COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/firestore_patch.py --leveldb-version-from ${CMAKE_CURRENT_LIST_DIR}/leveldb.cmake
84+
HTTP_HEADER "${EXTERNAL_PROJECT_HTTP_HEADER}"
85+
)

cmake/external/firestore_patch.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""
16+
Modify the version in leveldb.cmake from the Firebase iOS SDK to match the
17+
version from this C++ SDK.
18+
"""
19+
20+
import argparse
21+
import os
22+
import pathlib
23+
import re
24+
from typing import List, Tuple
25+
26+
27+
VERSION_PATTERN = r"\s*set\s*\(\s*version\s+([^)\s]+)\s*\)\s*"
28+
VERSION_EXPR = re.compile(VERSION_PATTERN, re.IGNORECASE)
29+
URL_HASH_PATTERN = r"\s*URL_HASH\s+([0-9a-zA-Z=]+)\s*"
30+
URL_HASH_EXPR = re.compile(URL_HASH_PATTERN, re.IGNORECASE)
31+
32+
33+
def main() -> None:
34+
(src_file, dest_file) = parse_args()
35+
36+
leveldb_version = load_value(src_file, VERSION_EXPR)
37+
url_hash = load_value(src_file, URL_HASH_EXPR)
38+
39+
set_value(dest_file, VERSION_EXPR, leveldb_version)
40+
set_value(dest_file, URL_HASH_EXPR, url_hash)
41+
42+
43+
def parse_args() -> Tuple[pathlib.Path, pathlib.Path]:
44+
arg_parser = argparse.ArgumentParser()
45+
arg_parser.add_argument("--leveldb-version-from", required=True)
46+
arg_parser.add_argument("--leveldb-version-to")
47+
48+
parsed_args = arg_parser.parse_args()
49+
50+
leveldb_cmake_src_file = pathlib.Path(parsed_args.leveldb_version_from)
51+
52+
if parsed_args.leveldb_version_to:
53+
leveldb_cmake_dest_file = pathlib.Path(parsed_args.leveldb_version_to)
54+
else:
55+
leveldb_cmake_dest_file = pathlib.Path.cwd() \
56+
/ "cmake" / "external" / "leveldb.cmake"
57+
58+
return (leveldb_cmake_src_file, leveldb_cmake_dest_file)
59+
60+
61+
def load_value(file_: pathlib.Path, expr: re.Pattern) -> str:
62+
value = None
63+
value_line = None
64+
value_line_number = None
65+
66+
with file_.open("rt", encoding="utf8") as f:
67+
for (line_number, line) in enumerate(f, start=1):
68+
match = expr.fullmatch(line)
69+
if not match:
70+
continue
71+
elif value is not None:
72+
raise RegexMatchError(
73+
f"Multiple lines matching regex {expr.pattern} found in "
74+
f"{file_}: line {value_line_number}, {value_line.strip()} "
75+
f"and line {line_number}, {line.strip()}")
76+
77+
value = match.group(1).strip()
78+
value_line = line
79+
value_line_number = line_number
80+
81+
if value is None:
82+
raise RegexMatchError(
83+
f"No line matching regex {expr.pattern} found in {file_}")
84+
85+
return value
86+
87+
88+
def set_value(file_: pathlib.Path, expr: re.Pattern, version: str) -> None:
89+
with file_.open("rt", encoding="utf8") as f:
90+
lines = list(f)
91+
92+
matching_line = None
93+
matching_line_number = None
94+
95+
for (line_number, line) in enumerate(lines, start=1):
96+
match = expr.fullmatch(line)
97+
if not match:
98+
continue
99+
elif matching_line is not None:
100+
raise RegexMatchError(
101+
f"Multiple lines matching regex {expr.pattern} found in "
102+
f"{file_}: line {matching_line_number}, {matching_line.strip()} "
103+
f"and line {line_number}, {line.strip()}")
104+
105+
lines[line_number - 1] = line[:match.start(1)] + version + line[match.end(1):]
106+
matching_line = line
107+
matching_line_number = line_number
108+
109+
if matching_line is None:
110+
raise RegexMatchError(
111+
f"No line matching regex {expr.pattern} found in {file_}")
112+
113+
with file_.open("wt", encoding="utf8") as f:
114+
f.writelines(lines)
115+
116+
117+
class RegexMatchError(Exception):
118+
pass
119+
120+
121+
if __name__ == "__main__":
122+
main()

0 commit comments

Comments
 (0)