attempt to use PGO nuget

This commit is contained in:
Michael Niksa 2021-11-10 13:13:37 -08:00
parent 7db7ba1ac9
commit 1645f7f33d
21 changed files with 95 additions and 423 deletions

View file

@ -2,4 +2,5 @@
<packages>
<package id="MUXCustomBuildTasks" version="1.0.48" targetFramework="native" />
<package id="Microsoft.Taef" version="10.60.210621002" targetFramework="native" />
<package id="Microsoft.PGO-Helpers.Cpp" version="0.2.22" />
</packages>

4
build/pgo/PGO.DB.proj Normal file
View file

@ -0,0 +1,4 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="Terminal.PGO.props" />
<Import Project="$(PkgMicrosoft_PGO_Helpers_Cpp)\build\Microsoft.PGO-Helpers.Cpp.targets" />
</Project>

View file

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Terminal.PGO.DB</id>
<version>0</version>
<title>Windows Terminal PGO Database</title>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Windows Terminal PGO Database</description>
</metadata>
<files>
<!-- The target directories for pgd files need to remain as is. PGO optimization pass will rely on this exact directory layout. -->
<file src="x64\Release\*.pgd" target="tools\x64"/>
</files>
</package>

View file

@ -0,0 +1,38 @@
<Project>
<PropertyGroup>
<NuGetPackageDirectory>$(MSBuildThisFileDirectory)..\..\packages</NuGetPackageDirectory>
<PkgMicrosoft_PGO_Helpers_Cpp>$(NuGetPackageDirectory)\Microsoft.PGO-Helpers.Cpp.0.2.18</PkgMicrosoft_PGO_Helpers_Cpp>
</PropertyGroup>
<!-- Get version information -->
<Import Project="$(MSBuildThisFileDirectory)..\..\custom.props" />
<PropertyGroup>
<!-- Optional, defaults to main. Name of the branch which will be used for calculating branch point. -->
<PGOBranch>main</PGOBranch>
<!-- Mandatory. Name of the NuGet package which will contain PGO databases for consumption by build system. -->
<PGOPackageName>Microsoft.Internal.Windows.Terminal.PGODatabase</PGOPackageName>
<!-- Mandatory. Major version number of the PGO database which should match the version of the product. This can be hardcoded or obtained from other sources in build system. -->
<PGOPackageVersionMajor>$(VersionMajor)</PGOPackageVersionMajor>
<!-- Mandatory. Minor version number of the PGO database which should match the version of the product. This can be hardcoded or obtained from other sources in build system. -->
<PGOPackageVersionMinor>$(VersionMinor)</PGOPackageVersionMinor>
<!-- Mandatory. Path to nuget.config file for the project. Path is relative to where the props file will be. -->
<PGONuGetConfigPath>$(MSBuildThisFileDirectory)..\..\nuget.config</PGONuGetConfigPath>
<!-- Mandatory. Path to PGO database NuSpec, see section below. -->
<PGONuspecPath>$(MSBuildThisFileDirectory)Terminal.PGO.DB.nuspec</PGONuspecPath>
<!-- Optional, defaults to true. Should verification result in build failure or error? -->
<PGOVerifyFailureTreatedAsError>true</PGOVerifyFailureTreatedAsError>
<!-- Optional, defaults to $(IntDir)\Nuspec. Temporary path where PGD files are copied to. -->
<PGONuspecBasePath>$(MSBuildThisFileDirectory)..\Nuspec</PGONuspecBasePath>
<!-- Optional, defaults to true. Specifies whether to use default information for PGD files. -->
<PGOUseDefaultPGDFileInfo>true</PGOUseDefaultPGDFileInfo>
</PropertyGroup>
</Project>

View file

