Skip to content

Prepare Firestore for upgrading the iOS SDK dependency to M115. #898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
50fca51
Remove the patch to enable Snappy support
dconeybe Apr 14, 2022
13222be
firestore_patch.py: also copy the URL_HASH
dconeybe Apr 15, 2022
47a2562
query_main.h: fix build error due to Filter being renamed to FieldFil…
dconeybe Apr 15, 2022
fa99004
user_data_converter_main.cc: fix build error when calling NullValue()…
dconeybe Apr 15, 2022
555a406
Merge in https://github.com/firebase/firebase-cpp-sdk/pull/896 (level…
dconeybe Apr 15, 2022
2564279
leveldb_snappy_test.cc: re-use the test from the iOS SDK instead of r…
dconeybe Apr 15, 2022
19e0b72
leveldb_snappy_test.cc: add a newline at the end of the file.
dconeybe Apr 15, 2022
16605a9
query_main.h: add missing #include "Firestore/core/src/core/field_fil…
dconeybe Apr 15, 2022
4e823e1
Set the FIRESTORE_INCLUDE_OBJC cmake cache var to NO to avoid buildin…
dconeybe Apr 15, 2022
56553d9
external/pip_requirements.txt: add six
dconeybe Apr 15, 2022
c6346fd
Improve FIREBASE_PYTHON_EXECUTABLE cmake cache var and make its usage…
dconeybe Apr 15, 2022
5a8038d
firestore.cmake: bump pinned commit
dconeybe Apr 15, 2022
b0ff4e8
Revert "external/pip_requirements.txt: add six" since it didn't fix t…
dconeybe Apr 15, 2022
05efff1
firestore.cmake: fix pinned commit
dconeybe Apr 15, 2022
48a7680
Revert "Improve FIREBASE_PYTHON_EXECUTABLE cmake cache var and make i…
dconeybe Apr 15, 2022
bd56ad5
firestore.cmake: update pinned commit
dconeybe Apr 15, 2022
7e229e8
CMakeLists.txt: Set FIRESTORE_INCLUDE_OBJC as a cache variable so it …
dconeybe Apr 15, 2022
bf8bffd
query_main.cc: IsBefore(BoundPosition) -> IsInclusive(BoundPosition)
dconeybe Apr 16, 2022
68c2a0f
Merge remote-tracking branch 'origin/main' into FirestorePrepForIosSd…
dconeybe Apr 16, 2022
3de3838
firestore.cmake: update pinned commit
dconeybe Apr 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 15 additions & 48 deletions cmake/external/firestore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,26 @@
# limitations under the License.

include(ExternalProject)
include(FindPythonInterp)

if(TARGET firestore)
return()
endif()

function(GetReleasedDep version)
message("Getting released firebase-ios-sdk @ ${version}")
ExternalProject_Add(
firestore
ExternalProject_Add(
firestore

DOWNLOAD_DIR ${FIREBASE_DOWNLOAD_DIR}
URL https://github.com/firebase/firebase-ios-sdk/archive/${version}.tar.gz
DOWNLOAD_DIR ${FIREBASE_DOWNLOAD_DIR}
GIT_REPOSITORY https://github.com/firebase/firebase-ios-sdk
GIT_TAG 70aa8b82a2ed36dd14448174bea0fd7e575d4d49
GIT_SHALLOW ON

PREFIX ${PROJECT_BINARY_DIR}

CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
PATCH_COMMAND patch -Np1 -i ${CMAKE_CURRENT_LIST_DIR}/firestore_snappy.patch.txt
HTTP_HEADER "${EXTERNAL_PROJECT_HTTP_HEADER}"
)
endfunction()

function(GetTag t)
message("Getting firebase-ios-sdk from ${t}")
ExternalProject_Add(
firestore

DOWNLOAD_DIR ${FIREBASE_DOWNLOAD_DIR}
GIT_REPOSITORY "https://github.com/firebase/firebase-ios-sdk.git"
GIT_TAG ${t}
GIT_SHALLOW "ON"

PREFIX ${PROJECT_BINARY_DIR}

CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
PATCH_COMMAND patch -Np1 -i ${CMAKE_CURRENT_LIST_DIR}/firestore_snappy.patch.txt
HTTP_HEADER "${EXTERNAL_PROJECT_HTTP_HEADER}"
)
endfunction()

if((NOT FIRESTORE_DEP_SOURCE) OR (FIRESTORE_DEP_SOURCE STREQUAL "RELEASED"))
# Get from released dependency by default
GetReleasedDep("CocoaPods-8.12.1")
else()
if(FIRESTORE_DEP_SOURCE STREQUAL "TIP")
GetTag("origin/master")
else()
GetTag(${FIRESTORE_DEP_SOURCE})
endif()
endif()
PREFIX ${PROJECT_BINARY_DIR}

CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
PATCH_COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/firestore_patch.py --leveldb-version-from ${CMAKE_CURRENT_LIST_DIR}/leveldb.cmake
HTTP_HEADER "${EXTERNAL_PROJECT_HTTP_HEADER}"
)
122 changes: 122 additions & 0 deletions cmake/external/firestore_patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Copyright 2022 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.

