Add windows tests for C++ builds (#10364)

* Adding non-docker builds for protoc in our supported build systems

* Tweaking bazel builds

* Fixing compatibility with older CMake used by kokoro

* Fixing configs to point to proper scripts

* Propagate errors up properly

* Reinstall Bazel, point NMake to compiler, fix broken static_assert in test

* Adding common setup, enabling long paths

* Explicitly pick 64-bit compiler

* Removing arch from nmake build

* Try to upgrade cmake for installation

* Enabling 8.3 filename support (https://bazel.build/docs/windows)

* Fixing choco calls

* Making installation use Release

* Switching to batch for common config

* Fixing some install test issues unique to Windows

* Attempt another way to get shorter Bazel paths

* More windows bazel tweaks

* Fixing shared library failure from non-exported function used in tests

* Use commandline flags instead of bazelrc

* Fix line break mismatch

* Add .exe extension for test plugin on windows

* Add temporary logging

* Switch to rootpath over hardcoded system-dependent plugin path

* Enabling symlinks/runfiles to fix broken test on windows
pull/10384/head
Mike Kruskal 3 years ago committed by GitHub
parent 50d23a3822
commit 69c1fa531c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      CMakeLists.txt
  2. 28
      kokoro/windows/bazel/build.bat
  3. 2
      kokoro/windows/bazel/continuous.cfg
  4. 2
      kokoro/windows/bazel/presubmit.cfg
  5. 30
      kokoro/windows/cmake/build.bat
  6. 43
      kokoro/windows/cmake_install/build.bat
  7. 32
      kokoro/windows/cmake_nmake/build.bat
  8. 31
      kokoro/windows/cmake_shared/build.bat
  9. 2
      kokoro/windows/cmake_shared/continuous.cfg
  10. 2
      kokoro/windows/cmake_shared/presubmit.cfg
  11. 16
      kokoro/windows/prepare_build_win64.bat
  12. 3
      src/google/protobuf/compiler/BUILD.bazel
  13. 4
      src/google/protobuf/compiler/command_line_interface_unittest.cc
  14. 4
      src/google/protobuf/compiler/csharp/csharp_helpers.h
  15. 9
      src/google/protobuf/util/BUILD.bazel

@ -324,8 +324,8 @@ if (protobuf_BUILD_PROTOBUF_BINARIES)
endif ()
endif ()
else ()
find_package(protobuf)
if (protobuf_FOUND)
find_package(Protobuf NO_MODULE)
if (Protobuf_FOUND)
set(protobuf_PROTOC_EXE protobuf::protoc)
set(protobuf_LIB_PROTOC protobuf::libprotoc)
set(protobuf_LIB_PROTOBUF protobuf::libprotobuf)

@ -1,4 +1,30 @@
@rem enter repo root
cd /d %~dp0\..\..\..
@rem TODO(mkruskal) Implement tests
call kokoro\windows\prepare_build_win64.bat || goto :error
@rem Allow Bazel to create short paths.
fsutil 8dot3name set 0
@rem TODO(b/241475022) Use docker to guarantee better stability.
@rem Reinstall Bazel due to corupt installation in kokoro.
bazel version
choco install bazel -y -i
bazel version
@rem Make paths as short as possible to avoid long path issues.
set BAZEL_STARTUP=--output_user_root=C:/tmp --windows_enable_symlinks
set BAZEL_FLAGS=--enable_runfiles --keep_going --test_output=streamed --verbose_failures
@rem Build libraries first.
bazel %BAZEL_STARTUP% build //:protoc //:protobuf //:protobuf_lite %BAZEL_FLAGS% || goto :error
@rem Run C++ tests.
bazel %BAZEL_STARTUP% test //src/... %BAZEL_FLAGS% || goto :error
goto :EOF
:error
echo Failed!
exit /b 1

@ -1,5 +1,5 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/windows/cmake/build.bat"
build_file: "protobuf/kokoro/windows/bazel/build.bat"
timeout_mins: 1440

@ -1,5 +1,5 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/windows/cmake/build.bat"
build_file: "protobuf/kokoro/windows/bazel/build.bat"
timeout_mins: 1440

@ -1,4 +1,32 @@
@rem enter repo root
cd /d %~dp0\..\..\..
@rem TODO(mkruskal) Implement tests
call kokoro\windows\prepare_build_win64.bat || goto :error
@rem TODO(b/241475022) Use docker to guarantee better stability.
@rem TODO(b/241484899) Run conformance tests in windows.
md build -ea 0
md %KOKORO_ARTIFACTS_DIR%\logs -ea 0
cd build
cmake .. ^
-G "Visual Studio 15 2017" -A x64 ^
-Dprotobuf_BUILD_CONFORMANCE=OFF ^
-Dprotobuf_WITH_ZLIB=OFF ^
-Dprotobuf_TEST_XML_OUTDIR=%KOKORO_ARTIFACTS_DIR%\logs\ || goto :error
cmake --build . || goto :error
ctest --verbose -C Debug || goto :error
goto :success
:error
cd /d %~dp0\..\..\..
echo Failed!
exit /b 1
:success
cd ..

@ -1,4 +1,45 @@
@rem enter repo root
cd /d %~dp0\..\..\..
@rem TODO(mkruskal) Implement tests
call kokoro\windows\prepare_build_win64.bat || goto :error
@rem TODO(b/241475022) Use docker to guarantee better stability.
@rem TODO(b/241484899) Run conformance tests in windows.
md build -ea 0
md %KOKORO_ARTIFACTS_DIR%\logs -ea 0
cd build
@rem First install protobuf from source.
cmake .. ^
-G "Visual Studio 15 2017" -A x64 ^
-Dprotobuf_BUILD_CONFORMANCE=OFF ^
-Dprotobuf_WITH_ZLIB=OFF || goto :error
cmake --build . --target install || goto :error
@rem Next run tests forcing the use of our installation.
rm -rf *
cmake .. ^
-G "Visual Studio 15 2017" -A x64 ^
-Dprotobuf_REMOVE_INSTALLED_HEADERS=ON ^
-Dprotobuf_BUILD_PROTOBUF_BINARIES=OFF ^
-Dprotobuf_BUILD_CONFORMANCE=OFF ^
-Dprotobuf_TEST_XML_OUTDIR=%KOKORO_ARTIFACTS_DIR%\logs\ || goto :error
cmake --build . --target ALL_BUILD || goto :error
ctest --verbose -C Debug || goto :error
goto :success
:error
cd /d %~dp0\..\..\..
echo Failed!
exit /b 1
:success
cd ..

@ -1,4 +1,34 @@
@rem enter repo root
cd /d %~dp0\..\..\..
@rem TODO(mkruskal) Implement tests
call kokoro\windows\prepare_build_win64.bat || goto :error
@rem TODO(b/241475022) Use docker to guarantee better stability.
@rem TODO(b/241484899) Run conformance tests in windows.
md build -ea 0
md %KOKORO_ARTIFACTS_DIR%\logs -ea 0
cd build
cmake .. ^
-G "NMake Makefiles" ^
-DCMAKE_C_COMPILER=cl.exe ^
-DCMAKE_CXX_COMPILER=cl.exe ^
-Dprotobuf_BUILD_CONFORMANCE=OFF ^
-Dprotobuf_WITH_ZLIB=OFF ^
-Dprotobuf_TEST_XML_OUTDIR=%KOKORO_ARTIFACTS_DIR%\logs\ || goto :error
cmake --build . || goto :error
ctest --verbose -C Debug || goto :error
goto :success
:error
cd /d %~dp0\..\..\..
echo Failed!
exit /b 1
:success
cd ..

@ -1,4 +1,33 @@
@rem enter repo root
cd /d %~dp0\..\..\..
@rem TODO(mkruskal) Implement tests
call kokoro\windows\prepare_build_win64.bat || goto :error
@rem TODO(b/241475022) Use docker to guarantee better stability.
@rem TODO(b/241484899) Run conformance tests in windows.
md build -ea 0
md %KOKORO_ARTIFACTS_DIR%\logs -ea 0
cd build
cmake .. ^
-G "Visual Studio 15 2017" -A x64 ^
-Dprotobuf_BUILD_SHARED_LIBS=ON ^
-Dprotobuf_BUILD_CONFORMANCE=OFF ^
-Dprotobuf_WITH_ZLIB=OFF ^
-Dprotobuf_TEST_XML_OUTDIR=%KOKORO_ARTIFACTS_DIR%\logs\ || goto :error
cmake --build . || goto :error
ctest --verbose -C Debug || goto :error
goto :success
:error
cd /d %~dp0\..\..\..
echo Failed!
exit /b 1
:success
cd ..

@ -1,5 +1,5 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/windows/cmake/build.bat"
build_file: "protobuf/kokoro/windows/cmake_shared/build.bat"
timeout_mins: 1440

@ -1,5 +1,5 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/windows/cmake/build.bat"
build_file: "protobuf/kokoro/windows/cmake_shared/build.bat"
timeout_mins: 1440

@ -0,0 +1,16 @@
@rem Update Chocolatey
choco upgrade -y --no-progress chocolatey
choco install -y --no-progress --pre cmake
@rem Enable long paths.
Powershell.exe -Command "New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -Value 1 -PropertyType DWORD -Force"
@rem Update git submodules.
git submodule update --init --recursive
@rem Select Visual Studio 2017.
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
@rem Convert Windows line breaks to Unix line breaks
@rem This allows text-matching tests to pass
find . -type f -print0 | xargs -0 d2u

@ -195,7 +195,8 @@ cc_test(
"-Wno-deprecated-declarations",
],
}) + [
"-DGOOGLE_PROTOBUF_TEST_PLUGIN_PATH=\\\"src/google/protobuf/compiler/test_plugin\\\"",
# Note: This only works on Windows with symlinks and runfiles enabled.
"-DGOOGLE_PROTOBUF_TEST_PLUGIN_PATH=\\\"$(rootpath :test_plugin)\\\"",
],
data = [
":test_plugin",

@ -357,9 +357,9 @@ void CommandLineInterfaceTest::RunWithArgs(std::vector<std::string> args) {
}
#endif
if (plugin_path.empty()) {
if (plugin_path.empty() || !FileExists(plugin_path)) {
GOOGLE_LOG(ERROR)
<< "Plugin executable not found. Plugin tests are likely to fail.";
<< "Plugin tests are likely to fail. Plugin executable not found at: " << plugin_path;
} else {
args.push_back("--plugin=prefix-gen-plug=" + plugin_path);
}

@ -91,7 +91,9 @@ std::string GetOneofCaseName(const FieldDescriptor* descriptor);
int GetFixedSize(FieldDescriptor::Type type);
std::string UnderscoresToCamelCase(const std::string& input,
// Note that we wouldn't normally want to export this (we're not expecting
// it to be used outside libprotoc itself) but this exposes it for testing.
std::string PROTOC_EXPORT UnderscoresToCamelCase(const std::string& input,
bool cap_next_letter,
bool preserve_period);

@ -69,9 +69,12 @@ cc_test(
cc_test(
name = "message_differencer_unittest",
srcs = ["message_differencer_unittest.cc"],
copts = COPTS + [
"-Wno-deprecated-declarations",
],
copts = COPTS + select({
"//build_defs:config_msvc": [],
"//conditions:default": [
"-Wno-deprecated-declarations",
],
}),
deps = [
":differencer",
":message_differencer_unittest_cc_proto",

Loading…
Cancel
Save