2019-03-06 17:55:39 +00:00
|
|
|
Param(
|
|
|
|
[Parameter(Mandatory=$true)][string] $barToken, # Token generated at https://maestro-prod.westus2.cloudapp.azure.com/Account/Tokens
|
|
|
|
[Parameter(Mandatory=$true)][string] $gitHubPat, # GitHub personal access token from https://github.com/settings/tokens (no auth scopes needed)
|
|
|
|
[Parameter(Mandatory=$true)][string] $azdoPat, # Azure Dev Ops tokens from https://dev.azure.com/dnceng/_details/security/tokens (code read scope needed)
|
|
|
|
[Parameter(Mandatory=$true)][string] $outputFolder, # Where the graphviz.txt file will be created
|
2020-01-30 13:35:10 +00:00
|
|
|
[string] $darcVersion, # darc's version
|
2019-03-21 12:33:28 +00:00
|
|
|
[string] $graphvizVersion = '2.38', # GraphViz version
|
2019-03-06 17:55:39 +00:00
|
|
|
[switch] $includeToolset # Whether the graph should include toolset dependencies or not. i.e. arcade, optimization. For more about
|
|
|
|
# toolset dependencies see https://github.com/dotnet/arcade/blob/master/Documentation/Darc.md#toolset-vs-product-dependencies
|
|
|
|
)
|
|
|
|
|
|
|
|
function CheckExitCode ([string]$stage)
|
|
|
|
{
|
|
|
|
$exitCode = $LASTEXITCODE
|
|
|
|
if ($exitCode -ne 0) {
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-PipelineTelemetryError -Category 'Arcade' -Message "Something failed in stage: '$stage'. Check for errors above. Exiting now..."
|
2019-03-06 17:55:39 +00:00
|
|
|
ExitWithExitCode $exitCode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2019-11-22 13:41:58 +00:00
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
. $PSScriptRoot\tools.ps1
|
|
|
|
|
|
|
|
Import-Module -Name (Join-Path $PSScriptRoot 'native\CommonLibrary.psm1')
|
|
|
|
|
2019-03-06 17:55:39 +00:00
|
|
|
Push-Location $PSScriptRoot
|
2019-06-08 12:08:27 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-Host 'Installing darc...'
|
2019-03-06 17:55:39 +00:00
|
|
|
. .\darc-init.ps1 -darcVersion $darcVersion
|
2019-11-22 13:41:58 +00:00
|
|
|
CheckExitCode 'Running darc-init'
|
2019-03-06 17:55:39 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
$engCommonBaseDir = Join-Path $PSScriptRoot 'native\'
|
2019-03-21 12:33:28 +00:00
|
|
|
$graphvizInstallDir = CommonLibrary\Get-NativeInstallDirectory
|
2019-11-22 13:41:58 +00:00
|
|
|
$nativeToolBaseUri = 'https://netcorenativeassets.blob.core.windows.net/resource-packages/external'
|
|
|
|
$installBin = Join-Path $graphvizInstallDir 'bin'
|
2019-03-21 12:33:28 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-Host 'Installing dot...'
|
2019-03-21 12:33:28 +00:00
|
|
|
.\native\install-tool.ps1 -ToolName graphviz -InstallPath $installBin -BaseUri $nativeToolBaseUri -CommonLibraryDirectory $engCommonBaseDir -Version $graphvizVersion -Verbose
|
|
|
|
|
2019-03-06 17:55:39 +00:00
|
|
|
$darcExe = "$env:USERPROFILE\.dotnet\tools"
|
|
|
|
$darcExe = Resolve-Path "$darcExe\darc.exe"
|
2019-06-08 12:08:27 +00:00
|
|
|
|
2019-03-06 17:55:39 +00:00
|
|
|
Create-Directory $outputFolder
|
2019-06-08 12:08:27 +00:00
|
|
|
|
2019-03-21 12:33:28 +00:00
|
|
|
# Generate 3 graph descriptions:
|
|
|
|
# 1. Flat with coherency information
|
|
|
|
# 2. Graphviz (dot) file
|
|
|
|
# 3. Standard dependency graph
|
2019-03-06 17:55:39 +00:00
|
|
|
$graphVizFilePath = "$outputFolder\graphviz.txt"
|
2019-03-21 12:33:28 +00:00
|
|
|
$graphVizImageFilePath = "$outputFolder\graph.png"
|
|
|
|
$normalGraphFilePath = "$outputFolder\graph-full.txt"
|
|
|
|
$flatGraphFilePath = "$outputFolder\graph-flat.txt"
|
2019-11-22 13:41:58 +00:00
|
|
|
$baseOptions = @( '--github-pat', "$gitHubPat", '--azdev-pat', "$azdoPat", '--password', "$barToken" )
|
2019-06-08 12:08:27 +00:00
|
|
|
|
2019-03-06 17:55:39 +00:00
|
|
|
if ($includeToolset) {
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-Host 'Toolsets will be included in the graph...'
|
|
|
|
$baseOptions += @( '--include-toolset' )
|
2019-03-06 17:55:39 +00:00
|
|
|
}
|
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-Host 'Generating standard dependency graph...'
|
2019-06-08 12:08:27 +00:00
|
|
|
& "$darcExe" get-dependency-graph @baseOptions --output-file $normalGraphFilePath
|
2019-11-22 13:41:58 +00:00
|
|
|
CheckExitCode 'Generating normal dependency graph'
|
2019-03-21 12:33:28 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-Host 'Generating flat dependency graph and graphviz file...'
|
2019-06-08 12:08:27 +00:00
|
|
|
& "$darcExe" get-dependency-graph @baseOptions --flat --coherency --graphviz $graphVizFilePath --output-file $flatGraphFilePath
|
2019-11-22 13:41:58 +00:00
|
|
|
CheckExitCode 'Generating flat and graphviz dependency graph'
|
2019-03-21 12:33:28 +00:00
|
|
|
|
|
|
|
Write-Host "Generating graph image $graphVizFilePath"
|
|
|
|
$dotFilePath = Join-Path $installBin "graphviz\$graphvizVersion\release\bin\dot.exe"
|
2019-06-08 12:08:27 +00:00
|
|
|
& "$dotFilePath" -Tpng -o"$graphVizImageFilePath" "$graphVizFilePath"
|
2019-11-22 13:41:58 +00:00
|
|
|
CheckExitCode 'Generating graphviz image'
|
2019-06-08 12:08:27 +00:00
|
|
|
|
2019-03-21 12:33:28 +00:00
|
|
|
Write-Host "'$graphVizFilePath', '$flatGraphFilePath', '$normalGraphFilePath' and '$graphVizImageFilePath' created!"
|
2019-03-06 17:55:39 +00:00
|
|
|
}
|
|
|
|
catch {
|
|
|
|
if (!$includeToolset) {
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-Host 'This might be a toolset repo which includes only toolset dependencies. ' -NoNewline -ForegroundColor Yellow
|
|
|
|
Write-Host 'Since -includeToolset is not set there is no graph to create. Include -includeToolset and try again...' -ForegroundColor Yellow
|
2019-03-06 17:55:39 +00:00
|
|
|
}
|
|
|
|
Write-Host $_.ScriptStackTrace
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-PipelineTelemetryError -Category 'Arcade' -Message $_
|
2019-03-06 17:55:39 +00:00
|
|
|
ExitWithExitCode 1
|
2019-03-21 12:33:28 +00:00
|
|
|
} finally {
|
2019-11-22 13:41:58 +00:00
|
|
|
Pop-Location
|
2020-04-30 12:44:30 +00:00
|
|
|
}
|