"""
Modify the version in leveldb.cmake from the Firebase iOS SDK to match the
version from this C++ SDK.
"""

import argparse
import os
import pathlib
import re
from typing import List, Tuple


VERSION_PATTERN = r"\s*set\s*\(\s*version\s+([^)\s]+)\s*\)\s*"
VERSION_EXPR = re.compile(VERSION_PATTERN, re.IGNORECASE)
URL_HASH_PATTERN = r"\s*URL_HASH\s+([0-9a-zA-Z=]+)\s*"
URL_HASH_EXPR = re.compile(URL_HASH_PATTERN, re.IGNORECASE)


def main() -> None:
(src_file, dest_file) = parse_args()

leveldb_version = load_value(src_file, VERSION_EXPR)
url_hash = load_value(src_file, URL_HASH_EXPR)

set_value(dest_file, VERSION_EXPR, leveldb_version)
set_value(dest_file, URL_HASH_EXPR, url_hash)


def parse_args() -> Tuple[pathlib.Path, pathlib.Path]:
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("--leveldb-version-from", required=True)
arg_parser.add_argument("--leveldb-version-to")

parsed_args = arg_parser.parse_args()

leveldb_cmake_src_file = pathlib.Path(parsed_args.leveldb_version_from)

if parsed_args.leveldb_version_to:
leveldb_cmake_dest_file = pathlib.Path(parsed_args.leveldb_version_to)
else:
leveldb_cmake_dest_file = pathlib.Path.cwd() \
/ "cmake" / "external" / "leveldb.cmake"

return (leveldb_cmake_src_file, leveldb_cmake_dest_file)


def load_value(file_: pathlib.Path, expr: re.Pattern) -> str:
value = None
value_line = None
value_line_number = None

with file_.open("rt", encoding="utf8") as f:
for (line_number, line) in enumerate(f, start=1):
match = expr.fullmatch(line)
if not match:
continue
elif value is not None:
raise RegexMatchError(
f"Multiple lines matching regex {expr.pattern} found in "
f"{file_}: line {value_line_number}, {value_line.strip()} "
f"and line {line_number}, {line.strip()}")

value = match.group(1).strip()
value_line = line
value_line_number = line_number

if value is None:
raise RegexMatchError(
f"No line matching regex {expr.pattern} found in {file_}")

return value


def set_value(file_: pathlib.Path, expr: re.Pattern, version: str) -> None:
with file_.open("rt", encoding="utf8") as f:
lines = list(f)

matching_line = None
matching_line_number = None

for (line_number, line) in enumerate(lines, start=1):
match = expr.fullmatch(line)
if not match:
continue
elif matching_line is not None:
raise RegexMatchError(
f"Multiple lines matching regex {expr.pattern} found in "
f"{file_}: line {matching_line_number}, {matching_line.strip()} "
f"and line {line_number}, {line.strip()}")

lines[line_number - 1] = line[:match.start(1)] + version + line[match.end(1):]
matching_line = line
matching_line_number = line_number

if matching_line is None:
raise RegexMatchError(
f"No line matching regex {expr.pattern} found in {file_}")

with file_.open("wt", encoding="utf8") as f:
f.writelines(lines)


class RegexMatchError(Exception):
pass


if __name__ == "__main__":
main()
Loading