Skip to content

Commit 50fca51

Browse files
committed
Remove the patch to enable Snappy support
1 parent fd054fa commit 50fca51

File tree

4 files changed

+296
-667
lines changed

4 files changed

+296
-667
lines changed

cmake/external/firestore.cmake

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,26 @@
1313
# limitations under the License.
1414

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

1718
if(TARGET firestore)
1819
return()
1920
endif()
2021

21-
function(GetReleasedDep version)
22-
message("Getting released firebase-ios-sdk @ ${version}")
23-
ExternalProject_Add(
24-
firestore
22+
ExternalProject_Add(
23+
firestore
2524

26-
DOWNLOAD_DIR ${FIREBASE_DOWNLOAD_DIR}
27-
URL https://github.com/firebase/firebase-ios-sdk/archive/${version}.tar.gz
25+
DOWNLOAD_DIR ${FIREBASE_DOWNLOAD_DIR}
26+
GIT_REPOSITORY https://github.com/firebase/firebase-ios-sdk
27+
GIT_TAG 582b384c99a5dd24331161d436fdb6fd088fa833
28+
GIT_SHALLOW ON
2829

29-
PREFIX ${PROJECT_BINARY_DIR}
30-
31-
CONFIGURE_COMMAND ""
32-
BUILD_COMMAND ""
33-
INSTALL_COMMAND ""
34-
TEST_COMMAND ""
35-
PATCH_COMMAND patch -Np1 -i ${CMAKE_CURRENT_LIST_DIR}/firestore_snappy.patch.txt
36-
HTTP_HEADER "${EXTERNAL_PROJECT_HTTP_HEADER}"
37-
)
38-
endfunction()
39-
40-
function(GetTag t)
41-
message("Getting firebase-ios-sdk from ${t}")
42-
ExternalProject_Add(
43-
firestore
44-
45-
DOWNLOAD_DIR ${FIREBASE_DOWNLOAD_DIR}
46-
GIT_REPOSITORY "https://github.com/firebase/firebase-ios-sdk.git"
47-
GIT_TAG ${t}
48-
GIT_SHALLOW "ON"
49-
50-
PREFIX ${PROJECT_BINARY_DIR}
51-
52-
CONFIGURE_COMMAND ""
53-
BUILD_COMMAND ""
54-
INSTALL_COMMAND ""
55-
TEST_COMMAND ""
56-
PATCH_COMMAND patch -Np1 -i ${CMAKE_CURRENT_LIST_DIR}/firestore_snappy.patch.txt
57-
HTTP_HEADER "${EXTERNAL_PROJECT_HTTP_HEADER}"
58-
)
59-
endfunction()
60-
61-
if((NOT FIRESTORE_DEP_SOURCE) OR (FIRESTORE_DEP_SOURCE STREQUAL "RELEASED"))
62-
# Get from released dependency by default
63-
GetReleasedDep("CocoaPods-8.12.1")
64-
else()
65-
if(FIRESTORE_DEP_SOURCE STREQUAL "TIP")
66-
GetTag("origin/master")
67-
else()
68-
GetTag(${FIRESTORE_DEP_SOURCE})
69-
endif()
70-
endif()
30+
PREFIX ${PROJECT_BINARY_DIR}
7131

32+
CONFIGURE_COMMAND ""
33+
BUILD_COMMAND ""
34+
INSTALL_COMMAND ""
35+
TEST_COMMAND ""
36+
PATCH_COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/firestore_patch.py --leveldb-version-from ${CMAKE_CURRENT_LIST_DIR}/leveldb.cmake
37+
HTTP_HEADER "${EXTERNAL_PROJECT_HTTP_HEADER}"
38+
)

