Skip to content

Commit 487b3e8

Browse files
committed
Use --with-packages and PackageVersions.props
1 parent a914737 commit 487b3e8

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

src/SourceBuild/content/eng/prep-source-build.sh

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
###
55
### Prepares the environment for a source build by downloading Private.SourceBuilt.Artifacts.*.tar.gz,
66
### installing the version of dotnet referenced in global.json,
7-
### and detecting new binaries and removing any non-SB allowed binaries.
7+
### and detecting binaries and removing any non-SB allowed binaries.
88
###
99
### Options:
1010
### --no-artifacts Exclude the download of the previously source-built artifacts archive
@@ -27,7 +27,7 @@
2727
### Default is null.
2828
### --with-sdk Use the SDK in the specified directory
2929
### Default is the .NET SDK
30-
### --packages-source-feed URL or specified directory as the source feed for packages
30+
### --with-packages URL or specified directory to use as the source feed for packages
3131
### Default is the previously source-built artifacts archive
3232
### --no-validate Do not run validation. Only remove the binaries.
3333
### --no-clean Do not remove the binaries. Only run the validation.
@@ -133,7 +133,7 @@ while :; do
133133
fi
134134
shift
135135
;;
136-
--packages-source-feed)
136+
--with-packages)
137137
packagesSourceFeed=$2
138138
shift
139139
;;
@@ -195,15 +195,22 @@ function ParseBinaryArgs {
195195
exit 1
196196
fi
197197

198-
## Attemping to run the binary tooling without a packages directory or source-feed will fail.
199-
## So either the --with-packages flag must be passed with a valid directory or the source feed must be set using --packages-source-feed
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.
200200
if [ "$packagesSourceFeed" == "$defaultPackagesDir" ] && [ ! -d "$packagesSourceFeed" ]; then
201-
echo " ERROR: A pre-existing packages directory is needed if --packages-source-feed is not provided. \
201+
echo " ERROR: A pre-existing packages directory is needed if --with-packages is not provided. \
202202
Please either supply a packages directory using --with-packages or \
203203
execute ./prep.sh with download artifacts enabled before proceeding. Exiting..."
204204
exit 1
205205
fi
206206

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+
207214
# Unpack the previously built packages if the previously built packages directory is empty and
208215
# if we're using the default artifacts
209216
previouslyBuiltPackagesDir="$defaultPackagesDir/previously-source-built"
@@ -213,10 +220,12 @@ function ParseBinaryArgs {
213220
echo "Unpacking previously built artifacts from ${packageArtifacts} to $previouslyBuiltPackagesDir"
214221
mkdir -p "$previouslyBuiltPackagesDir"
215222
tar -xzf ${packageArtifacts} -C "$previouslyBuiltPackagesDir"
223+
tar -xzf ${packageArtifacts} -C "$previouslyBuiltPackagesDir" PackageVersions.props
224+
packagesSourceFeed="$previouslyBuiltPackagesDir"
216225
else
217-
echo " ERROR: A pre-existing package archive is needed if --packages-source-feed is not provided. \
218-
Please either supply a source-feed using --packages-source-feed or \
219-
execute ./prep.sh with with download artifacts enabled before proceeding. Exiting..."
226+
echo " ERROR: A pre-existing package archive is needed if --with-packages is not provided. \
227+
Please either supply a source-feed using --with-packages or execute ./prep.sh with \
228+
download artifacts enabled before proceeding. Exiting..."
220229
exit 1
221230
fi
222231
fi
@@ -289,11 +298,8 @@ function RunBinaryTool {
289298
# Set the environment variable for the packages source feed
290299
export ARTIFACTS_PATH="$packagesSourceFeed"
291300

292-
# Get the runtime version
293-
runtimeVersion=$("$dotnetSdk/dotnet" --list-runtimes | tail -n 1 | awk '{print $2}')
294-
295301
# Run the BinaryDetection tool
296-
"$dotnetSdk/dotnet" run --project "$BinaryTool" -c Release -p RuntimeVersion="$runtimeVersion" "$TargetDir" "$OutputDir" -ab "$allowedBinaries" -db "$disallowedSbBinaries" -m $mode -l Debug
302+
"$dotnetSdk/dotnet" run --project "$BinaryTool" -c Release -p PackagesPropsDirectory="$packagesSourceFeed" "$TargetDir" "$OutputDir" -ab "$allowedBinaries" -db "$disallowedSbBinaries" -m $mode -l Debug
297303
}
298304

299305
# Check for the version of dotnet to install

src/SourceBuild/content/eng/tools/BinaryToolKit/BinaryToolKit.csproj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
<Project Sdk="Microsoft.NET.Sdk" InitialTargets="CheckRuntimeVersion">
1+
<Project Sdk="Microsoft.NET.Sdk" InitialTargets="CheckPackagesPropsDirectory">
22

33
<PropertyGroup>
44
<TargetFramework>$(NetCurrent)</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<RuntimeVersion></RuntimeVersion>
7+
<PackagesPropsDirectory></PackagesPropsDirectory>
88
<OutputType>Exe</OutputType>
9-
<NoWarn>$(NoWarn);NU1603</NoWarn>
109
</PropertyGroup>
1110

12-
<Target Name="CheckRuntimeVersion">
13-
<Error Condition="'$(RuntimeVersion)' == ''" Text="RuntimeVersion is not set. Please consider passing as an MSBuild Property" />
11+
<Target Name="CheckPackagesPropsDirectory">
12+
<Error Condition="'$(PackagesPropsDirectory)' == ''" Text="PackagesPropsDirectory is not set. Please pass as an MSBuild Property" />
13+
<Error Condition="!Exists('$(PackagesPropsDirectory)/PackageVersions.props')" Text="PackageVersions.props does not exist in $(PackagesPropsDirectory)." />
1414
</Target>
1515

16+
<!-- Need to condition this import because msbuild will complain about the project not being valid otherwise. -->
17+
<!-- With the condition, the CheckPackagesPropsDirectory will run as expected and show the respective errors. -->
18+
<Import Project="$(PackagesPropsDirectory)/PackageVersions.props" Condition="'$(PackagesPropsDirectory)' != ''" />
19+
1620
<ItemGroup>
17-
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="$(RuntimeVersion)" />
18-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(RuntimeVersion)" />
19-
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(RuntimeVersion)" />
21+
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="$(MicrosoftExtensionsFileSystemGlobbingVersion)" />
22+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsLoggingConsoleVersion)" />
23+
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingVersion)" />
2024
<PackageReference Include="System.CommandLine" Version="$(SystemCommandLineVersion)" />
2125
</ItemGroup>
2226

0 commit comments

Comments
 (0)