@ -140,12 +140,6 @@ jobs:
filePath: .\build\scripts\Generate-ThirdPartyNotices.ps1
arguments: -MarkdownNoticePath .\NOTICE.md -OutputPath .\src\cascadia\CascadiaPackage\NOTICE.html
pwsh: true
- ${{ if eq(parameters.pgoBuildMode, 'Optimize') }}:
- task: PowerShell@2
displayName: Restore PGO Database
inputs:
filePath: tools/PGODatabase/restore-pgodb.ps1
workingDirectory: $(Build.SourcesDirectory)\tools\PGODatabase
- ${{ if eq(parameters.buildTerminal, true) }}:
- task: VSBuild@1
displayName: Build solution **\OpenConsole.sln
@ -164,20 +158,6 @@ jobs:
inputs:
PathtoPublish: $(Build.SourcesDirectory)\msbuild.binlog
ArtifactName: binlog-$(BuildPlatform)
- ${{ if eq(parameters.pgoBuildMode, 'Optimize') }}:
- task: PowerShell@2
displayName: Validate binaries are optimized
condition: and(succeeded(), eq(variables['BuildPlatform'], 'x64'))
inputs:
targetType: inline
script: >-
$Binaries = 'OpenConsole.exe', 'WindowsTerminal.exe', 'TerminalApp.dll', 'TerminalConnection.dll', 'Microsoft.Terminal.Control.dll', 'Microsoft.Terminal.Remoting.dll', 'Microsoft.Terminal.Settings.Editor.dll', 'Microsoft.Terminal.Settings.Model.dll'
foreach ($BinFile in $Binaries) {
& "$(Build.SourcesDirectory)\tools\PGODatabase\verify-pgo.ps1" "$(Build.SourcesDirectory)/src/cascadia/CascadiaPackage/bin/$(BuildPlatform)/$(BuildConfiguration)/$BinFile"
}
- task: PowerShell@2
displayName: Check MSIX for common regressions
inputs:

View file

@ -22,7 +22,7 @@ jobs:
steps:
- template: build-console-steps.yml
parameters:
additionalBuildArguments: ${{ parameters.additionalBuildArguments }}
additionalBuildArguments: '${{ parameters.additionalBuildArguments }}'
- template: helix-runtests-job.yml
parameters:
@ -52,3 +52,4 @@ jobs:
- ProcessTestResults
pgoArtifact: 'PGO'
platform: ${{ parameters.platform }}
configuration: ${{ parameters.configuration }}

View file

@ -12,6 +12,8 @@ steps:
inputs:
versionSpec: 5.2.0
- task: NuGetAuthenticate@0
# In the Microsoft Azure DevOps tenant, NuGetCommand is ambiguous.
# This should be `task: NuGetCommand@2`
- task: 333b11bd-d341-40d9-afcf-b32d5ce6f23b@2
@ -47,14 +49,6 @@ steps:
inputs:
filename: 'set'
- task: powershell@2
displayName: 'Restore PGO database'
condition: eq(variables['PGOBuildMode'], 'Optimize')
inputs:
targetType: filePath
workingDirectory: $(Build.SourcesDirectory)\tools\PGODatabase
filePath: $(Build.SourcesDirectory)\tools\PGODatabase\restore-pgodb.ps1
- task: VSBuild@1
displayName: 'Build solution **\OpenConsole.sln'
inputs:
@ -62,7 +56,10 @@ steps:
vsVersion: 16.0
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
msbuildArgs: "${{ parameters.additionalBuildArguments }}"
${{ if eq(variables['PGOBuildMode'], 'Instrument') }}:
msbuildArgs: "${{ parameters.additionalBuildArguments }} /p:PGOBuildMode=$(PGOBuildMode) /p:PGOCopyRuntime=true"
${{ if ne(variables['PGOBuildMode'], 'Instrument') }}:
msbuildArgs: "${{ parameters.additionalBuildArguments }} /p:PGOBuildMode=$(PGOBuildMode)"
clean: true
maximumCpuCount: true
@ -95,18 +92,6 @@ steps:
If ($Arch -Eq "x86") { $Arch = "Win32" }
Write-Host "##vso[task.setvariable variable=RationalizedBuildPlatform]${Arch}"
- task: PowerShell@2
displayName: 'Validate binaries are optimized'
condition: eq(variables['pgoBuildMode'], 'Optimize')
inputs:
targetType: inline
script: |
$Binaries = 'OpenConsole.exe', 'WindowsTerminal.exe', 'TerminalApp.dll', 'TerminalConnection.dll', 'Microsoft.Terminal.Control.dll', 'Microsoft.Terminal.Remoting.dll', 'Microsoft.Terminal.Settings.Editor.dll', 'Microsoft.Terminal.Settings.Model.dll'
foreach ($BinFile in $Binaries)
{
& "$(Build.SourcesDirectory)\tools\PGODatabase\verify-pgo.ps1" "$(Build.SourcesDirectory)/bin/$(RationalizedBuildPlatform)/$(BuildConfiguration)/$BinFile"
}
- task: PowerShell@2
displayName: 'Run Unit Tests'
inputs:

