2
2
3
3
# ## Usage: $0
4
4
# ##
5
- # ## Prepares the environment for a source build by downloading Private.SourceBuilt.Artifacts.*.tar.gz and
6
- # ## installing the version of dotnet referenced in global.json
5
+ # ## Prepares the environment for a source build by downloading Private.SourceBuilt.Artifacts.*.tar.gz,
6
+ # ## installing the version of dotnet referenced in global.json,
7
+ # ## and detecting binaries and removing any non-SB allowed binaries.
7
8
# ##
8
9
# ## Options:
9
10
# ## --no-artifacts Exclude the download of the previously source-built artifacts archive
15
16
# ## --runtime-source-feed URL of a remote server or a local directory, from which SDKs and
16
17
# ## runtimes can be downloaded
17
18
# ## --runtime-source-feed-key Key for accessing the above server, if necessary
19
+ # ##
20
+ # ## Binary-Tooling options:
21
+ # ## --no-binary-tooling Don't run the binary tooling
22
+ # ## --allowed-binaries Path to the file containing the list of known binaries that are allowed
23
+ # ## in the VMR and can be kept for source-building.
24
+ # ## Default is src/installer/src/VirtualMonoRepo/allowed-binaries.txt
25
+ # ## --disallowed-sb-binaries Path to the file containing the list of known binaries that are allowed
26
+ # ## in the VMR but cannot be kept for source-building.
27
+ # ## Default is null.
28
+ # ## --with-sdk Use the SDK in the specified directory
29
+ # ## Default is the .NET SDK
30
+ # ## --with-packages URL or specified directory to use as the source feed for packages
31
+ # ## Default is the previously source-built artifacts archive
32
+ # ## --no-validate Do not run validation. Only remove the binaries.
33
+ # ## --no-clean Do not remove the binaries. Only run the validation.
18
34
19
35
set -euo pipefail
20
36
IFS=$' \n\t '
@@ -26,15 +42,32 @@ function print_help () {
26
42
sed -n ' /^### /,/^$/p' " $source " | cut -b 5-
27
43
}
28
44
45
+ # SB prep default arguments
29
46
defaultArtifactsRid=' centos.8-x64'
30
47
48
+ # Binary Tooling default arguments
49
+ defaultAllowedBinaries=" $REPO_ROOT /src/installer/src/VirtualMonoRepo/allowed-binaries.txt"
50
+ defaultDotnetSdk=" $REPO_ROOT /.dotnet"
51
+ defaultPackagesDir=" $REPO_ROOT /prereqs/packages"
52
+ defaultMode=" All"
53
+
54
+ # SB prep arguments
31
55
buildBootstrap=true
32
56
downloadArtifacts=true
33
57
downloadPrebuilts=true
34
58
installDotnet=true
35
59
artifactsRid=$defaultArtifactsRid
36
60
runtime_source_feed=' ' # IBM requested these to support s390x scenarios
37
61
runtime_source_feed_key=' ' # IBM requested these to support s390x scenarios
62
+
63
+ # Binary Tooling arguments
64
+ runBinaryTool=true
65
+ allowedBinaries=$defaultAllowedBinaries
66
+ disallowedSbBinaries=' '
67
+ dotnetSdk=$defaultDotnetSdk
68
+ packagesSourceFeed=$defaultPackagesDir
69
+ mode=$defaultMode
70
+
38
71
positional_args=()
39
72
while : ; do
40
73
if [ $# -le 0 ]; then
@@ -69,6 +102,47 @@ while :; do
69
102
runtime_source_feed_key=$2
70
103
shift
71
104
;;
105
+ --no-binary-tooling)
106
+ runBinaryTool=false
107
+ ;;
108
+ --allowed-binaries)
109
+ allowedBinaries=$2
110
+ if [ ! -f " $allowedBinaries " ]; then
111
+ echo " Allowed binaries file '$allowedBinaries ' does not exist"
112
+ exit 1
113
+ fi
114
+ shift
115
+ ;;
116
+ --disallowed-sb-binaries)
117
+ disallowedSbBinaries=$2
118
+ if [ ! -f " $disallowedSbBinaries " ]; then
119
+ echo " Disallowed source build binaries file '$disallowedSbBinaries ' does not exist"
120
+ exit 1
121
+ fi
122
+ shift
123
+ ;;
124
+ --with-sdk)
125
+ dotnetSdk=$2
126
+ if [ ! -d " $dotnetSdk " ]; then
127
+ echo " Custom SDK directory '$dotnetSdk ' does not exist"
128
+ exit 1
129
+ fi
130
+ if [ ! -x " $dotnetSdk /dotnet" ]; then
131
+ echo " Custom SDK '$dotnetSdk /dotnet' does not exist or is not executable"
132
+ exit 1
133
+ fi
134
+ shift
135
+ ;;
136
+ --with-packages)
137
+ packagesSourceFeed=$2
138
+ shift
139
+ ;;
140
+ --no-clean)
141
+ mode=" Validate"
142
+ ;;
143
+ --no-validate)
144
+ mode=" Clean"
145
+ ;;
72
146
* )
73
147
positional_args+=(" $1 " )
74
148
;;
@@ -112,6 +186,56 @@ if [ "$installDotnet" == true ] && [ -d "$REPO_ROOT/.dotnet" ]; then
112
186
installDotnet=false;
113
187
fi
114
188
189
+ function ParseBinaryArgs {
190
+ # Attempting to run the binary tooling without an SDK will fail. So either the --with-sdk flag must be passed
191
+ # or a pre-existing .dotnet SDK directory must exist.
192
+ if [ " $dotnetSdk " == " $defaultDotnetSdk " ] && [ ! -d " $dotnetSdk " ]; then
193
+ echo " ERROR: A pre-existing .dotnet SDK directory is needed if --with-sdk is not provided. \
194
+ Please either supply an SDK using --with-sdk or execute ./eng/prep-source-build.sh before proceeding. Exiting..."
195
+ exit 1
196
+ fi
197
+
198
+ # # Attemping to run the binary tooling without a packages directory or source-feed will fail. So either the
199
+ # # --with-packages flag must be passed with a valid directory or a pre-existing packages directory must exist.
200
+ if [ " $packagesSourceFeed " == " $defaultPackagesDir " ] && [ ! -d " $packagesSourceFeed " ]; then
201
+ echo " ERROR: A pre-existing packages directory is needed if --with-packages is not provided. \
202
+ Please either supply a packages directory using --with-packages or \
203
+ execute ./eng/prep-source-build.sh with download artifacts enabled before proceeding. Exiting..."
204
+ exit 1
205
+ fi
206
+
207
+ # Attempting to run the binary tooling with a custom packages feed that does not
208
+ # have PackageVersions.props in the packages directory or source-feed will fail.
209
+ if [ " $packagesSourceFeed " != " $defaultPackagesDir " ] && [ ! -f " $packagesSourceFeed /PackageVersions.props" ]; then
210
+ echo " ERROR: PackageVersions.props is needed in the packages directory or source-feed. Exiting..."
211
+ exit 1
212
+ fi
213
+
214
+ # Set up the packages source feed if we're using the default artifacts
215
+ previouslyBuiltPackagesDir=" $defaultPackagesDir /previously-source-built"
216
+ packageArtifacts=" $defaultPackagesDir /archive/Private.SourceBuilt.Artifacts.*.tar.gz"
217
+ if [ " $packagesSourceFeed " == " $defaultPackagesDir " ]; then
218
+ if [ -d " $previouslyBuiltPackagesDir " ]; then
219
+ echo " Previously source built packages directory exists..."
220
+ echo " Using $previouslyBuiltPackagesDir as the source-feed for the binary tooling..."
221
+ packagesSourceFeed=" $previouslyBuiltPackagesDir "
222
+ elif [ -f ${packageArtifacts} ]; then
223
+ echo " Unpacking Private.SourceBuilt.Artifacts.*.tar.gz to $previouslyBuiltPackagesDir ..."
224
+ mkdir -p " $previouslyBuiltPackagesDir "
225
+ tar -xzf ${packageArtifacts} -C " $previouslyBuiltPackagesDir "
226
+ tar -xzf ${packageArtifacts} -C " $previouslyBuiltPackagesDir " PackageVersions.props
227
+
228
+ echo " Using $previouslyBuiltPackagesDir as the source-feed for the binary tooling..."
229
+ packagesSourceFeed=" $previouslyBuiltPackagesDir "
230
+ else
231
+ echo " ERROR: A pre-existing package archive is needed if --with-packages is not provided. \
232
+ Please either supply a source-feed using --with-packages or execute ./eng/prep-source-build.sh \
233
+ with download artifacts enabled before proceeding. Exiting..."
234
+ exit 1
235
+ fi
236
+ fi
237
+ }
238
+
115
239
function DownloadArchive {
116
240
archiveType=" $1 "
117
241
isRequired=" $2 "
@@ -171,6 +295,18 @@ function BootstrapArtifacts {
171
295
rm -rf " $workingDir "
172
296
}
173
297
298
+ function RunBinaryTool {
299
+ BinaryTool=" $REPO_ROOT /eng/tools/BinaryToolKit"
300
+ TargetDir=" $REPO_ROOT "
301
+ OutputDir=" $REPO_ROOT /artifacts/log/binary-report"
302
+
303
+ # Set the environment variable for the packages source feed
304
+ export ARTIFACTS_PATH=" $packagesSourceFeed "
305
+
306
+ # Run the BinaryDetection tool
307
+ " $dotnetSdk /dotnet" run --project " $BinaryTool " -c Release -p PackagesPropsDirectory=" $packagesSourceFeed " " $TargetDir " " $OutputDir " -ab " $allowedBinaries " -db " $disallowedSbBinaries " -m $mode -l Debug
308
+ }
309
+
174
310
# Check for the version of dotnet to install
175
311
if [ " $installDotnet " == true ]; then
176
312
echo " Installing dotnet..."
189
325
if [ " $downloadPrebuilts " == true ]; then
190
326
DownloadArchive Prebuilts false $artifactsRid
191
327
fi
328
+
329
+ if [ " $runBinaryTool " == true ]; then
330
+ ParseBinaryArgs
331
+ RunBinaryTool
332
+ fi
0 commit comments