Debian Codegraph @

tools/internal_ci/helper_scripts/move_src_tree_and_respawn_itself.bat

raw
1 @rem Copyright 2021 The 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 Call this script at the beginning of your CI script to move
16 @rem the entire source tree to a different directory.
17 @rem That avoids slow finalization (and a number of other problems)
18 @rem caused by kokoro rsyncing the entire /tmpfs/src directory
19 @rem back to the agent.
20 @rem Since batch scripts don't support the "source" unix command,
21 @rem invoking this script is a bit trickier than on unix.
22 @rem This script should be invoked from the CI script like this:
23 @rem Note that honoring the pattern (including e.g. EnableDelayedExpansion)
24 @rem is critical for correctly propagating the exitcode.
25 @rem TODO(jtattermusch): find a way to simplify the invocation of the respawn script.
26 @rem
27 @rem setlocal EnableDelayedExpansion
28 @rem IF "%cd%"=="T:\src" (
29 @rem call %~dp0\..\..\..\tools\internal_ci\helper_scripts\move_src_tree_and_respawn_itself.bat %0
30 @rem echo respawn script has finished with exitcode !errorlevel!
31 @rem exit /b !errorlevel!
32 @rem )
33 @rem endlocal
34
35
36 @echo off
37
38 @rem CI script path needs to be passed as arg1.
39 set CI_SCRIPT_RELATIVE_TO_SRC=%1
40
41 @rem Check that this script was invoked under correct circumstances.
42 IF NOT "%cd%"=="T:\src" (
43 @echo "Error: Current directory must be T:\src when invoking move_src_tree_and_respawn_itself.bat"
44 exit /b 1
45 )
46
47 @rem T:\ is equivalent to /tmpfs on kokoro linux.
48 echo "Moving workspace from T:\src to T:\altsrc and respawning the CI script."
49 cd /d T:\
50 @rem We cannot simply rename "src" to "altsrc" as on linux since the currently running batch file is in it
51 @rem and windows holds a lock that prevents moving the dir.
52 bash -c "set -ex; mkdir -p altsrc; time cp -r src/github altsrc;"
53 @rem Delete files we can under the original "src/github" directory, skipping the directory that contains CI scripts
54 @rem (as on of the scripts is currently running and cannot be deleted)
55 @rem We don't want to delete files in "src" outside of "src/github" since they contain e.g kokoro input artifacts.
56 bash -c "set -ex; cd src/github; time find . -type f -not -path './grpc/tools/internal_ci/*' -exec rm -f {} +; ls grpc"
57 cd altsrc
58
59 @rem scripts in tools/run_tests generate test reports and we need to make sure these reports
60 @rem land in a directory that is going to be rsynced back to the kokoro agent.
61 set GRPC_TEST_REPORT_BASE_DIR=T:\src\github\grpc
62
63 echo "Invoking original CI script now."
64 @echo on
65 call "%CI_SCRIPT_RELATIVE_TO_SRC%"
66 exit /b %errorlevel%