Skip to content

Commit d682fd9

Browse files
author
Alex Ames
authored
Added build source to user agent string. (#480)
This allows the library to determine whether the library was built on github or not.
1 parent 287f764 commit d682fd9

File tree

6 files changed

+33
-7
lines changed

6 files changed

+33
-7
lines changed

.github/workflows/cpp-packaging.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ jobs:
351351
# Run the build in the host OS default shell since Windows can't handle long path names in bash.
352352
- name: Build desktop SDK
353353
run: |
354-
python scripts/gha/build_desktop.py --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" --linux_abi "${{ matrix.linux_abi }}" --build_dir out-sdk ${VERBOSE_FLAG} ${{ matrix.additional_build_flags }}
354+
python scripts/gha/build_desktop.py --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" --linux_abi "${{ matrix.linux_abi }}" --build_dir out-sdk ${VERBOSE_FLAG} ${{ matrix.additional_build_flags }} --gha_build
355355
356356
- name: Archive SDK
357357
shell: bash

.github/workflows/desktop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ jobs:
151151
- name: Build SDK
152152
shell: bash
153153
run: |
154-
python scripts/gha/build_desktop.py --build_tests --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}"
154+
python scripts/gha/build_desktop.py --build_tests --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" --gha_build
155155
156156
- name: Stats for ccache (mac and linux)
157157
if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')

CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ option(FIREBASE_FORCE_FAKE_SECURE_STORAGE
6666
option(FIREBASE_CPP_BUILD_PACKAGE
6767
"Bundle the Firebase C++ libraries into a zip file." OFF)
6868
option(FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD
69-
"When building with Gradle, use the previously built libraries." OFF)
69+
"When building with Gradle, use the previously built libraries." OFF)
7070
option(FIREBASE_USE_BORINGSSL
71-
"Build against BoringSSL instead of using your system's OpenSSL." OFF)
71+
"Build against BoringSSL instead of using your system's OpenSSL." OFF)
7272
option(FIREBASE_USE_LINUX_CXX11_ABI
73-
"Build Linux SDK using the C++11 ABI instead of the legacy ABI." OFF)
73+
"Build Linux SDK using the C++11 ABI instead of the legacy ABI." OFF)
74+
75+
# This should only be enabled by the GitHub Action build script.
76+
option(FIREBASE_GITHUB_ACTION_BUILD
77+
"Indicates that this build was created from a GitHub Action" OFF)
7478

7579
set(FIREBASE_ANDROID_STL "" CACHE STRING "STL implementation to use.")
7680
if (NOT FIREBASE_ANDROID_STL STREQUAL "")
@@ -139,6 +143,12 @@ if(DESKTOP AND NOT MSVC AND NOT APPLE)
139143
endif()
140144
endif()
141145

146+
if(FIREBASE_GITHUB_ACTION_BUILD)
147+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIREBASE_GITHUB_ACTION_BUILD=1")
148+
else()
149+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIREBASE_GITHUB_ACTION_BUILD=0")
150+
endif()
151+
142152
# Set directories needed by the Firebase subprojects
143153
# Directory to store generated files.
144154
set(FIREBASE_GEN_FILE_DIR ${CMAKE_BINARY_DIR}/generated)

app/src/app_common.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ const char* kCpuArchitecture = "x86";
164164
#else
165165
#error Unknown operating system.
166166
#endif // Operating system
167+
168+
#if FIREBASE_GITHUB_ACTION_BUILD
169+
const char* kBuildSource = "github_action_built";
170+
#else
171+
const char* kBuildSource = "custom_built";
172+
#endif
167173
// clang-format=on
168174

169175
const char* kApiClientHeader = "x-firebase-client";
@@ -303,6 +309,8 @@ App* AddApp(App* app, std::map<std::string, InitResult>* results) {
303309
kCpuArchitecture);
304310
App::RegisterLibrary(FIREBASE_CPP_USER_AGENT_PREFIX "-stl",
305311
kCppRuntimeOrStl);
312+
App::RegisterLibrary(FIREBASE_CPP_USER_AGENT_PREFIX "-buildsrc",
313+
kBuildSource);
306314
}
307315
callback::Initialize();
308316
AppCallback::NotifyAllAppCreated(app, results);

app/src/app_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ namespace app_common {
4545
extern const char* kOperatingSystem;
4646
extern const char* kCppRuntimeOrStl;
4747
extern const char* kCpuArchitecture;
48+
extern const char* kBuildSource;
4849

4950
// Extended API client header for Google user agent strings.
5051
extern const char* kApiClientHeader;

scripts/gha/build_desktop.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, cleanup=True
150150

151151
def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='legacy',
152152
build_tests=True, config=None, target_format=None,
153-
use_openssl=False, disable_vcpkg=False, verbose=False):
153+
use_openssl=False, disable_vcpkg=False, gha_build=False, verbose=False):
154154
""" CMake configure.
155155
156156
If you are seeing problems when running this multiple times,
@@ -168,6 +168,8 @@ def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='l
168168
use_openssl (bool) : Use prebuilt OpenSSL library instead of using boringssl
169169
downloaded and built during the cmake configure step.
170170
disable_vcpkg (bool): If True, skip vcpkg and just use CMake for deps.
171+
gha_build (bool): If True, this build will be marked as having been built
172+
from GitHub, which is useful for metrics tracking.
171173
verbose (bool): If True, enable verbose mode in the CMake file.
172174
"""
173175
cmd = ['cmake', '-S', '.', '-B', build_dir]
@@ -216,6 +218,10 @@ def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='l
216218
if not use_openssl:
217219
cmd.append('-DFIREBASE_USE_BORINGSSL=ON')
218220

221+
# When building from GitHub Actions, this should always be set.
222+
if gha_build:
223+
cmd.append('-DFIREBASE_GITHUB_ACTION_BUILD=ON')
224+
219225
# Print out every command while building.
220226
if verbose:
221227
cmd.append('-DCMAKE_VERBOSE_MAKEFILE=1')
@@ -248,7 +254,7 @@ def main():
248254
# CMake configure
249255
cmake_configure(args.build_dir, args.arch, args.msvc_runtime_library, args.linux_abi,
250256
args.build_tests, args.config, args.target_format,
251-
args.use_openssl, args.disable_vcpkg, args.verbose)
257+
args.use_openssl, args.disable_vcpkg, args.gha_build, args.verbose)
252258

253259
# CMake build
254260
# cmake --build build -j 8
@@ -278,6 +284,7 @@ def parse_cmdline_args():
278284
parser.add_argument('--target', nargs='+', help='A list of CMake build targets (eg: firebase_app firebase_auth)')
279285
parser.add_argument('--target_format', default=None, help='(Mac only) whether to output frameworks (default) or libraries.')
280286
parser.add_argument('--use_openssl', action='store_true', default=None, help='Use openssl for build instead of boringssl')
287+
parser.add_argument('--gha_build', action='store_true', default=None, help='Set to true when building on GitHub, for metric tracking purposes')
281288
args = parser.parse_args()
282289
return args
283290

0 commit comments

Comments
 (0)