13
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
-
16
+ """
17
+ Standalone self-sufficient (no external dependencies) python script that can ease
18
+ building desktop apps depending on firebase, by either using the firebase cpp
19
+ source (firebase-cpp-sdk github repo) or the prebuilt release firebase libraries.
20
+
21
+ Note that this script works with only Python3 (3.6+).
22
+ Known side effects:
23
+ If building against firebase cpp source, this script might checkout a specific
24
+ branch on github containing vcpkg. This will not be required once vcpkg is in the
25
+ main branch.
26
+
27
+ Example usage:
28
+ Let's say we want to build the quickstart cpp example for firebase database.
29
+ As specified above, there are 2 options - build against the firebase source or
30
+ prebuilt firebase libraries.
31
+
32
+ # Build against the firebase cpp sdk source
33
+ python3 scripts/build_desktop_app_with_firebase.py --app_dir ~/quickstart-cpp/database/testapp
34
+ --sdk_dir . --build_dir build_source
35
+
36
+ (or)
37
+
38
+ # Build against the prebuilt released firebase libraries
39
+ python3 scripts/build_desktop_app_with_firebase.py --app_dir ~/quickstart-cpp/database/testapp
40
+ --sdk_dir ~/prebuilt/firebase_cpp_sdk_6.15.1/
41
+ --build_dir build_prebuilt
42
+
43
+ # If the script ran successfully, it will print the path to the build directory.
44
+ Build successful!
45
+ Please find your executables in build directory: /Users/<user>/quickstart-cpp/database/testapp/build_source
46
+
47
+ # Running the built example
48
+ $ ./Users/<user>/quickstart-cpp/database/testapp/build_source/desktop_testapp
49
+ """
17
50
import argparse
18
- import sys
51
+ import distutils . spawn
19
52
import os
20
53
import platform
21
54
import subprocess
22
- import distutils . spawn
55
+ import sys
23
56
24
- def is_path_valid (path ):
57
+ def is_path_valid_for_cmake (path ):
58
+ """Check if specified path is setup for cmake"""
25
59
return os .path .exists (os .path .join (path , 'CMakeLists.txt' ))
26
60
27
- def is_sdk_path_source (path ):
61
+ def is_sdk_path_source (sdk_dir ):
62
+ """Validate if firebase sdk dir is firebase cpp source dir"""
28
63
# Not the most reliable way to detect if the sdk path is source or prebuilt but
29
64
# should work for our purpose.
30
- return os .path .exists (os .path .join (path , 'build_tools' ))
65
+ return os .path .exists (os .path .join (sdk_dir , 'build_tools' ))
31
66
32
67
def get_vcpkg_triplet (arch , msvc_runtime_library = 'static' ):
33
68
""" Get vcpkg target triplet (platform definition).
@@ -62,37 +97,47 @@ def get_vcpkg_triplet(arch, msvc_runtime_library='static'):
62
97
return triplet_name
63
98
64
99
def build_source_vcpkg_dependencies (sdk_source_dir , arch , msvc_runtime_library ):
65
- # TODO: Remove this once dev has been merged onto master
66
- # This is required because vcpkg lives only in dev branch right now.
67
- subprocess .run (['git' , 'checkout' , 'feature/python-tool-build-apps-with-firebase' ], cwd = sdk_source_dir )
68
- subprocess .run (['git' , 'pull' ], cwd = sdk_source_dir )
100
+ """Build C++ dependencies for firebase source SDK using vcpkg.
101
+
102
+ Args:
103
+ sdk_source_dir (str): Path to Firebase C++ source directory.
104
+ arch (str): Platform Architecture (example: 'x64').
105
+ msvc_runtime_library (str): Runtime library for MSVC (eg: 'static', 'dynamic').
106
+ """
107
+ # TODO: Remove this once dev branch of firebase-cpp-sdk repo has been merged
108
+ # onto main branch. This is required because vcpkg lives only in dev branch currently.
109
+ subprocess .run (['git' , 'checkout' , 'feature/python-tool-build-apps-with-firebase' ],
110
+ cwd = sdk_source_dir , check = True )
111
+ subprocess .run (['git' , 'pull' ], cwd = sdk_source_dir , check = True )
69
112
70
113
python_exe = 'python3' if distutils .spawn .find_executable ('python3' ) else 'python'
71
- subprocess .run ([python_exe , "scripts/gha/install_prereqs_desktop.py" ], cwd = sdk_source_dir )
114
+ subprocess .run ([python_exe , "scripts/gha/install_prereqs_desktop.py" ],
115
+ cwd = sdk_source_dir , check = True )
72
116
subprocess .run ([python_exe , "scripts/gha/build_desktop.py" , "--arch" , arch ,
73
117
"--msvc_runtime_library" , msvc_runtime_library ,
74
- "--vcpkg_step_only" ], cwd = sdk_source_dir )
118
+ "--vcpkg_step_only" ], cwd = sdk_source_dir , check = True )
75
119
76
- def build_app_with_source (app_dir , sdk_dir , build_dir , arch ,
120
+ def build_app_with_source (app_dir , sdk_source_dir , build_dir , arch ,
77
121
msvc_runtime_library = 'static' , config = None ,
78
122
target_format = None ):
79
- """ CMake configure .
123
+ """Build desktop app directly against the firebase C++ SDK source .
80
124
81
- If you are seeing problems when running this multiple times,
82
- make sure to clean/delete previous build directory.
125
+ Since this invovles a cmake configure, it is advised to run this on a clean
126
+ build directory.
83
127
84
128
Args:
129
+ app_dir (str): Path to directory containing application's CMakeLists.txt.
130
+ sdk_source_dir (str): Path to firebase C++ SDK source directory (root of github repo).
85
131
build_dir (str): Output build directory.
86
132
arch (str): Platform Architecture (example: 'x64').
87
133
msvc_runtime_library (str): Runtime library for MSVC (eg: 'static', 'dynamic').
88
- build_tests (bool): Build cpp unit tests.
89
134
config (str): Release/Debug config.
90
135
If its not specified, cmake's default is used (most likely Debug).
91
136
target_format (str): If specified, build for this targetformat ('frameworks' or 'libraries').
92
137
"""
93
138
# Cmake configure
94
139
cmd = ['cmake' , '-S' , '.' , '-B' , build_dir ]
95
- cmd .append ('-DFIREBASE_CPP_SDK_DIR={0}' .format (sdk_dir ))
140
+ cmd .append ('-DFIREBASE_CPP_SDK_DIR={0}' .format (sdk_source_dir ))
96
141
97
142
# If generator is not specifed, default for platform is used by cmake, else
98
143
# use the specified value
@@ -103,10 +148,10 @@ def build_app_with_source(app_dir, sdk_dir, build_dir, arch,
103
148
104
149
if platform .system () == 'Linux' and arch == 'x86' :
105
150
# Use a separate cmake toolchain for cross compiling linux x86 builds
106
- vcpkg_toolchain_file_path = os .path .join (sdk_dir , 'external' , 'vcpkg' ,
151
+ vcpkg_toolchain_file_path = os .path .join (sdk_source_dir , 'external' , 'vcpkg' ,
107
152
'scripts' , 'buildsystems' , 'linux_32.cmake' )
108
153
else :
109
- vcpkg_toolchain_file_path = os .path .join (sdk_dir , 'external' ,
154
+ vcpkg_toolchain_file_path = os .path .join (sdk_source_dir , 'external' ,
110
155
'vcpkg' , 'scripts' ,
111
156
'buildsystems' , 'vcpkg.cmake' )
112
157
@@ -124,7 +169,7 @@ def build_app_with_source(app_dir, sdk_dir, build_dir, arch,
124
169
125
170
# Use our special cmake option for /MD (dynamic).
126
171
# If this option is not specified, the default value is /MT (static).
127
- if msvc_runtime_library == "dynamic " :
172
+ if msvc_runtime_library == "static " :
128
173
cmd .append ('-DMSVC_RUNTIME_LIBRARY_STATIC=ON' )
129
174
130
175
if (target_format ):
@@ -137,10 +182,25 @@ def build_app_with_source(app_dir, sdk_dir, build_dir, arch,
137
182
print ("Running {0}" .format (' ' .join (cmd )))
138
183
subprocess .run (cmd , cwd = app_dir , check = True )
139
184
140
- def build_app_with_prebuilt (app_dir , sdk_dir , build_dir , arch ,
185
+ def build_app_with_prebuilt (app_dir , sdk_prebuilt_dir , build_dir , arch ,
141
186
msvc_runtime_library = 'static' , config = None ):
187
+ """Build desktop app directly against the prebuilt firebase C++ libraries.
188
+
189
+ Since this invovles a cmake configure, it is advised to run this on a clean
190
+ build directory.
191
+
192
+ Args:
193
+ app_dir (str): Path to directory containing application's CMakeLists.txt.
194
+ sdk_prebuilt_dir (str): Path to prebuilt firebase C++ libraries.
195
+ build_dir (str): Output build directory.
196
+ arch (str): Platform Architecture (example: 'x64').
197
+ msvc_runtime_library (str): Runtime library for MSVC (eg: 'static', 'dynamic').
198
+ config (str): Release/Debug config.
199
+ If its not specified, cmake's default is used (most likely Debug).
200
+ """
201
+
142
202
cmd = ['cmake' , '-S' , '.' , '-B' , build_dir ]
143
- cmd .append ('-DFIREBASE_CPP_SDK_DIR={0}' .format (sdk_dir ))
203
+ cmd .append ('-DFIREBASE_CPP_SDK_DIR={0}' .format (sdk_prebuilt_dir ))
144
204
145
205
if platform .system () == 'Windows' :
146
206
if arch == 'x64' :
@@ -164,12 +224,12 @@ def build_app_with_prebuilt(app_dir, sdk_dir, build_dir, arch,
164
224
def main ():
165
225
args = parse_cmdline_args ()
166
226
167
- if not is_path_valid (args .sdk_dir ):
227
+ if not is_path_valid_for_cmake (args .sdk_dir ):
168
228
print ("SDK path provided is not valid. Could not find a CMakeLists.txt at the root level.\n "
169
229
"Please check the argument to '--sdk_dir'" )
170
230
sys .exit (1 )
171
231
172
- if not is_path_valid (args .app_dir ):
232
+ if not is_path_valid_for_cmake (args .app_dir ):
173
233
print ("App path provided is not valid. Could not find a CMakeLists.txt at the root level.\n "
174
234
"Please check the argument to '--app_dir'" )
175
235
sys .exit (1 )
0 commit comments