Skip to content

Commit 8110e41

Browse files
committed
Refactor clean.cmd based on corefx implementation
clean.cmd supports removal of bin dir, repo-local nuget packeges directory and user-local nuget packages directory. In addition it is possible to clean repo using git clean -xdf command by passing -all command line switch to clean.cmd. In addition logic supporting killing of VBCScompiler.exe process is added
1 parent 37a0e34 commit 8110e41

File tree

3 files changed

+67
-95
lines changed

3 files changed

+67
-95
lines changed

build.proj

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
<Import Project="dir.traversal.targets" />
1313

14+
<Import Project="$(ToolsDir)clean.targets" />
15+
1416
<!-- The following properties are in place to keep the behavior of build.cmd while we work on the dev workflow steps. -->
1517
<PropertyGroup>
1618
<!-- To disable the restoration of packages, set RestoreDuringBuild=false or pass /p:RestoreDuringBuild=false.-->
@@ -45,5 +47,10 @@
4547
<Exec Command="$(DotnetRestoreCommand) $(SourceDir).nuget/init/init.csproj"
4648
StandardOutputImportance="Low" />
4749
</Target>
50+
51+
<Target Name="CleanAllProjects">
52+
<Message Condition="Exists($(RootBinDir))" Importance="High" Text="Removing $(RootBinDir)"/>
53+
<RemoveDir Directories="$(RootBinDir)" />
54+
</Target>
4855

4956
</Project>

clean.cmd

+14-95
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,39 @@
11
@if not defined _echo @echo off
22
setlocal EnableDelayedExpansion
33

4-
echo Running clean.cmd
54

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
5+
:: Check if VBCSCompiler.exe is running
626
tasklist /fi "imagename eq VBCSCompiler.exe" |find ":" > nul
7+
:: Compiler is running if errorlevel == 1
638
if errorlevel 1 (
649
echo Stop VBCSCompiler.exe execution.
6510
for /f "tokens=2 delims=," %%F in ('tasklist /nh /fi "imagename eq VBCSCompiler.exe" /fo csv') do taskkill /f /PID %%~F
6611
)
6712

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] (
13+
:: Strip all dashes off the argument and use invariant
14+
:: compare to match as many versions of "all" that we can
15+
:: All other argument validation happens inside Run.exe
16+
set NO_DASHES_ARG=%1
17+
if not defined NO_DASHES_ARG goto no_args
18+
if /I [%NO_DASHES_ARG:-=%] == [all] (
10219
echo Cleaning entire working directory ...
10320
call git clean -xdf
10421
exit /b !ERRORLEVEL!
10522
)
10623

107-
echo Clean was successful
108-
exit /b 0
24+
:no_args
25+
if [%1]==[] set __args=-b
26+
call %~dp0run.cmd clean %__args% %*
27+
exit /b %ERRORLEVEL%
10928

11029
:Usage
11130
echo.
11231
echo Repository cleaning script.
11332
echo Options:
11433
echo -b - Cleans the bin directory
11534
echo -p - Cleans the packages directory
116-
echo -t - Cleans the tools directory
35+
echo -c - Deletes the user-local nuget package cache.
11736
echo -all - Cleans everything and restores repository to pristine state
11837
echo.
119-
echo If no option is specified then clean.cmd -b -p -t is implied.
38+
echo If no option is specified then clean.cmd -b is implied.
12039
exit /b

config.json

+46
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@
3636
"values": [],
3737
"defaultValue": ""
3838
},
39+
"CleanAllProjects": {
40+
"description": "MsBuild target that deletes the binary output directory.",
41+
"valueType": "target",
42+
"values": [],
43+
"defaultValue": ""
44+
},
45+
"CleanPackages": {
46+
"description": "MsBuild target that deletes the repo-local nuget package directory.",
47+
"valueType": "target",
48+
"values": [],
49+
"defaultValue": ""
50+
},
51+
"CleanPackagesCache": {
52+
"description": "MsBuild target that deletes the user-local nuget package cache.",
53+
"valueType": "target",
54+
"values": [],
55+
"defaultValue": ""
56+
},
3957
"ContainerName": {
4058
"description": "Container name for Azure upload.",
4159
"valueType": "property",
@@ -519,6 +537,34 @@
519537
}
520538
}
521539
},
540+
"clean": {
541+
"alias": {
542+
"b": {
543+
"description": "Deletes the binary output directory.",
544+
"settings": {
545+
"CleanAllProjects": "default"
546+
}
547+
},
548+
"p": {
549+
"description": "Deletes the repo-local nuget package directory.",
550+
"settings": {
551+
"CleanPackages": "default"
552+
}
553+
},
554+
"c": {
555+
"description": "Deletes the user-local nuget package cache.",
556+
"settings": {
557+
"CleanPackagesCache": "default"
558+
}
559+
}
560+
},
561+
"defaultValues": {
562+
"toolName": "msbuild",
563+
"settings": {
564+
"MsBuildLog":"/flp:v=normal;LogFile=clean.log"
565+
}
566+
}
567+
},
522568
"sync": {
523569
"alias": {
524570
"p": {

0 commit comments

Comments
 (0)