Exemplo n.º 1
0
def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, cleanup=True,
                                        use_openssl=False):
  """Install packages with vcpkg and optionally cleanup any intermediates.

  This is a wrapper over a low level installation function and attempts the
  installation twice, a second time after attempting to auto fix known issues.

  Args:
    arch (str): Architecture (eg: 'x86', 'x64', 'arm64').
    msvc_runtime_library (str): Runtime library for MSVC (eg: 'static', 'dynamic').
    cleanup (bool): Clean up intermediate files used during installation.
    use_openssl (bool): Use OpenSSL based vcpkg response files.

  Raises:
    (ValueError) If installation wasn't successful.
  """
  _install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, use_openssl)
  vcpkg_triplet = utils.get_vcpkg_triplet(arch, msvc_runtime_library)
  # Verify the installation with an attempt to auto fix any issues.
  success = utils.verify_vcpkg_build(vcpkg_triplet, attempt_auto_fix=True)
  if not success:
    print("Installation was not successful but auto fix was attempted. "
          "Retrying installation...")
    # Retry once more after attempted auto fix.
    _install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library)
    # Check for success again. If installation failed, this call will raise a ValueError.
    success = utils.verify_vcpkg_build(vcpkg_triplet, attempt_auto_fix=False)

  if cleanup:
    # Clear temporary directories and files created by vcpkg buildtrees
    # could be several GBs and cause github runners to run out of space
    utils.clean_vcpkg_temp_data()
Exemplo n.º 2
0
def _install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, use_openssl=False):
  """Install packages with vcpkg.

  This does the following,
    - initialize/update the vcpkg git submodule
    - build vcpkg executable
    - install packages via vcpkg.
  Args:
    arch (str): Architecture (eg: 'x86', 'x64', 'arm64').
    msvc_runtime_library (str): Runtime library for MSVC (eg: 'static', 'dynamic').
    use_openssl (bool): Use OpenSSL based vcpkg response files.
  """

  # Install vcpkg executable if its not installed already
  vcpkg_executable_file_path = utils.get_vcpkg_executable_file_path()
  found_vcpkg_executable = os.path.exists(vcpkg_executable_file_path)
  if not found_vcpkg_executable:
    script_absolute_path = utils.get_vcpkg_installation_script_path()
    # Example: ./external/vcpkg/bootstrap-sh
    utils.run_command([script_absolute_path], check=True)

  # Copy any of our custom defined vcpkg data to vcpkg submodule directory
  utils.copy_vcpkg_custom_data()

  # for each desktop platform, there exists a vcpkg response file in the repo
  # (external/vcpkg_<triplet>_response_file.txt) defined for each target triplet
  vcpkg_triplet = utils.get_vcpkg_triplet(arch, msvc_runtime_library)
  vcpkg_response_files_dir_path = os.path.join(os.getcwd(), 'external', 'vcpkg_custom_data',
                      'response_files')
  if use_openssl:
    vcpkg_response_files_dir_path = os.path.join(vcpkg_response_files_dir_path, 'openssl')

  vcpkg_response_file_path = os.path.join(vcpkg_response_files_dir_path,
                                          '{0}.txt'.format(vcpkg_triplet))

  # Eg: ./external/vcpkg/vcpkg install @external/vcpkg_x64-osx_response_file.txt
  # --disable-metrics
  utils.run_command([vcpkg_executable_file_path, 'install',
                     '@' + vcpkg_response_file_path, '--disable-metrics'],
                    check=True)