View file

@ -11,7 +11,7 @@ jobs:
vmImage: 'windows-2019'
variables:
artifactsPath: $(Build.SourcesDirectory)\Artifacts
pgoToolsPath: $(Build.SourcesDirectory)\tools\PGODatabase
pgoToolsPath: $(Build.SourcesDirectory)\PGO
nuspecPath: $(pgoToolsPath)\NuSpecs
nuspecFilename: PGO.nuspec
@ -30,43 +30,26 @@ jobs:
inputs:
versionSpec: 5.8.0
- task: CopyFiles@2
displayName: 'Copy pgd files to NuGet build directory'
- task: MSBuild@1
displayName: 'Create PGO Nuget'
inputs:
sourceFolder: $(artifactsPath)\${{ parameters.pgoArtifact }}
contents: '**\*.pgd'
targetFolder: $(nuspecPath)\tools
- task: powershell@2
displayName: 'Generate NuSpec file'
inputs:
targetType: filePath
filePath: $(pgoToolsPath)\generate-nuspec.ps1
workingDirectory: $(pgoToolsPath)
arguments: $(nuspecPath)\$(nuspecFilename).template $(nuspecPath)\$(nuspecFilename)
- task: 333b11bd-d341-40d9-afcf-b32d5ce6f23b@2
displayName: 'NuGet pack'
inputs:
command: pack
packagesToPack: '$(nuspecPath)\$(nuspecFilename)'
basePath: '$(nuspecPath)'
packDestination: '$(Build.ArtifactStagingDirectory)'
solution: $(pgoToolsPath)\PGO.DB.proj
msbuildArguments: '/t:CreatePGONuGet /p:PGDPathForAllArch=$(artifactsPath)\${{ parameters.pgoArtifact }} /p:PGOOutputPath=$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)
artifactName: ${{ parameters.pgoArtifact }}
- task: 333b11bd-d341-40d9-afcf-b32d5ce6f23b@2
displayName: 'NuGet push'
inputs:
command: push
nuGetFeedType: external
packagesToPush: $(Build.ArtifactStagingDirectory)/*.nupkg
# The actual URL and PAT for this feed is configured at
# https://microsoft.visualstudio.com/Dart/_settings/adminservices
# This is the name of that connection
publishFeedCredentials: 'Terminal Public Artifact Feed'
feedsToUse: config
nugetConfigPath: '$(Build.SourcesDirectory)/NuGet.config'
# - task: 333b11bd-d341-40d9-afcf-b32d5ce6f23b@2
# displayName: 'NuGet push'
# inputs:
# command: push
# nuGetFeedType: external
# packagesToPush: $(Build.ArtifactStagingDirectory)/*.nupkg
# # The actual URL and PAT for this feed is configured at
# # https://microsoft.visualstudio.com/Dart/_settings/adminservices
# # This is the name of that connection
# publishFeedCredentials: 'Terminal Public Artifact Feed'
# feedsToUse: config
# nugetConfigPath: '$(Build.SourcesDirectory)/NuGet.config'

View file

@ -2,6 +2,7 @@ parameters:
dependsOn: ''
pgoArtifact: PGO
platform: ''
configuration: ''
jobs:
- job: MergePGD
@ -12,6 +13,7 @@ jobs:
artifactsPath: $(Build.SourcesDirectory)\Artifacts
pgoArtifactsPath: $(artifactsPath)\${{ parameters.pgoArtifact }}
buildPlatform: ${{ parameters.platform }}
buildConfiguration: ${{ parameters.configuration }}
steps:
# The environment variable VCToolsInstallDir isn't defined on lab machines, so we need to retrieve it ourselves.
@ -29,53 +31,13 @@ jobs:
artifactName: ${{ parameters.pgoArtifact }}
downloadPath: $(artifactsPath)
- script: |
cd $(buildPlatform)
"%VCToolsInstallDir%\bin\hostx64\x64\pgomgr.exe" /merge WindowsTerminal*.pgc WindowsTerminal.pgd
displayName: 'Merge Terminal pgc files into pgd'
workingDirectory: $(pgoArtifactsPath)
- script: |
cd $(buildPlatform)
"%VCToolsInstallDir%\bin\hostx64\x64\pgomgr.exe" /merge OpenConsole*.pgc OpenConsole.pgd
displayName: 'Merge OpenConsole pgc files into pgd'
workingDirectory: $(pgoArtifactsPath)
- script: |
cd $(buildPlatform)
"%VCToolsInstallDir%\bin\hostx64\x64\pgomgr.exe" /merge Microsoft.Terminal.Control*.pgc Microsoft.Terminal.Control.pgd
displayName: 'Merge Microsoft.Terminal.Control pgc files into pgd'
workingDirectory: $(pgoArtifactsPath)
- script: |
cd $(buildPlatform)
"%VCToolsInstallDir%\bin\hostx64\x64\pgomgr.exe" /merge Microsoft.Terminal.Remoting*.pgc Microsoft.Terminal.Remoting.pgd
displayName: 'Merge Microsoft.Terminal.Remoting pgc files into pgd'
workingDirectory: $(pgoArtifactsPath)
- script: |
cd $(buildPlatform)
"%VCToolsInstallDir%\bin\hostx64\x64\pgomgr.exe" /merge Microsoft.Terminal.Settings.Editor*.pgc Microsoft.Terminal.Settings.Editor.pgd
displayName: 'Merge Microsoft.Terminal.Settings.Editor pgc files into pgd'
workingDirectory: $(pgoArtifactsPath)
- script: |
cd $(buildPlatform)
"%VCToolsInstallDir%\bin\hostx64\x64\pgomgr.exe" /merge Microsoft.Terminal.Settings.Model*.pgc Microsoft.Terminal.Settings.Model.pgd
displayName: 'Merge Microsoft.Terminal.Settings.Model pgc files into pgd'
workingDirectory: $(pgoArtifactsPath)
- script: |
cd $(buildPlatform)
"%VCToolsInstallDir%\bin\hostx64\x64\pgomgr.exe" /merge TerminalApp*.pgc TerminalApp.pgd
displayName: 'Merge TerminalApp pgc files into pgd'
workingDirectory: $(pgoArtifactsPath)
- script: |
cd $(buildPlatform)
"%VCToolsInstallDir%\bin\hostx64\x64\pgomgr.exe" /merge TerminalConnection*.pgc TerminalConnection.pgd
displayName: 'Merge TerminalConnection pgc files into pgd'
workingDirectory: $(pgoArtifactsPath)
- task: MSBuild@1
displayName: Merge counts into PGD
inputs:
solution: $(Build.SourcesDirectory)\OpenConsole.sln
platform: $(buildPlatform)
configuration: $(buildConfiguration)
msbuildArguments: '/t:MergePGOCounts /p:PGDPath=$(pgoArtifactsPath)\$(buildPlatform) /p:PGCRootPath=$(pgoArtifactsPath)\$(buildPlatform)'
- task: CopyFiles@2
displayName: 'Copy merged pgd to artifact staging'

View file

@ -34,8 +34,7 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<!-- PGO -->
<Import Condition="'$(PgoTarget)' == 'true' And '$(PGOBuildMode)' == 'Optimize'" Project="$(SolutionDir)packages\$(PGODatabaseId).$(PGODatabaseVersion)\build\PGO.targets" />
<Import Condition="'$(PgoTarget)' == 'true' And '$(PGOBuildMode)' == 'Instrument'" Project="$(SolutionDir)\src\common.pgo.runtime.props" />
<Import Condition="'$(PgoTarget)' == 'true'" Project="$(SolutionDir)\PGO\Terminal.PGO.props" />
<!-- Exclude our dependencies from static analysis. CAExcludePath can only be
set after we've imported Microsoft.Cpp.targets -->

View file

@ -174,8 +174,7 @@
</Link>
</ItemDefinitionGroup>
<Import Condition="'$(PgoTarget)' == 'true' And '$(Configuration)' == 'Release'" Project="$(SolutionDir)\src\common.pgo.compile.props" />
<Import Condition="'$(PgoTarget)' == 'true' And '$(PGOBuildMode)' == 'Optimize'" Project="$(SolutionDir)\tools\PGODatabase\PGO.version.props" />
<Import Condition="'$(PgoTarget)' == 'true'" Project="$(SolutionDir)\build\Terminal.PGO.props" />
<!-- For Win32 (x86) ONLY ... we use all defaults for AMD64. No def for those. -->
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">

View file

@ -1,18 +0,0 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id</id>
<version>$version</version>
<title>PGO Database</title>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>PGO Database</description>
<releaseNotes>Initial release</releaseNotes>
<copyright>Copyright 2021</copyright>
</metadata>
<files>
<file target="build\PGO.targets" src="build\PGO.targets"/>
<file target="tools\x64\" src="tools\x64\*.pgd"/>
</files>
</package>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PlatformShortName Condition="'$(PlatformShortName)'==''">$(Platform)</PlatformShortName>
<PlatformShortName Condition="'$(PlatformShortName)'=='Win32'">x86</PlatformShortName>
<PlatformShortName Condition="'$(PlatformShortName)'=='AnyCPU' and '$(Prefer32Bit)'==''">x64</PlatformShortName>
<PlatformShortName Condition="'$(PlatformShortName)'=='AnyCPU' and '$(Prefer32Bit)'=='true'">x64</PlatformShortName>
<PlatformShortName Condition="'$(PlatformShortName)'=='AnyCPU' and '$(Prefer32Bit)'=='false'">x64</PlatformShortName>
<ProfileGuidedDatabaseFileName>$(MSBuildThisFileDirectory)..\tools\$(PlatformShortName)\$(TargetName).pgd</ProfileGuidedDatabaseFileName>
</PropertyGroup>
<!-- Enable PGO optimization only for if the pgds file exists. -->
<ItemDefinitionGroup Condition="'$(Configuration)' == 'Release' and '$(PGOBuildMode)' == 'Optimize' and Exists('$(ProfileGuidedDatabaseFileName)')">
<Link>
<LinkTimeCodeGeneration>PGUpdate</LinkTimeCodeGeneration>
<ProfileGuidedDatabase>$(ProfileGuidedDatabaseFileName)</ProfileGuidedDatabase>
<AdditionalOptions>/force:pgorepro %(AdditionalOptions)</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
</Project>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<PGODatabaseId>$id</PGODatabaseId>
<PGODatabaseVersion>$version</PGODatabaseVersion>
</PropertyGroup>
</Project>

View file

@ -1,7 +0,0 @@
$pgoBranch = "main"
$packageId = "Microsoft.Internal.Windows.Terminal.PGODatabase"
# Get release version
[xml] $customProps = ( Get-Content "..\..\custom.props" )
$releaseVersionMajor = ( [int]::Parse( $customProps.GetElementsByTagName("VersionMajor").'#text' ) )
$releaseVersionMinor = ( [int]::Parse( $customProps.GetElementsByTagName("VersionMinor").'#text' ) )

View file

@ -1,11 +0,0 @@
Param(
[Parameter(Mandatory = $true, Position = 1)] [string] $templatePath,
[Parameter(Mandatory = $true, Position = 2)] [string] $outputPath)
. .\version.ps1
. .\template.ps1
. .\config.ps1
$version = FormatVersion ( MakeVersion $releaseVersionMajor $releaseVersionMinor ( GetDatetimeStamp $pgoBranch ) )
Write-Host ( "PGO INSTRUMENT: generating {0} version {1}" -f $packageId, $version )
FillOut-Template $templatePath $outputPath @{ "version" = $version; "id" = $packageId }

View file

@ -1,49 +0,0 @@
# Profile Guided Optimization
**NOTE: All PGO work builds on work from Microsoft/Microsoft-UI-XAML**
## Description
We generate PGO database NuGet package which is versioned based on product release version and branch name/time stamp of the code that was used for instrumentation and training. In CI/release builds an initialization step enumerates all available versions, filters out those for other releases and branches. Given a list of applicable versions, it will find the one that is closest (BEFORE) the time-stamp of the last commit or a fork-point from instrumented branch. That package version will be installed and version references will be updated. The PGO branch is determined by variable $pgoBranch in tools/PGODatabase/config.ps1. It will need to be updated if a forked branch should be PGO'd.
## Scenarios
For the purpose of illustration, lets assume the following is a chronological list of check-ins to two branches (main and release/2.4). Some of them have had instrumentation/training run done on them and have generated PGO NuGets (version numbers in parentheses). To simplify, lets assume that release major and minor versions are the same for all check-in as they merely act as filters for what versions are considered to be available.
1b27fd5f -- main --
7b303f74 -- main --
930ff585 -- main -- 2.4.2001312227-main
63948a75 -- main --
0d379b51 -- main --
f23f1fad -- main -- 2.4.2001312205-main
bcf9adaa -- main --
6ef44a23 -- main --
310bc133 -- release/2.4 --
80a4ab55 -- release/2.4 -- 2.4.2001312054-release_2_4
18b956f6 -- release/2.4 --
4abd4d54 -- main -- 2.4.2001312033-main
d150eae0 -- main -- 2.4.2001312028-main
### Optimizing on PGOd branch
If we are building on main (which in this example is PGOd), the version picked will be the one that has the same major and minor versions AND branch name and is the same or is right before the SHA being built.
E.g.
1b27fd5f -- 2.4.2001312227-main
f23f1fad -- 2.4.2001312205-main
bcf9adaa -- 2.4.2001312033-main
### Optimizing release branch
A branch which will be PGOd requires a slightly different handling. Lets say release/2.4 forked from main on commit 4abd4d54. Initially, it will be configured to track main and 18b956f6 will be optimized with 2.4.2001312033-main. When the configuration is changed to start tracking release/2.4 (change branch name $pgoBranch in tools/PGODatabase/config.ps1 script), it will start tracking its own branch.
E.g.
18b956f6 -- if tracking main -> 2.4.2001312033-main,
if tracking release/2.4 -> ERROR (no database exists)
310bc133 -- 2.4.2001312054-release_2_4
### Optimizing topic branch
Assuming topic branch will not have a training run done, it can still use database from branch it was forked from. Lets say we have a branch which was forked from main on 4abd4d54. If we dont change which branch its tracking, it will keep using 2.4.2001312033-main. Merging main on f23f1fad into topic branch, will change used database to 2.4.2001312205-main.

View file

@ -1,47 +0,0 @@
. .\version.ps1
. .\template.ps1
. .\config.ps1
$feedUri = "https://pkgs.dev.azure.com/ms/terminal/_packaging/TerminalDependencies/nuget/v2"
$currentVersion = MakeVersion $releaseVersionMajor $releaseVersionMinor ( GetDatetimeStamp $pgoBranch )
Write-Host ( "PGO OPTIMIZE: requesting {0} version {1}" -f $packageId, ( FormatVersion $currentVersion ) )
$packageSource = Register-PackageSource -ForceBootstrap -Name TerminalDependencies -Location $feedUri -ProviderName NuGet -Trusted
$packages = ( Find-Package $packageId -Source TerminalDependencies -AllowPrereleaseVersions -AllVersions ) | Sort-Object -Property Version -Descending
$best = $null
foreach ( $existing in $packages )
{
$existingVersion = MakeVersionFromString $existing.Version
if ( ( CompareBranches $existingVersion $currentVersion ) -eq $False -or
( CompareReleases $existingVersion $currentVersion ) -ne 0 )
{
# If this is different release or branch, then skip it.
continue
}
if ( ( CompareRevisions $existingVersion $currentVersion ) -le 0 )
{
# Version are sorted in descending order, the first one less than or equal to the current is the one we want.
# NOTE: at this point the only difference between versions will be revision (date-time stamp)
# which is formatted as a fixed-length string, so string comparison WILL sort it correctly.
$best = $existing
break
}
}
if ( $best -eq $null )
{
throw "Appropriate database cannot be found"
}
Write-Host ( "PGO OPTIMIZE: picked {0} version {1}" -f $packageId, $best.Version )
$best | Install-Package -Destination ..\..\packages -Force
$packageSource | Unregister-PackageSource
FillOut-Template "PGO.version.props.template" "PGO.version.props" @{ "version" = $best.Version; "id" = $packageId }

View file

@ -1,16 +0,0 @@
function Replace-Many ( $string, $dictionary )
{
foreach ( $key in $dictionary.Keys )
{
$field = '$' + $key.ToString()
$string = $string.Replace( $field, $dictionary[$key].ToString() )
}
return $string
}
function FillOut-Template ( $inputPath, $outputPath, $dictionary )
{
$replaced = Replace-Many ( Get-Content $inputPath ) $dictionary
Write-Output $replaced | Set-Content $outputPath -Force | Out-Null
}

View file

@ -1,45 +0,0 @@
Param(
[Parameter(Mandatory = $true, Position = 1)]
[string] $module)
if ( !( Test-Path $module ) )
{
throw "File does not exist $module"
}
$vsPath = &(Join-Path ${env:ProgramFiles(x86)} "\Microsoft Visual Studio\Installer\vswhere.exe") -property installationpath
Import-Module (Get-ChildItem $vsPath -Recurse -File -Filter Microsoft.VisualStudio.DevShell.dll).FullName
Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation
$output = ( & link.exe /dump /headers /coffgroup $module )
$regex1 = [regex] '^\s*[A-F0-9]+ coffgrp(\s+[A-F0-9]+){4} \(PGU\)$'
$regex2 = [regex] '^\s*([A-F0-9]+\s+){2}\.text\$zz$'
$matchFlags = 0
foreach ( $line in $output )
{
if ( $line -match $regex1 )
{
$matchFlags = $matchFlags -bor 1
}
if ( $line -match $regex2 )
{
$matchFlags = $matchFlags -bor 2
}
}
$optimized = $matchFlags -eq 3
$message = "$module is $( if ( $optimized ) { "optimized" } else { "not optimized" } )"
if ( -not $optimized )
{
throw $message
}
else
{
write-host $message
}

View file

@ -1,75 +0,0 @@
function MakeVersion ( $major, $minor, $datetimeStamp )
{
$revision, $branch = $datetimeStamp.Split("-", 2)
if ( $branch -eq $null )
{
$branch = ""
}
return [PSCustomObject] @{
Major = $major
Minor = $minor
Revision = $revision
Branch = $branch
}
}
function MakeVersionFromString ( $str )
{
$parts = $str.Split(".")
return MakeVersion ( [int]::Parse($parts[0]) ) ( [int]::Parse($parts[1]) ) $parts[2]
}
function FormatVersion ( $version )
{
$branch = ""
if ( $version.Branch -ne "" )
{
$branch = "-{0}" -f $version.Branch
}
return "{0}.{1}.{2}{3}" -f $version.Major, $version.Minor, $version.Revision, $branch
}
function CompareReleases ( $version1, $version2 )
{
$cmpMajor = [Math]::Sign($version1.Major - $version2.Major)
if ( $cmpMajor -ne 0 )
{
return $cmpMajor
}
return [Math]::Sign($version1.Minor - $version2.Minor)
}
function CompareRevisions ( $version1, $version2 )
{
return [Math]::Sign($version1.Revision - $version2.Revision)
}
function CompareBranches ( $version1, $version2 )
{
return $version1.Branch -eq $version2.Branch
}
function GetDatetimeStamp ( $pgoBranch )
{
$forkSHA = $( git merge-base origin/$pgoBranch HEAD )
if ( $LastExitCode -ne 0 )
{
throw "FAILED: git merge-base"
}
$forkDate = ( Get-Date -Date $( git log -1 $forkSHA --date=iso --pretty=format:"%ad" ) ).ToUniversalTime().ToString("yyMMddHHmm")
if ( $LastExitCode -ne 0 )
{
throw "FAILED: Get forkDate"
}
return $forkDate + "-" + ( $pgoBranch -replace "(/|\.|@|>|<)", "-" )
}