Skip to content

Commit

Permalink
Sign the *.VSInsertionMetadata optprof package
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Jul 12, 2024
1 parent 71b9db8 commit 03d69cf
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 50 deletions.
8 changes: 2 additions & 6 deletions Expand-Template.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ try {
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
git mv test/Library.Tests "test/$LibraryName.Tests"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
git mv src/VSInsertionMetadata/Library.VSInsertionMetadata.proj "src/VSInsertionMetadata/$LibraryName.VSInsertionMetadata.proj"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

# Refresh solution file both to update paths and give the projects unique GUIDs
dotnet sln remove src/Library/Library.csproj
Expand Down Expand Up @@ -168,12 +170,6 @@ try {
'LibraryName' = $LibraryName;
}

Replace-Placeholders -Path "azure-pipelines/InsertionMetadataPackage.nuspec" -Replacements @{
'LibraryName' = $LibraryName;
}
Replace-Placeholders -Path "azure-pipelines/artifacts/VSInsertion.ps1" -Replacements @{
'LibraryName' = $LibraryName;
}
Replace-Placeholders -Path "azure-pipelines/OptProf.yml" -Replacements @{
'LibraryName' = $LibraryName;
}
Expand Down
17 changes: 0 additions & 17 deletions azure-pipelines/InsertionMetadataPackage.nuspec

This file was deleted.

25 changes: 1 addition & 24 deletions azure-pipelines/artifacts/VSInsertion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,7 @@ $result = @{

if ($env:IsOptProf) {
$VSRepoPackages = "$RepoRoot/bin/Packages/$BuildConfiguration/VSRepo"

$ArtifactBasePath = "$RepoRoot\obj\_artifacts"
$ArtifactPath = "$ArtifactBasePath\VSInsertion"
if (-not (Test-Path $ArtifactPath)) { New-Item -ItemType Directory -Path $ArtifactPath | Out-Null }

$profilingInputs = [xml](Get-Content -Path "$PSScriptRoot\..\ProfilingInputs.props")
$profilingInputs.Project.ItemGroup.TestStore.Include = "vstsdrop:" + (& "$PSScriptRoot\..\variables\ProfilingInputsDropName.ps1")
$profilingInputs.Save("$ArtifactPath\ProfilingInputs.props")

$InsertionMetadataVersion = $(dotnet tool run nbgv get-version -p "$RepoRoot\src" -f json | ConvertFrom-Json).NuGetPackageVersion
if ($env:BUILD_BUILDID) {
# We must ensure unique versions for the insertion metadata package so
# it can contain information that is unique to this build.
# In particular it includes the ProfilingInputsDropName, which contains the BuildId.
# A non-unique package version here may collide with a prior run of this same commit,
# ultimately resulting in a failure of the optprof run.
$InsertionMetadataVersion += '.' + $env:BUILD_BUILDID
}
& (& "$PSScriptRoot\..\Get-NuGetTool.ps1") pack "$PSScriptRoot\..\InsertionMetadataPackage.nuspec" -OutputDirectory $VSRepoPackages -BasePath $ArtifactPath -Version $InsertionMetadataVersion | Out-Null
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

$result["$VSRepoPackages"] = (Get-ChildItem "$VSRepoPackages\LibraryName.VSInsertionMetadata.$InsertionMetadataVersion.nupkg");
$result["$VSRepoPackages"] = (Get-ChildItem "$VSRepoPackages\*.VSInsertionMetadata.*.nupkg");
}

$result
5 changes: 2 additions & 3 deletions azure-pipelines/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ steps:
condition: and(succeeded(), ${{ parameters.RunTests }})

- ${{ if parameters.IsOptProf }}:
# We have to artifically run this script so that the extra .nupkg is produced for variables/InsertPropsValues.ps1 to notice.
- powershell: azure-pipelines\artifacts\VSInsertion.ps1
displayName: 🔧 Prepare VSInsertion artifact
- script: dotnet pack src\VSInsertionMetadata -c $(BuildConfiguration) -warnaserror /bl:"$(Build.ArtifactStagingDirectory)/build_logs/VSInsertion-Pack.binlog"
displayName: 🔧 dotnet pack VSInsertionMetadata

- powershell: azure-pipelines/variables/_pipelines.ps1
failOnStderr: true
Expand Down
3 changes: 3 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"version": "8.0.300",
"rollForward": "patch",
"allowPrerelease": false
},
"msbuild-sdks": {
"Microsoft.Build.NoTargets": "3.7.56"
}
}
11 changes: 11 additions & 0 deletions src/VSInsertionMetadata/Library.VSInsertionMetadata.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.Build.NoTargets">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<PackageOutputPath>$(RepoRootPath)bin\Packages\$(Configuration)\VSRepo\</PackageOutputPath>
<IncludeSymbols>false</IncludeSymbols>
<EnableDefaultSignFiles>false</EnableDefaultSignFiles>
<Description>Contains metadata for insertion into VS.</Description>
</PropertyGroup>
<Import Project="VSInsertionMetadata.targets" />
</Project>
File renamed without changes.
64 changes: 64 additions & 0 deletions src/VSInsertionMetadata/VSInsertionMetadata.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<Project>
<UsingTask TaskName="ReplaceFileText" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<InputFilename ParameterType="System.String" Required="true" />
<OutputFilename ParameterType="System.String" Required="true" />
<MatchExpression ParameterType="System.String" Required="true" />
<ReplacementText ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs">
<![CDATA[
File.WriteAllText(
OutputFilename,
Regex.Replace(File.ReadAllText(InputFilename), MatchExpression, ReplacementText)
);
]]>
</Code>
</Task>
</UsingTask>

<PropertyGroup>
<TargetsForTfmSpecificContentInPackage>
$(TargetsForTfmSpecificContentInPackage);
SubstituteProfilingInputsMacro;
SubstituteProfilingInputsMacroWarning;
</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>

<Target Name="SubstituteProfilingInputsMacroWarning" Condition="'$(ProfilingInputsDropName)'==''">
<Warning Text="The ProfilingInputsDropName msbuild property has not been set, and the OptProf will not contain accurate content."/>
</Target>
<Target Name="SubstituteProfilingInputsMacro" Condition="'$(ProfilingInputsDropName)'!=''">
<ItemGroup>
<ProfilingInputsSource Include="ProfilingInputs.props" />
<ProfilingInputsTarget Include="$(IntermediateOutputPath)ProfilingInputs.props" />
</ItemGroup>
<ReplaceFileText
Condition="'$(ProfilingInputsDropName)' != ''"
InputFilename="@(ProfilingInputsSource)"
OutputFilename="@(ProfilingInputsTarget)"
MatchExpression="%TESTSTORE%"
ReplacementText="vstsdrop:$(ProfilingInputsDropName)" />
<ItemGroup>
<TfmSpecificPackageFile Include="@(ProfilingInputsTarget)" PackagePath="InsertionVS/" />
</ItemGroup>
</Target>
<Target Name="EnsureUniquePackageVersion"
Condition="'$(Build_BuildId)' != ''"
AfterTargets="GetBuildVersion">
<!--
We must ensure unique versions for the insertion metadata package so
it can contain information that is unique to this build.
In particular it includes the ProfilingInputsDropName, which contains the BuildId.
A non-unique package version here may collide with a prior run of this same commit,
ultimately resulting in a failure of the optprof run.
-->
<PropertyGroup>
<PackageVersion>$(PackageVersion).$(Build_BuildId)</PackageVersion>
</PropertyGroup>
</Target>
</Project>

0 comments on commit 03d69cf

Please sign in to comment.