Skip to content

Commit

Permalink
Merge remote-tracking branch 'libtemplate/fixOptProfPackageSigningLib…
Browse files Browse the repository at this point in the history
…Template' into libtemplateUpdate
  • Loading branch information
AArnott committed Jul 12, 2024
2 parents 94cb52b + 0c9771d commit ce528a0
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 45 deletions.
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\Microsoft.VisualStudio.Threading.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: 2 additions & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"allowPrerelease": false
},
"msbuild-sdks": {
"MSBuild.Sdk.Extras": "3.0.44"
"MSBuild.Sdk.Extras": "3.0.44",
"Microsoft.Build.NoTargets": "3.7.56"
}
}
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.
70 changes: 70 additions & 0 deletions src/VSInsertionMetadata/VSInsertionMetadata.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<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;
</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>

<Target Name="SubstituteProfilingInputsMacro">
<ItemGroup>
<ProfilingInputsSource Include="ProfilingInputs.props" />
<ProfilingInputsTarget Include="$(IntermediateOutputPath)ProfilingInputs.props" />
</ItemGroup>
<ReplaceFileText
Condition="'$(ProfilingInputsDropName)' != ''"
InputFilename="@(ProfilingInputsSource)"
OutputFilename="@(ProfilingInputsTarget)"
MatchExpression="%TESTSTORE%"
ReplacementText="vstsdrop:$(ProfilingInputsDropName)" />

<Warning
Text="The ProfilingInputsDropName msbuild property has not been set, and the OptProf will not contain accurate content."
Condition="'$(ProfilingInputsDropName)' == ''" />
<Copy SourceFiles="@(ProfilingInputsSource)" DestinationFiles="@(ProfilingInputsTarget)"
Condition="'$(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>
<Target Name="BreakForRename" BeforeTargets="Pack;GenerateNuspec" Condition="'$(MSBuildProjectName)'=='Library.VSInsertionMetadata'">
<Error Text="This project should be renamed so the library name is used instead of 'Library'. Then delete this target." />
</Target>
</Project>

0 comments on commit ce528a0

Please sign in to comment.