Skip to content

Commit a1d4c3e

Browse files
committed
Patch in #932 to get the C++ SDK to build successfully against HEAD of the firebase-ios-sdk
1 parent a192efb commit a1d4c3e

File tree

6 files changed

+409
-621
lines changed

6 files changed

+409
-621
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ endif()
214214
# firebase-ios-sdk since it's not needed and can sometimes fail to build.
215215
set(FIRESTORE_INCLUDE_OBJC OFF CACHE BOOL "Disabled for the CPP SDK")
216216

217+
# Disable re2 build tests
218+
set(RE2_BUILD_TESTING OFF CACHE BOOL "")
219+
217220
if(FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD)
218221
# Quote meta characters in ${CMAKE_CURRENT_LIST_DIR} so we can
219222
# match it in a regex.

cmake/external/firestore.cmake

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ if(TARGET firestore)
1818
return()
1919
endif()
2020

21+
if(${CMAKE_VERSION} VERSION_LESS "3.12")
22+
include(FindPythonInterp)
23+
set(MY_PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE}")
24+
else()
25+
find_package(Python3 COMPONENTS Interpreter REQUIRED)
26+
set(MY_PYTHON_EXECUTABLE "${Python3_EXECUTABLE}")
27+
endif()
28+
2129
# If the format of the line below changes, then be sure to update
2230
# https://github.com/firebase/firebase-cpp-sdk/blob/fd054fa016/.github/workflows/update-dependencies.yml#L81
2331
set(version CocoaPods-9.0.0)
@@ -36,7 +44,11 @@ function(GetReleasedDep)
3644
BUILD_COMMAND ""
3745
INSTALL_COMMAND ""
3846
TEST_COMMAND ""
39-
PATCH_COMMAND patch -Np1 -i ${CMAKE_CURRENT_LIST_DIR}/firestore_snappy.patch.txt
47+
PATCH_COMMAND
48+
${MY_PYTHON_EXECUTABLE}
49+
${CMAKE_CURRENT_LIST_DIR}/firestore_patch.py
50+
--leveldb-version-from
51+
${CMAKE_CURRENT_LIST_DIR}/leveldb.cmake
4052
HTTP_HEADER "${EXTERNAL_PROJECT_HTTP_HEADER}"
4153
)
4254
endfunction()
@@ -57,7 +69,11 @@ function(GetTag t)
5769
BUILD_COMMAND ""
5870
INSTALL_COMMAND ""
5971
TEST_COMMAND ""
60-
PATCH_COMMAND patch -Np1 -i ${CMAKE_CURRENT_LIST_DIR}/firestore_snappy.patch.txt
72+
PATCH_COMMAND
73+
${MY_PYTHON_EXECUTABLE}
74+
${CMAKE_CURRENT_LIST_DIR}/firestore_patch.py
75+
--leveldb-version-from
76+
${CMAKE_CURRENT_LIST_DIR}/leveldb.cmake
6177
HTTP_HEADER "${EXTERNAL_PROJECT_HTTP_HEADER}"
6278
)
6379
endfunction()

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)