Skip to content

Commit

Permalink
Refactor clean.cmd based on corefx implementation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
4creators committed Nov 8, 2017
1 parent 37a0e34 commit 8110e41
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 95 deletions.
7 changes: 7 additions & 0 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

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

<Import Project="$(ToolsDir)clean.targets" />

<!-- The following properties are in place to keep the behavior of build.cmd while we work on the dev workflow steps. -->
<PropertyGroup>
<!-- To disable the restoration of packages, set RestoreDuringBuild=false or pass /p:RestoreDuringBuild=false.-->
Expand Down Expand Up @@ -45,5 +47,10 @@
<Exec Command="$(DotnetRestoreCommand) $(SourceDir).nuget/init/init.csproj"
StandardOutputImportance="Low" />
</Target>

<Target Name="CleanAllProjects">
<Message Condition="Exists($(RootBinDir))" Importance="High" Text="Removing $(RootBinDir)"/>
<RemoveDir Directories="$(RootBinDir)" />
</Target>

</Project>
109 changes: 14 additions & 95 deletions clean.cmd
Original file line number Diff line number Diff line change
@@ -1,120 +1,39 @@
@if not defined _echo @echo off
setlocal EnableDelayedExpansion

echo Running clean.cmd

set bin=false
set packages=false
set tools = false

if [%1]==[] (
set bin=true
set packages=true
set tools=true
set all=false
goto Begin
)

:Loop
if [%1]==[] goto Begin

if /I [%1] == [-?] goto Usage
if /I [%1] == [-help] goto Usage

if /I [%1] == [-p] (
set packages=true
set thisArgs=!thisArgs!%1
goto Next
)

if /I [%1] == [-b] (
set bin=true
set thisArgs=!thisArgs!%1
goto Next
)

if /I [%1] == [-t] (
set tools=true
set thisArgs=!thisArgs!%1
goto Next
)

if /I [%1] == [-all] (
set tools=true
set bin=true
set packages=true
set all=true
goto Begin
)

:Next
shift /1
goto Loop

:Begin
:: Set __ProjectDir to be the directory of this script
set "__ProjectDir=%~dp0"
:: remove trailing slash
if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
set "__RootBinDir=%__ProjectDir%\bin"

:: Check if VBCSCompiler.exe is running and stop it
:: Check if VBCSCompiler.exe is running
tasklist /fi "imagename eq VBCSCompiler.exe" |find ":" > nul
:: Compiler is running if errorlevel == 1
if errorlevel 1 (
echo Stop VBCSCompiler.exe execution.
for /f "tokens=2 delims=," %%F in ('tasklist /nh /fi "imagename eq VBCSCompiler.exe" /fo csv') do taskkill /f /PID %%~F
)

if [%bin%] == [true] (
if exist "%__RootBinDir%" (
echo Deleting bin directory
rd /s /q "%__RootBinDir%"
if NOT [!ERRORLEVEL!]==[0] (
echo ERROR: An error occurred while deleting the bin directory - error code is !ERRORLEVEL!
exit /b 1
)
)
)

if [%tools%] == [true] (
if exist "%__ProjectDir%\Tools" (
echo Deleting tools directory
rd /s /q "%__ProjectDir%\Tools"
if NOT [!ERRORLEVEL!]==[0] (
echo ERROR: An error occurred while deleting the Tools directory - error code is !ERRORLEVEL!
exit /b 1
)
)
)

if [%packages%] == [true] (
if exist "%__ProjectDir%\packages" (
echo Deleting packages directory
rd /s /q "%__ProjectDir%\packages"
if NOT [!ERRORLEVEL!]==[0] (
echo ERROR: An error occurred while deleting the packages directory - error code is !ERRORLEVEL!
exit /b 1
)
)
)

if [%all%] == [true] (
:: Strip all dashes off the argument and use invariant
:: compare to match as many versions of "all" that we can
:: All other argument validation happens inside Run.exe
set NO_DASHES_ARG=%1
if not defined NO_DASHES_ARG goto no_args
if /I [%NO_DASHES_ARG:-=%] == [all] (
echo Cleaning entire working directory ...
call git clean -xdf
exit /b !ERRORLEVEL!
)

echo Clean was successful
exit /b 0
:no_args
if [%1]==[] set __args=-b
call %~dp0run.cmd clean %__args% %*
exit /b %ERRORLEVEL%

:Usage
echo.
echo Repository cleaning script.
echo Options:
echo -b - Cleans the bin directory
echo -p - Cleans the packages directory
echo -t - Cleans the tools directory
echo -c - Deletes the user-local nuget package cache.
echo -all - Cleans everything and restores repository to pristine state
echo.
echo If no option is specified then clean.cmd -b -p -t is implied.
echo If no option is specified then clean.cmd -b is implied.
exit /b
46 changes: 46 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@
"values": [],
"defaultValue": ""
},
"CleanAllProjects": {
"description": "MsBuild target that deletes the binary output directory.",
"valueType": "target",
"values": [],
"defaultValue": ""
},
"CleanPackages": {
"description": "MsBuild target that deletes the repo-local nuget package directory.",
"valueType": "target",
"values": [],
"defaultValue": ""
},
"CleanPackagesCache": {
"description": "MsBuild target that deletes the user-local nuget package cache.",
"valueType": "target",
"values": [],
"defaultValue": ""
},
"ContainerName": {
"description": "Container name for Azure upload.",
"valueType": "property",
Expand Down Expand Up @@ -519,6 +537,34 @@
}
}
},
"clean": {
"alias": {
"b": {
"description": "Deletes the binary output directory.",
"settings": {
"CleanAllProjects": "default"
}
},
"p": {
"description": "Deletes the repo-local nuget package directory.",
"settings": {
"CleanPackages": "default"
}
},
"c": {
"description": "Deletes the user-local nuget package cache.",
"settings": {
"CleanPackagesCache": "default"
}
}
},
"defaultValues": {
"toolName": "msbuild",
"settings": {
"MsBuildLog":"/flp:v=normal;LogFile=clean.log"
}
}
},
"sync": {
"alias": {
"p": {
Expand Down

0 comments on commit 8110e41

Please sign in to comment.