84d897eb11998c7c52801401490bf484b154f185
[platform/upstream/coreclr.git] / clean.cmd
1 @if not defined _echo @echo off
2 setlocal EnableDelayedExpansion
3
4 echo Running clean.cmd
5
6 set bin=false
7 set packages=false
8 set tools = false
9
10 if [%1]==[] (
11   set bin=true
12   set packages=true
13   set tools=true
14   set all=false
15   goto Begin
16 )
17
18 :Loop
19 if [%1]==[] goto Begin
20
21 if /I [%1] == [-?] goto Usage
22 if /I [%1] == [-help] goto Usage
23
24 if /I [%1] == [-p] (
25     set packages=true
26     set thisArgs=!thisArgs!%1
27     goto Next
28 )
29
30 if /I [%1] == [-b] (
31     set bin=true
32     set thisArgs=!thisArgs!%1
33     goto Next
34 )
35
36 if /I [%1] == [-t] (
37     set tools=true
38     set thisArgs=!thisArgs!%1
39     goto Next
40 )
41
42 if /I [%1] == [-all] (
43     set tools=true
44     set bin=true
45     set packages=true
46         set all=true
47     goto Begin
48 )
49
50 :Next
51 shift /1
52 goto Loop
53
54 :Begin
55 :: Set __ProjectDir to be the directory of this script
56 set "__ProjectDir=%~dp0"
57 :: remove trailing slash
58 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
59 set "__RootBinDir=%__ProjectDir%\bin"
60
61 :: Check if VBCSCompiler.exe is running and stop it
62 tasklist /fi "imagename eq VBCSCompiler.exe" |find ":" > nul
63 if errorlevel 1 (
64         echo Stop VBCSCompiler.exe execution.
65         for /f "tokens=2 delims=," %%F in ('tasklist /nh /fi "imagename eq VBCSCompiler.exe" /fo csv') do taskkill /f /PID %%~F
66 )
67
68 if [%bin%] == [true] (
69         if exist "%__RootBinDir%" (
70                 echo Deleting bin directory
71                 rd /s /q "%__RootBinDir%"
72                 if NOT [!ERRORLEVEL!]==[0] (
73                         echo ERROR: An error occurred while deleting the bin directory - error code is !ERRORLEVEL!
74                         exit /b 1
75                 )
76         )
77 )
78
79 if [%tools%] == [true] (
80         if exist "%__ProjectDir%\Tools" (
81                 echo Deleting tools directory
82                 rd /s /q "%__ProjectDir%\Tools"
83                 if NOT [!ERRORLEVEL!]==[0] (
84                         echo ERROR: An error occurred while deleting the Tools directory - error code is !ERRORLEVEL!
85                         exit /b 1
86                 )
87         )
88 )
89
90 if [%packages%] == [true] (
91         if exist "%__ProjectDir%\packages" (
92                 echo Deleting packages directory
93                 rd /s /q "%__ProjectDir%\packages"
94                 if NOT [!ERRORLEVEL!]==[0] (
95                         echo ERROR: An error occurred while deleting the packages directory - error code is !ERRORLEVEL!
96                         exit /b 1
97                 )
98         )
99 )
100
101 if [%all%] == [true] (
102   echo Cleaning entire working directory ...
103   call git clean -xdf
104   exit /b !ERRORLEVEL!
105 )
106
107 echo Clean was successful
108 exit /b 0
109
110 :Usage
111 echo.
112 echo Repository cleaning script.
113 echo Options:
114 echo     -b     - Cleans the bin directory
115 echo     -p     - Cleans the packages directory
116 echo     -t     - Cleans the tools directory
117 echo     -all   - Cleans everything and restores repository to pristine state
118 echo.
119 echo If no option is specified then clean.cmd -b -p -t is implied.
120 exit /b