@Nullable
  private static File findCppCompilerExecutable(Project project, CppBinary cppBinary) {
    Throwable throwable = null;
    try {
      if (cppBinary instanceof ConfigurableComponentWithExecutable) {
        PlatformToolProvider toolProvider = ((ConfigurableComponentWithExecutable)cppBinary).getPlatformToolProvider();
        ToolSearchResult toolSearchResult;
        if (GradleVersionUtil.isCurrentGradleAtLeast("4.10")) {
          toolSearchResult = toolProvider.locateTool(ToolType.CPP_COMPILER);
        }
        else {
          Method isToolAvailableMethod = toolProvider.getClass().getDeclaredMethod("isToolAvailable", ToolType.class);
          isToolAvailableMethod.setAccessible(true);
          toolSearchResult = (ToolSearchResult)isToolAvailableMethod.invoke(toolProvider, ToolType.CPP_COMPILER);
        }
        if (toolSearchResult.isAvailable()) {
          if (toolSearchResult instanceof CommandLineToolSearchResult) {
            return ((CommandLineToolSearchResult)toolSearchResult).getTool();
          }
          // dirty hack for gradle versions <= 4.9 because of dummy implementation of org.gradle.nativeplatform.toolchain.internal.msvcpp.VisualCppPlatformToolProvider.isToolAvailable
          if (toolProvider.getClass().getSimpleName().equals("VisualCppPlatformToolProvider")) {
            Field visualCppField = toolProvider.getClass().getDeclaredField("visualCpp");
            visualCppField.setAccessible(true);
            Object visualCpp = visualCppField.get(toolProvider);

            if (visualCpp instanceof NativeLanguageTools) {
              return ((NativeLanguageTools)visualCpp).getCompilerExecutable();
            }
          }
        }
      }
    }
    catch (Throwable t) {
      throwable = t;
    }

    NativeToolChain toolChain = cppBinary.getToolChain();
    String exeName;
    if (toolChain instanceof Gcc) {
      exeName = "g++";
    }
    else if (toolChain instanceof Clang) {
      exeName = "clang++";
    }
    else if (toolChain instanceof VisualCpp) {
      exeName = "cl";
    }
    else {
      exeName = null;
    }

    if (exeName != null) {
      ToolSearchPath toolSearchPath = new ToolSearchPath(OperatingSystem.current());
      CommandLineToolSearchResult searchResult = toolSearchPath.locate(ToolType.CPP_COMPILER, exeName);
      if (searchResult.isAvailable()) {
        return searchResult.getTool();
      }
    }

    if (!GradleVersionUtil.isCurrentGradleAtLeast("4.7")) {
      project.getLogger().error(
        "[sync error] Unable to resolve compiler executable. " +
        "The project uses '" + GradleVersion.current() + "' try to update the gradle version");
    }
    else {
      project.getLogger().error("[sync error] Unable to resolve compiler executable", throwable);
    }
    return null;
  }
@Nullable
  private static File findCppCompilerExecutable(Project project, CppBinary cppBinary)