cmake/external/firestore_patch.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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 dataclasses
22+
import os
23+
import pathlib
24+
import re
25+
from typing import Iterable, Sequence
26+
27+
28+
VERSION_PATTERN = r"\s*set\s*\(\s*version\s+([^)\s]+)\s*\)\s*"
29+
VERSION_EXPR = re.compile(VERSION_PATTERN, re.IGNORECASE)
30+
31+
32+
def main() -> None:
33+
args = parse_args()
34+
leveldb_version = load_leveldb_version(args.leveldb_cmake_src_file)
35+
set_leveldb_version(args.leveldb_cmake_dest_file, leveldb_version)
36+
37+
38+
@dataclasses.dataclass(frozen=True)
39+
class ParsedArgs:
40+
leveldb_cmake_src_file: pathlib.Path
41+
leveldb_cmake_dest_file: pathlib.Path
42+
43+
44+
def parse_args() -> ParsedArgs:
45+
arg_parser = argparse.ArgumentParser()
46+
arg_parser.add_argument("--leveldb-version-from", required=True)
47+
arg_parser.add_argument("--leveldb-version-to")
48+
49+
parsed_args = arg_parser.parse_args()
50+
51+
leveldb_cmake_src_file = pathlib.Path(parsed_args.leveldb_version_from)
52+
53+
if parsed_args.leveldb_version_to:
54+
leveldb_cmake_dest_file = pathlib.Path(parsed_args.leveldb_version_to)
55+
else:
56+
leveldb_cmake_dest_file = pathlib.Path.cwd() \
57+
/ "cmake" / "external" / "leveldb.cmake"
58+
59+
return ParsedArgs(
60+
leveldb_cmake_src_file=leveldb_cmake_src_file,
61+
leveldb_cmake_dest_file=leveldb_cmake_dest_file,
62+
)
63+
64+
65+
def load_leveldb_version(cmake_file: pathlib.Path) -> str:
66+
version = None
67+
version_line = None
68+
version_line_number = None
69+
70+
with cmake_file.open("rt", encoding="utf8") as f:
71+
for (line_number, line) in enumerate(f, start=1):
72+
match = VERSION_EXPR.fullmatch(line)
73+
if match:
74+
if version is not None:
75+
raise LevelDbVersionLineError(
76+
f"Multiple lines matching regex {VERSION_EXPR.pattern} found in "
77+
f"{cmake_file}: line {version_line_number}, {version_line.strip()} "
78+
f"and line {line_number}, {line.strip()}")
79+
version = match.group(1).strip()
80+
version_line = line
81+
version_line_number = line_number
82+
83+
if version is None:
84+
raise LevelDbVersionLineError(
85+
f"No line matching regex {VERSION_EXPR.pattern} found in {cmake_file}")
86+
87+
return version
88+
89+
90+
def set_leveldb_version(cmake_file: pathlib.Path, version: str) -> str:
91+
with cmake_file.open("rt", encoding="utf8") as f:
92+
lines = list(f)
93+
94+
version_lines_found = []
95+
for (i, line) in enumerate(lines):
96+
match = VERSION_EXPR.fullmatch(line)
97+
if match:
98+
lines[i] = line[:match.start(1)] + version + line[match.end(1):]
99+
version_lines_found.append(i)
100+
101+
if len(version_lines_found) == 0:
102+
raise LevelDbVersionLineError(
103+
f"No line matching regex {VERSION_EXPR.pattern} found in {cmake_file}")
104+
elif len(version_lines_found) > 1:
105+
raise LevelDbVersionLineError(
106+
f"Multiple lines matching regex {VERSION_EXPR.pattern} found in "
107+
f"{cmake_file}: {', '.join(str(i+1) for i in version_lines_found)}")
108+
109+
with cmake_file.open("wt", encoding="utf8") as f:
110+
f.writelines(lines)
111+
112+
113+
class LevelDbVersionLineError(Exception):
114+
pass
115+
116+
117+
118+
if __name__ == "__main__":
119+
main()
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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+
import firestore_patch
16+
import pathlib
17+
import shutil
18+
import tempfile
19+
import unittest
20+
21+
22+
class LoadLevelDbVersionTest(unittest.TestCase):
23+
24+
def setUp(self):
25+
super().setUp()
26+
temp_dir = pathlib.Path(tempfile.mkdtemp())
27+
self.addCleanup(shutil.rmtree, temp_dir)
28+
self.temp_file = temp_dir / "temp_file.txt"
29+
30+
def test_loads_correct_version(self):
31+
with self.temp_file.open("wt", encoding="utf8") as f:
32+
print("blah1", file=f)
33+
print("set(version 1.23)", file=f)
34+
print("blah2", file=f)
35+
36+
version = firestore_patch.load_leveldb_version(self.temp_file)
37+
38+
self.assertEqual(version, "1.23")
39+
40+
def test_ignores_whitespace(self):
41+
with self.temp_file.open("wt", encoding="utf8") as f:
42+
print(" set ( version 1.23 ) ", file=f)
43+
44+
version = firestore_patch.load_leveldb_version(self.temp_file)
45+
46+
self.assertEqual(version, "1.23")
47+
48+
def test_case_insensitive(self):
49+
with self.temp_file.open("wt", encoding="utf8") as f:
50+
print("SeT(vErSiOn 1.23)", file=f)
51+
52+
version = firestore_patch.load_leveldb_version(self.temp_file)
53+
54+
self.assertEqual(version, "1.23")
55+
56+
def test_version_not_found_raises_error(self):
57+
with self.temp_file.open("wt", encoding="utf8") as f:
58+
print("aaa", file=f)
59+
print("bbb", file=f)
60+
61+
with self.assertRaises(firestore_patch.LevelDbVersionLineError) as cm:
62+
firestore_patch.load_leveldb_version(self.temp_file)
63+
64+
self.assertIn("no line matching", str(cm.exception).lower())
65+
self.assertIn(str(self.temp_file), str(cm.exception))
66+
67+
def test_multiple_version_lines_found_raises_error(self):
68+
with self.temp_file.open("wt", encoding="utf8") as f:
69+
for i in range(100):
70+
print(f"line {i+1}", file=f)
71+
print("set(version aaa)", file=f)
72+
print("set(version bbb)", file=f)
73+
74+
with self.assertRaises(firestore_patch.LevelDbVersionLineError) as cm:
75+
firestore_patch.load_leveldb_version(self.temp_file)
76+
77+
self.assertIn("multiple lines matching", str(cm.exception).lower())
78+
self.assertIn(str(self.temp_file), str(cm.exception))
79+
self.assertIn("line 101", str(cm.exception))
80+
self.assertIn("line 102", str(cm.exception))
81+
self.assertIn("aaa", str(cm.exception))
82+
self.assertIn("bbb", str(cm.exception))
83+
84+
85+
class SetLevelDbVersionTest(unittest.TestCase):
86+
87+
def setUp(self):
88+
super().setUp()
89+
temp_dir = pathlib.Path(tempfile.mkdtemp())
90+
self.addCleanup(shutil.rmtree, temp_dir)
91+
self.temp_file = temp_dir / "temp_file.txt"
92+
93+
def test_saves_correct_version(self):
94+
with self.temp_file.open("wt", encoding="utf8") as f:
95+
print("set(version asdfasdf)", file=f)
96+
97+
firestore_patch.set_leveldb_version(self.temp_file, "1.2.3")
98+
99+
new_version = firestore_patch.load_leveldb_version(self.temp_file)
100+
self.assertEqual(new_version, "1.2.3")
101+
102+
def test_case_insensitivity(self):
103+
with self.temp_file.open("wt", encoding="utf8") as f:
104+
print("sEt(vErSiOn asdfasdf)", file=f)
105+
106+
firestore_patch.set_leveldb_version(self.temp_file, "1.2.3")
107+
108+
new_version = firestore_patch.load_leveldb_version(self.temp_file)
109+
self.assertEqual(new_version, "1.2.3")
110+
111+
def test_leaves_whitespace_alone(self):
112+
with self.temp_file.open("wt", encoding="utf8") as f:
113+
print(" set ( version 1.2.3.4 ) ", file=f)
114+
temp_file_contents = self.temp_file.read_text(encoding="utf8")
115+
116+
firestore_patch.set_leveldb_version(self.temp_file, "a.b.c.d")
117+
118+
temp_file_contents_after = self.temp_file.read_text(encoding="utf8")
119+
expected_temp_file_contents = temp_file_contents.replace("1.2.3.4", "a.b.c.d")
120+
self.assertEqual(temp_file_contents_after, expected_temp_file_contents)
121+
122+
def test_does_not_touch_other_lines(self):
123+
with self.temp_file.open("wt", encoding="utf8") as f:
124+
print("blah1", file=f)
125+
print("set(version 1.2.3.4)", file=f)
126+
print("blah2", file=f)
127+
temp_file_contents = self.temp_file.read_text(encoding="utf8")
128+
129+
firestore_patch.set_leveldb_version(self.temp_file, "a.b.c.d")
130+
131+
temp_file_contents_after = self.temp_file.read_text(encoding="utf8")
132+
expected_temp_file_contents = temp_file_contents.replace("1.2.3.4", "a.b.c.d")
133+
self.assertEqual(temp_file_contents_after, expected_temp_file_contents)
134+
135+
def test_version_not_found_raises_error(self):
136+
with self.temp_file.open("wt", encoding="utf8") as f:
137+
print("aaa", file=f)
138+
print("bbb", file=f)
139+
140+
with self.assertRaises(firestore_patch.LevelDbVersionLineError) as cm:
141+
firestore_patch.set_leveldb_version(self.temp_file, "a.b.c")
142+
143+
self.assertIn("no line matching", str(cm.exception).lower())
144+
self.assertIn(str(self.temp_file), str(cm.exception))
145+
146+
def test_multiple_version_lines_found_raises_error(self):
147+
with self.temp_file.open("wt", encoding="utf8") as f:
148+
for i in range(100):
149+
print(f"line {i+1}", file=f)
150+
print("set(version aaa)", file=f)
151+
print("set(version bbb)", file=f)
152+
153+
with self.assertRaises(firestore_patch.LevelDbVersionLineError) as cm:
154+
firestore_patch.set_leveldb_version(self.temp_file, "a.b.c")
155+
156+
self.assertIn("multiple lines matching", str(cm.exception).lower())
157+
self.assertIn(str(self.temp_file), str(cm.exception))
158+
self.assertIn("101, 102", str(cm.exception))
159+
160+
161+
if __name__ == "__main__":
162+
unittest.main()

0 commit comments

Comments
 (0)