Exemplo n.º 3
0
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):
  """ CMake configure.

  If you are seeing problems when running this multiple times,
  make sure to clean/delete previous build directory.

  Args:
   build_dir (str): Output build directory.
   arch (str): Platform Architecture (example: 'x64', 'x86', 'arm64').
   msvc_runtime_library (str): Runtime library for MSVC (eg: 'static', 'dynamic').
   linux_abi (str): Linux ABI (eg: 'legacy', 'c++11').
   build_tests (bool): Build cpp unit tests.
   config (str): Release/Debug config.
          If its not specified, cmake's default is used (most likely Debug).
   target_format (str): If specified, build for this targetformat ('frameworks' or 'libraries').
   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]

  # If generator is not specifed, default for platform is used by cmake, else
  # use the specified value
  if config:
    cmd.append('-DCMAKE_BUILD_TYPE={0}'.format(config))
  if build_tests:
    cmd.append('-DFIREBASE_CPP_BUILD_TESTS=ON')
    cmd.append('-DFIREBASE_FORCE_FAKE_SECURE_STORAGE=ON')
  else:
    # workaround, absl doesn't build without tests enabled
    cmd.append('-DBUILD_TESTING=off')

  if not disable_vcpkg:
    if utils.is_linux_os() and arch == 'x86':
      # Use a separate cmake toolchain for cross compiling linux x86 builds
      vcpkg_toolchain_file_path = os.path.join(os.getcwd(), 'external', 'vcpkg',
                                               'scripts', 'buildsystems', 'linux_32.cmake')
    elif utils.is_mac_os() and arch == 'arm64':
      vcpkg_toolchain_file_path = os.path.join(os.getcwd(), 'external', 'vcpkg',
                                               'scripts', 'buildsystems', 'macos_arm64.cmake')
    else:
      vcpkg_toolchain_file_path = os.path.join(os.getcwd(), 'external',
                                               'vcpkg', 'scripts',
                                               'buildsystems', 'vcpkg.cmake')
    cmd.append('-DCMAKE_TOOLCHAIN_FILE={0}'.format(vcpkg_toolchain_file_path))
    vcpkg_triplet = utils.get_vcpkg_triplet(arch, msvc_runtime_library)
    cmd.append('-DVCPKG_TARGET_TRIPLET={0}'.format(vcpkg_triplet))

  if utils.is_windows_os():
    # If building for x86, we should supply -A Win32 to cmake configure
    # Its a good habit to specify for x64 too as the default might be different
    # on different windows machines.
    cmd.append('-A')
    cmd.append('Win32') if arch == 'x86' else cmd.append('x64')

    # Use our special cmake flag to specify /MD vs /MT
    if msvc_runtime_library == "static":
      cmd.append('-DMSVC_RUNTIME_LIBRARY_STATIC=ON')

  if utils.is_mac_os():
    if (arch == 'arm64'):
      cmd.append('-DCMAKE_OSX_ARCHITECTURES=arm64')
    else:
      cmd.append('-DCMAKE_OSX_ARCHITECTURES=x86_64')

  if utils.is_linux_os() and linux_abi == 'c++11':
      cmd.append('-DFIREBASE_LINUX_USE_CXX11_ABI=TRUE')

  if (target_format):
    cmd.append('-DFIREBASE_XCODE_TARGET_FORMAT={0}'.format(target_format))

  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')

  utils.run_command(cmd)
Exemplo n.º 4
0
def main(argv):
  if len(argv) > 1:
    raise app.UsageError("Too many command-line arguments.")

  platforms = FLAGS.platforms
  testapps = FLAGS.testapps

  sdk_dir = _fix_path(FLAGS.packaged_sdk or FLAGS.repo_dir)
  root_output_dir = _fix_path(FLAGS.output_directory)
  repo_dir = _fix_path(FLAGS.repo_dir)

  update_pod_repo = FLAGS.update_pod_repo
  if FLAGS.add_timestamp:
    timestamp = datetime.datetime.now().strftime("%Y_%m_%d-%H_%M_%S")
  else:
    timestamp = ""

  if FLAGS.short_output_paths:
    output_dir = os.path.join(root_output_dir, "ta")
  else:
    output_dir = os.path.join(root_output_dir, "testapps" + timestamp)

  config = config_reader.read_config()

  xcframework_dir = os.path.join(sdk_dir, "xcframeworks")
  xcframework_exist = os.path.isdir(xcframework_dir)
  if not xcframework_exist:
    if _IOS in platforms:
      _build_xcframework_from_repo(repo_dir, "ios", testapps, config)
    if _TVOS in platforms:
      _build_xcframework_from_repo(repo_dir, "tvos", testapps, config)

  if update_pod_repo and (_IOS in platforms or _TVOS in platforms):
    _run(["pod", "repo", "update"])

  cmake_flags = _get_desktop_compiler_flags(FLAGS.compiler, config.compilers)
  # VCPKG is used to install dependencies for the desktop SDK.
  # Building from source requires building the underlying SDK libraries,
  # so we need to use VCPKG as well.
  if _DESKTOP in platforms and not FLAGS.packaged_sdk:
    vcpkg_arch = FLAGS.arch
    installer = os.path.join(repo_dir, "scripts", "gha", "build_desktop.py")
    _run([sys.executable, installer, "--vcpkg_step_only", "--arch", vcpkg_arch])
    toolchain_file = os.path.join(
        repo_dir, "external", "vcpkg", "scripts", "buildsystems", "vcpkg.cmake")
    if utils.is_mac_os() and FLAGS.arch == "arm64":
      toolchain_file = os.path.join(
          repo_dir, "external", "vcpkg", "scripts", "buildsystems", "macos_arm64.cmake")
    if utils.is_linux_os() and FLAGS.arch == "x86":
      toolchain_file = os.path.join(
          repo_dir, "external", "vcpkg", "scripts", "buildsystems", "linux_32.cmake")

    cmake_flags.extend((
        "-DCMAKE_TOOLCHAIN_FILE=%s" % toolchain_file,
        "-DVCPKG_TARGET_TRIPLET=%s" % utils.get_vcpkg_triplet(arch=vcpkg_arch)
    ))

  if FLAGS.cmake_flag:
    cmake_flags.extend(FLAGS.cmake_flag)

  failures = []
  for testapp in testapps:
    api_config = config.get_api(testapp)
    if FLAGS.repo_dir and not FLAGS.packaged_sdk and api_config.internal_testapp_path:
      testapp_dirs = [api_config.internal_testapp_path]
    else:
      testapp_dirs = [api_config.testapp_path]
    for testapp_dir in testapp_dirs:
      logging.info("BEGIN building for %s: %s", testapp, testapp_dir)
      failures += _build(
          testapp=testapp,
          platforms=platforms,
          api_config=config.get_api(testapp),
          testapp_dir=testapp_dir,
          output_dir=output_dir,
          sdk_dir=sdk_dir,
          xcframework_exist=xcframework_exist,
          repo_dir=repo_dir,
          ios_sdk=FLAGS.ios_sdk,
          tvos_sdk=FLAGS.tvos_sdk,
          cmake_flags=cmake_flags,
          short_output_paths=FLAGS.short_output_paths)
      logging.info("END building for %s", testapp)
  
  _collect_integration_tests(testapps, root_output_dir, output_dir, FLAGS.artifact_name)

  _summarize_results(testapps, platforms, failures, root_output_dir, FLAGS.artifact_name)
  return 1 if failures else 0