From b4c9de77f75f324b1120f0b4dac1d40b606dfe08 Mon Sep 17 00:00:00 2001 From: Alex Ames Date: Wed, 16 Jun 2021 16:16:40 -0700 Subject: [PATCH 1/4] Added build source to user agent string. This allows the library to determine whether the library was built on github or not. --- CMakeLists.txt | 14 +++++++++++--- app/src/app_common.cc | 8 ++++++++ app/src/app_common.h | 1 + scripts/gha/build_desktop.py | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7795d9a946..70afbd3eef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,11 +66,15 @@ option(FIREBASE_FORCE_FAKE_SECURE_STORAGE option(FIREBASE_CPP_BUILD_PACKAGE "Bundle the Firebase C++ libraries into a zip file." OFF) option(FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD - "When building with Gradle, use the previously built libraries." OFF) + "When building with Gradle, use the previously built libraries." OFF) option(FIREBASE_USE_BORINGSSL - "Build against BoringSSL instead of using your system's OpenSSL." OFF) + "Build against BoringSSL instead of using your system's OpenSSL." OFF) option(FIREBASE_USE_LINUX_CXX11_ABI - "Build Linux SDK using the C++11 ABI instead of the legacy ABI." OFF) + "Build Linux SDK using the C++11 ABI instead of the legacy ABI." OFF) + +# This should only be enabled by the GitHub Action build script. +option(FIREBASE_GITHUB_ACTION_BUILD + "Indicates that this build was created from a GitHub Action" OFF) set(FIREBASE_ANDROID_STL "" CACHE STRING "STL implementation to use.") if (NOT FIREBASE_ANDROID_STL STREQUAL "") @@ -139,6 +143,10 @@ if(DESKTOP AND NOT MSVC AND NOT APPLE) endif() endif() +if(FIREBASE_GITHUB_ACTION_BUILD) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIREBASE_GITHUB_ACTION_BUILD=1") +endif() + # Set directories needed by the Firebase subprojects # Directory to store generated files. set(FIREBASE_GEN_FILE_DIR ${CMAKE_BINARY_DIR}/generated) diff --git a/app/src/app_common.cc b/app/src/app_common.cc index 99425b7e54..709af66c7a 100644 --- a/app/src/app_common.cc +++ b/app/src/app_common.cc @@ -164,6 +164,12 @@ const char* kCpuArchitecture = "x86"; #else #error Unknown operating system. #endif // Operating system + +#if FIREBASE_GITHUB_ACTION_BUILD +const char* kBuildSource = "github_action_built"; +#elif +const char* kBuildSource = "custom_built"; +#endif // clang-format=on const char* kApiClientHeader = "x-firebase-client"; @@ -303,6 +309,8 @@ App* AddApp(App* app, std::map* results) { kCpuArchitecture); App::RegisterLibrary(FIREBASE_CPP_USER_AGENT_PREFIX "-stl", kCppRuntimeOrStl); + App::RegisterLibrary(FIREBASE_CPP_USER_AGENT_PREFIX "-buildsrc", + kBuildSource); } callback::Initialize(); AppCallback::NotifyAllAppCreated(app, results); diff --git a/app/src/app_common.h b/app/src/app_common.h index 2f585acab2..1769da3674 100644 --- a/app/src/app_common.h +++ b/app/src/app_common.h @@ -45,6 +45,7 @@ namespace app_common { extern const char* kOperatingSystem; extern const char* kCppRuntimeOrStl; extern const char* kCpuArchitecture; +extern const char* kBuildSource; // Extended API client header for Google user agent strings. extern const char* kApiClientHeader; diff --git a/scripts/gha/build_desktop.py b/scripts/gha/build_desktop.py index 186abe3ac4..e053d712df 100644 --- a/scripts/gha/build_desktop.py +++ b/scripts/gha/build_desktop.py @@ -182,6 +182,8 @@ def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='l else: # workaround, absl doesn't build without tests enabled cmd.append('-DBUILD_TESTING=off') + # When building from GitHub Actions, this should always be set. + cmd.append('-DFIREBASE_GITHUB_ACTION_BUILD=ON') if not disable_vcpkg: if utils.is_linux_os() and arch == 'x86': From 061e78a9b6f95958e38b3bf53e54e8c1faef1416 Mon Sep 17 00:00:00 2001 From: Alex Ames Date: Fri, 18 Jun 2021 15:45:08 -0700 Subject: [PATCH 2/4] Updated how the GHA flag is set --- .github/workflows/cpp-packaging.yml | 2 +- .github/workflows/desktop.yml | 2 +- CMakeLists.txt | 2 ++ scripts/gha/build_desktop.py | 13 +++++++++---- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cpp-packaging.yml b/.github/workflows/cpp-packaging.yml index f77cdd13cc..a4278b74d1 100644 --- a/.github/workflows/cpp-packaging.yml +++ b/.github/workflows/cpp-packaging.yml @@ -351,7 +351,7 @@ jobs: # Run the build in the host OS default shell since Windows can't handle long path names in bash. - name: Build desktop SDK run: | - 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 }} + 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 - name: Archive SDK shell: bash diff --git a/.github/workflows/desktop.yml b/.github/workflows/desktop.yml index 103ab7066a..5ff5df0911 100644 --- a/.github/workflows/desktop.yml +++ b/.github/workflows/desktop.yml @@ -151,7 +151,7 @@ jobs: - name: Build SDK shell: bash run: | - python scripts/gha/build_desktop.py --build_tests --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" + python scripts/gha/build_desktop.py --build_tests --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" --gha_build - name: Stats for ccache (mac and linux) if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos') diff --git a/CMakeLists.txt b/CMakeLists.txt index 70afbd3eef..a33df70e74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,8 @@ endif() if(FIREBASE_GITHUB_ACTION_BUILD) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIREBASE_GITHUB_ACTION_BUILD=1") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIREBASE_GITHUB_ACTION_BUILD=0") endif() # Set directories needed by the Firebase subprojects diff --git a/scripts/gha/build_desktop.py b/scripts/gha/build_desktop.py index e053d712df..511ef31195 100644 --- a/scripts/gha/build_desktop.py +++ b/scripts/gha/build_desktop.py @@ -150,7 +150,7 @@ def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, cleanup=True def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='legacy', build_tests=True, config=None, target_format=None, - use_openssl=False, disable_vcpkg=False, verbose=False): + use_openssl=False, disable_vcpkg=False, gha_build=False,verbose=False): """ CMake configure. 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 use_openssl (bool) : Use prebuilt OpenSSL library instead of using boringssl downloaded and built during the cmake configure step. disable_vcpkg (bool): If True, skip vcpkg and just use CMake for deps. + gha_build (bool): If True, this build will be marked as having been built + from GitHub, which is useful for metrics tracking. verbose (bool): If True, enable verbose mode in the CMake file. """ cmd = ['cmake', '-S', '.', '-B', build_dir] @@ -182,8 +184,6 @@ def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='l else: # workaround, absl doesn't build without tests enabled cmd.append('-DBUILD_TESTING=off') - # When building from GitHub Actions, this should always be set. - cmd.append('-DFIREBASE_GITHUB_ACTION_BUILD=ON') if not disable_vcpkg: if utils.is_linux_os() and arch == 'x86': @@ -218,6 +218,10 @@ def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='l if not use_openssl: cmd.append('-DFIREBASE_USE_BORINGSSL=ON') + # When building from GitHub Actions, this should always be set. + if gha_build: + cmd.append('-DFIREBASE_GITHUB_ACTION_BUILD=ON') + # Print out every command while building. if verbose: cmd.append('-DCMAKE_VERBOSE_MAKEFILE=1') @@ -250,7 +254,7 @@ def main(): # CMake configure cmake_configure(args.build_dir, args.arch, args.msvc_runtime_library, args.linux_abi, args.build_tests, args.config, args.target_format, - args.use_openssl, args.disable_vcpkg, args.verbose) + args.use_openssl, args.disable_vcpkg, args.gha_build, args.verbose) # CMake build # cmake --build build -j 8 @@ -280,6 +284,7 @@ def parse_cmdline_args(): parser.add_argument('--target', nargs='+', help='A list of CMake build targets (eg: firebase_app firebase_auth)') parser.add_argument('--target_format', default=None, help='(Mac only) whether to output frameworks (default) or libraries.') parser.add_argument('--use_openssl', action='store_true', default=None, help='Use openssl for build instead of boringssl') + parser.add_argument('--gha_build', action='store_true', default=None, help='Set to true when building on GitHub, for metric tracking purposes') args = parser.parse_args() return args From e22580edb9a8835181d29d25d0aaa28c0fecf038 Mon Sep 17 00:00:00 2001 From: Alex Ames Date: Mon, 21 Jun 2021 10:04:53 -0700 Subject: [PATCH 3/4] Fixed preprocessor else statement --- app/src/app_common.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/app_common.cc b/app/src/app_common.cc index 709af66c7a..a931b23db3 100644 --- a/app/src/app_common.cc +++ b/app/src/app_common.cc @@ -167,7 +167,7 @@ const char* kCpuArchitecture = "x86"; #if FIREBASE_GITHUB_ACTION_BUILD const char* kBuildSource = "github_action_built"; -#elif +#else const char* kBuildSource = "custom_built"; #endif // clang-format=on From 4ff5786ff179eecc99ca4302f700a25b1a673333 Mon Sep 17 00:00:00 2001 From: Alex Ames Date: Mon, 21 Jun 2021 10:06:15 -0700 Subject: [PATCH 4/4] Fixed formatting --- scripts/gha/build_desktop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gha/build_desktop.py b/scripts/gha/build_desktop.py index 511ef31195..3542a27713 100644 --- a/scripts/gha/build_desktop.py +++ b/scripts/gha/build_desktop.py @@ -150,7 +150,7 @@ def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, cleanup=True def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='legacy', build_tests=True, config=None, target_format=None, - use_openssl=False, disable_vcpkg=False, gha_build=False,verbose=False): + use_openssl=False, disable_vcpkg=False, gha_build=False, verbose=False): """ CMake configure. If you are seeing problems when running this multiple times,