forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.sh
executable file
·127 lines (113 loc) · 3.54 KB
/
clean.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
usage()
{
echo "Usage: clean [options]"
echo "Cleans the local dev environment."
echo
echo " -b Delete the binary output directory"
echo " -p Delete the repo-local NuGet package directory"
echo " -c Delete the user-local NuGet package caches"
echo " -t Delete the tools directory"
echo " -s Remove all untracked files under the src directory"
echo " -a, --all Clean all of the above"
echo
echo "If no option is specified, then \"clean.sh -b\" is implied."
exit 1
}
check_exit_status()
{
ExitStatus=$?
if [ $ExitStatus -ne 0 ]
then
echo "Command exited with exit status $ExitStatus" >> $CleanLog
CleanSuccessful=false
fi
}
WorkingTreeRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CleanLog=$WorkingTreeRoot/clean.log
CleanSuccessful=true
CleanTargets=
# Parse arguments
echo "Running clean.sh $*" > $CleanLog
if [ $# == 0 ]
then
CleanTargets="Clean;"
fi
while [[ $# > 0 ]]
do
opt="$1"
case $opt in
-h|--help)
usage
;;
-b)
CleanTargets="Clean;$CleanTargets"
;;
-p)
CleanTargets="CleanPackages;$CleanTargets"
;;
-c)
CleanTargets="CleanPackagesCache;$CleanTargets"
;;
-t)
CleanToolsDir=true
;;
-s)
CleanSrc=true
;;
-a|--all)
CleanWorkingTree=true
CleanTargets="Clean;CleanPackages;CleanPackagesCache;"
;;
*)
echo "Unrecognized argument '$opt'"
echo "Use 'clean -h' for help."
exit 1
;;
esac
shift
done
if [ -n "$CleanTargets" ]
then
# Ensure that MSBuild is available
echo "Running init-tools.sh"
$WorkingTreeRoot/init-tools.sh
# Trim the trailing semicolon from the targets string
CleanTargetsTrimmed=${CleanTargets:0:${#CleanTargets}-1}
echo "Running MSBuild target(s): $CleanTargetsTrimmed"
echo -e "\n$WorkingTreeRoot/Tools/corerun $WorkingTreeRoot/Tools/MSBuild.exe $WorkingTreeRoot/build.proj /t:$CleanTargetsTrimmed /nologo /verbosity:minimal /flp:v=detailed;Append;LogFile=$CleanLog" >> $CleanLog
$WorkingTreeRoot/Tools/corerun $WorkingTreeRoot/Tools/MSBuild.exe $WorkingTreeRoot/build.proj /t:$CleanTargetsTrimmed /nologo /verbosity:minimal "/flp:v=detailed;Append;LogFile=$CleanLog"
check_exit_status
fi
if [ "$CleanToolsDir" == true ] && [ "$CleanWorkingTree" != true ]
then
echo "Removing Tools directory"
# This directory cannot be removed in a build target because MSBuild is in the Tools directory
echo -e "\nrm -rf $WorkingTreeRoot/Tools" >> $CleanLog
rm -rf $WorkingTreeRoot/Tools >> $CleanLog
check_exit_status
fi
if [ "$CleanSrc" == true ] && [ "$CleanWorkingTree" != true ]
then
echo "Removing all untracked files in the src directory"
echo -e "\ngit clean -xdf $WorkingTreeRoot/src" >> $CleanLog
git clean -xdf $WorkingTreeRoot/src >> $CleanLog
check_exit_status
fi
if [ "$CleanWorkingTree" == true ]
then
echo "Removing all untracked files in the working tree"
echo -e "\ngit clean -xdf -e clean.log $WorkingTreeRoot" >> $CleanLog
git clean -xdf -e clean.log $WorkingTreeRoot >> $CleanLog
check_exit_status
fi
if [ "$CleanSuccessful" == true ]
then
echo "Clean completed successfully."
echo -e "\nClean completed successfully." >> $CleanLog
exit 0
else
echo "An error occured while cleaning; see $CleanLog for more details."
echo -e "\nClean completed with errors." >> $CleanLog
exit 1
fi