1@rem Copyright 2017 gRPC authors.
2@rem
3@rem Licensed under the Apache License, Version 2.0 (the "License");
4@rem you may not use this file except in compliance with the License.
5@rem You may obtain a copy of the License at
6@rem
7@rem     http://www.apache.org/licenses/LICENSE-2.0
8@rem
9@rem Unless required by applicable law or agreed to in writing, software
10@rem distributed under the License is distributed on an "AS IS" BASIS,
11@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12@rem See the License for the specific language governing permissions and
13@rem limitations under the License.
14
15@rem allow timing of how long the script takes to run.
16echo "!TIME!: prepare_build_windows.bat started"
17
18@rem make sure msys binaries are preferred over cygwin binaries
19@rem set path to python3.7
20@rem set path to CMake
21set PATH=C:\tools\msys64\usr\bin;C:\Python37;C:\Program Files\CMake\bin;%PATH%
22
23@rem Print image ID of the windows kokoro image being used.
24cat C:\image_id.txt
25
26@rem create "python3" link that normally doesn't exist
27dir C:\Python37\
28mklink C:\Python37\python3.exe C:\Python37\python.exe
29
30python --version
31python3 --version
32
33@rem If this is a PR using RUN_TESTS_FLAGS var, then add flags to filter tests
34if defined KOKORO_GITHUB_PULL_REQUEST_NUMBER if defined RUN_TESTS_FLAGS (
35  set RUN_TESTS_FLAGS=%RUN_TESTS_FLAGS% --filter_pr_tests --base_branch origin/%KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH%
36)
37
38@rem Update DNS settings to:
39@rem 1. allow resolving metadata.google.internal hostname
40@rem 2. make fetching default GCE credential by oauth2client work
41netsh interface ip set dns "Local Area Connection 8" static 169.254.169.254 primary
42netsh interface ip add dnsservers "Local Area Connection 8" 8.8.8.8 index=2
43netsh interface ip add dnsservers "Local Area Connection 8" 8.8.4.4 index=3
44
45@rem Uninstall protoc so that it doesn't clash with C++ distribtests.
46@rem (on grpc-win2016 kokoro workers it can result in GOOGLE_PROTOBUF_MIN_PROTOC_VERSION violation)
47choco uninstall protoc -y --limit-output
48
49@rem Install nasm (required for boringssl assembly optimized build as boringssl no long supports yasm)
50@rem Downloading from GCS should be very reliables when on a GCP VM.
51mkdir C:\nasm
52curl -sSL --fail -o C:\nasm\nasm.exe https://storage.googleapis.com/grpc-build-helper/nasm-2.15.05/nasm.exe || goto :error
53set PATH=C:\nasm;%PATH%
54nasm
55
56@rem Install ccache
57mkdir C:\ccache
58curl -sSL --fail -o C:\ccache\ccache.exe https://storage.googleapis.com/grpc-build-helper/ccache-4.8-windows-64/ccache.exe || goto :error
59set PATH=C:\ccache;%PATH%
60ccache --version
61
62@rem Only install C# dependencies if we are running C# tests
63If "%PREPARE_BUILD_INSTALL_DEPS_CSHARP%" == "true" (
64  @rem C# prerequisites: Install dotnet SDK
65  powershell -File src\csharp\install_dotnet_sdk.ps1 || goto :error
66
67  @rem Explicitly add default nuget source.
68  @rem (on Kokoro grpc-win2016 workers, the default nuget source is not configured,
69  @rem which results in errors when "dotnet restore" is run)
70  %LOCALAPPDATA%\Microsoft\dotnet\dotnet nuget add source https://api.nuget.org/v3/index.json -n "nuget.org"
71)
72
73@rem Add dotnet on path and disable some unwanted dotnet
74@rem option regardless of PREPARE_BUILD_INSTALL_DEPS_CSHARP value.
75@rem Always setting the env vars is fine since its instantaneous,
76@rem it can't fail and it avoids possible issues with
77@rem "setlocal" and "EnableDelayedExpansion" which would be required if
78@rem we wanted to do the same under the IF block.
79set PATH=%LOCALAPPDATA%\Microsoft\dotnet;%PATH%
80set NUGET_XMLDOC_MODE=skip
81set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
82set DOTNET_CLI_TELEMETRY_OPTOUT=true
83
84@rem Workaround https://github.com/NuGet/Home/issues/11099 that exhibits
85@rem on windows workers as "The repository primary signature's timestamping certificate is not trusted by the trust provider"
86set NUGET_EXPERIMENTAL_CHAIN_BUILD_RETRY_POLICY=3,1000
87
88@rem Only install Python interpreters if we are running Python tests
89If "%PREPARE_BUILD_INSTALL_DEPS_PYTHON%" == "true" (
90  echo "!TIME!: invoking install_python_interpreters.ps1"
91  powershell -File tools\internal_ci\helper_scripts\install_python_interpreters.ps1 || goto :error
92)
93
94@rem Needed for uploading test results to bigquery
95python -m pip install google-api-python-client oauth2client six==1.16.0 || goto :error
96
97git submodule update --init || goto :error
98
99echo "!TIME!: prepare_build_windows.bat exiting with success"
100goto :EOF
101
102:error
103echo "!TIME!: prepare_build_windows.bat exiting with error"
104exit /b 1
105