[2020-02] Bump msbuild to track mono-2019-12 (#19661)
[mono-project.git] / eng / common / generate-graph-files.ps1
blob7ad26afa692e0eba3a3bc8db9cdfb79494eb6307
1 Param(
2 [Parameter(Mandatory=$true)][string] $barToken, # Token generated at https://maestro-prod.westus2.cloudapp.azure.com/Account/Tokens
3 [Parameter(Mandatory=$true)][string] $gitHubPat, # GitHub personal access token from https://github.com/settings/tokens (no auth scopes needed)
4 [Parameter(Mandatory=$true)][string] $azdoPat, # Azure Dev Ops tokens from https://dev.azure.com/dnceng/_details/security/tokens (code read scope needed)
5 [Parameter(Mandatory=$true)][string] $outputFolder, # Where the graphviz.txt file will be created
6 [string] $darcVersion = '1.1.0-beta.19175.6', # darc's version
7 [string] $graphvizVersion = '2.38', # GraphViz version
8 [switch] $includeToolset # Whether the graph should include toolset dependencies or not. i.e. arcade, optimization. For more about
9 # toolset dependencies see https://github.com/dotnet/arcade/blob/master/Documentation/Darc.md#toolset-vs-product-dependencies
12 function CheckExitCode ([string]$stage)
14 $exitCode = $LASTEXITCODE
15 if ($exitCode -ne 0) {
16 Write-PipelineTelemetryError -Category 'Arcade' -Message "Something failed in stage: '$stage'. Check for errors above. Exiting now..."
17 ExitWithExitCode $exitCode
21 try {
22 $ErrorActionPreference = 'Stop'
23 . $PSScriptRoot\tools.ps1
25 Import-Module -Name (Join-Path $PSScriptRoot 'native\CommonLibrary.psm1')
27 Push-Location $PSScriptRoot
29 Write-Host 'Installing darc...'
30 . .\darc-init.ps1 -darcVersion $darcVersion
31 CheckExitCode 'Running darc-init'
33 $engCommonBaseDir = Join-Path $PSScriptRoot 'native\'
34 $graphvizInstallDir = CommonLibrary\Get-NativeInstallDirectory
35 $nativeToolBaseUri = 'https://netcorenativeassets.blob.core.windows.net/resource-packages/external'
36 $installBin = Join-Path $graphvizInstallDir 'bin'
38 Write-Host 'Installing dot...'
39 .\native\install-tool.ps1 -ToolName graphviz -InstallPath $installBin -BaseUri $nativeToolBaseUri -CommonLibraryDirectory $engCommonBaseDir -Version $graphvizVersion -Verbose
41 $darcExe = "$env:USERPROFILE\.dotnet\tools"
42 $darcExe = Resolve-Path "$darcExe\darc.exe"
44 Create-Directory $outputFolder
46 # Generate 3 graph descriptions:
47 # 1. Flat with coherency information
48 # 2. Graphviz (dot) file
49 # 3. Standard dependency graph
50 $graphVizFilePath = "$outputFolder\graphviz.txt"
51 $graphVizImageFilePath = "$outputFolder\graph.png"
52 $normalGraphFilePath = "$outputFolder\graph-full.txt"
53 $flatGraphFilePath = "$outputFolder\graph-flat.txt"
54 $baseOptions = @( '--github-pat', "$gitHubPat", '--azdev-pat', "$azdoPat", '--password', "$barToken" )
56 if ($includeToolset) {
57 Write-Host 'Toolsets will be included in the graph...'
58 $baseOptions += @( '--include-toolset' )
61 Write-Host 'Generating standard dependency graph...'
62 & "$darcExe" get-dependency-graph @baseOptions --output-file $normalGraphFilePath
63 CheckExitCode 'Generating normal dependency graph'
65 Write-Host 'Generating flat dependency graph and graphviz file...'
66 & "$darcExe" get-dependency-graph @baseOptions --flat --coherency --graphviz $graphVizFilePath --output-file $flatGraphFilePath
67 CheckExitCode 'Generating flat and graphviz dependency graph'
69 Write-Host "Generating graph image $graphVizFilePath"
70 $dotFilePath = Join-Path $installBin "graphviz\$graphvizVersion\release\bin\dot.exe"
71 & "$dotFilePath" -Tpng -o"$graphVizImageFilePath" "$graphVizFilePath"
72 CheckExitCode 'Generating graphviz image'
74 Write-Host "'$graphVizFilePath', '$flatGraphFilePath', '$normalGraphFilePath' and '$graphVizImageFilePath' created!"
76 catch {
77 if (!$includeToolset) {
78 Write-Host 'This might be a toolset repo which includes only toolset dependencies. ' -NoNewline -ForegroundColor Yellow
79 Write-Host 'Since -includeToolset is not set there is no graph to create. Include -includeToolset and try again...' -ForegroundColor Yellow
81 Write-Host $_.ScriptStackTrace
82 Write-PipelineTelemetryError -Category 'Arcade' -Message $_
83 ExitWithExitCode 1
84 } finally {
85 Pop-Location