Skip to content

Commit

Permalink
Add generateErrorLog setting to Run-ALPipeline (#3186)
Browse files Browse the repository at this point in the history
Add generateErrorLog setting to `Run-ALPipeline`

The setting is propagated down to `Compile-AppInNavContainer` and
`Compile-AppWithBcCompilerFolder` and is used to set the compiler
setting `errorLog`.

The generated error log file has the same name as the `.app` file but
the file extension is `.errorLog.json`.

---------

Co-authored-by: Alexander Holstrup <[email protected]>
Co-authored-by: Freddy Kristiansen <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2023
1 parent 212485a commit e932f36
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 162 deletions.
51 changes: 32 additions & 19 deletions AppHandling/Compile-AppInNavContainer.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#
<#
.Synopsis
Use NAV/BC Container to Compile App
.Description
Expand Down Expand Up @@ -50,6 +50,9 @@
Specify if you want Compilation to fail on Error or Warning
.Parameter nowarn
Specify a nowarn parameter for the compiler
.Parameter generateErrorLog
Switch parameter on whether to generate an alerts log file. Default is false.
The file will be placed in the same folder as the app file, and will have the same name as the app file, but with the extension .errorLog.json.
.Parameter preProcessorSymbols
PreProcessorSymbols to set when compiling the app.
.Parameter generatecrossreferences
Expand Down Expand Up @@ -115,6 +118,7 @@ function Compile-AppInBcContainer {
[string[]] $CustomCodeCops = @(),
[Parameter(Mandatory=$false)]
[string] $nowarn,
[switch] $generateErrorLog,
[string[]] $preProcessorSymbols = @(),
[switch] $GenerateCrossReferences,
[switch] $ReportSuppressedDiagnostics,
Expand Down Expand Up @@ -143,7 +147,7 @@ try {
$platform = (Get-BcContainerNavVersion -containerOrImageName $containerName).Split('-')[0]
}
[System.Version]$platformversion = $platform

$containerProjectFolder = Get-BcContainerPath -containerName $containerName -path $appProjectFolder
if ("$containerProjectFolder" -eq "") {
throw "The appProjectFolder ($appProjectFolder) is not shared with the container."
Expand Down Expand Up @@ -216,7 +220,7 @@ try {
throw "The rulesetFile ($rulesetFile) is not shared with the container."
}
}

$CustomCodeCopFiles = @()
if ($CustomCodeCops.Count -gt 0) {
$CustomCodeCops | ForEach-Object {
Expand Down Expand Up @@ -248,14 +252,14 @@ try {
AddTelemetryProperty -telemetryScope $telemetryScope -key "name" -value $appJsonObject.Name
AddTelemetryProperty -telemetryScope $telemetryScope -key "version" -value $appJsonObject.Version
AddTelemetryProperty -telemetryScope $telemetryScope -key "appname" -value $appName

Write-Host "Using Symbols Folder: $appSymbolsFolder"
if (!(Test-Path -Path $appSymbolsFolder -PathType Container)) {
New-Item -Path $appSymbolsFolder -ItemType Directory | Out-Null
}

if ($CopySymbolsFromContainer) {
Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { Param($appSymbolsFolder)
Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { Param($appSymbolsFolder)
if (Test-Path "C:\Extensions\*.app") {
$paths = @(
"C:\Program Files\Microsoft Dynamics NAV\*\AL Development Environment\System.app"
Expand Down Expand Up @@ -397,25 +401,25 @@ try {
else {
$protocol = "http://"
}

$ip = Get-BcContainerIpAddress -containerName $containerName
if ($ip) {
$devServerUrl = "$($protocol)$($ip):$($customConfig.DeveloperServicesPort)/$ServerInstance"
}
else {
$devServerUrl = "$($protocol)$($containerName):$($customConfig.DeveloperServicesPort)/$ServerInstance"
}

$timeout = 300000
$sslVerificationDisabled = ($protocol -eq "https://")
$sslVerificationDisabled = ($protocol -eq "https://")
if ($customConfig.ClientServicesCredentialType -eq "Windows") {
$useDefaultCredentials = $true
}
else {
if (!($credential)) {
throw "You need to specify credentials when you are not using Windows Authentication"
}

$pair = ("$($Credential.UserName):"+[System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($credential.Password)))
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
Expand Down Expand Up @@ -454,7 +458,7 @@ try {
else {
$symbolsFile = Join-Path $appSymbolsFolder $symbolsName
Write-Host "Downloading symbols: $symbolsName"

$publisher = [uri]::EscapeDataString($publisher)
$name = [uri]::EscapeDataString($name)
if ($appId -and $platformversion -ge [System.Version]"20.0.0.0") {
Expand Down Expand Up @@ -490,11 +494,11 @@ try {
$addDependencies = Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param($symbolsFile, $platformversion)
# Wait for file to be accessible in container
While (-not (Test-Path $symbolsFile)) { Start-Sleep -Seconds 1 }

if ($platformversion.Major -ge 15) {
Add-Type -AssemblyName System.IO.Compression.FileSystem
Add-Type -AssemblyName System.Text.Encoding

try {
# Import types needed to invoke the compiler
$alcPath = 'C:\build\vsix\extension\bin'
Expand All @@ -506,11 +510,11 @@ try {
$packageStream = [System.IO.File]::OpenRead($symbolsFile)
$package = [Microsoft.Dynamics.Nav.CodeAnalysis.Packaging.NavAppPackageReader]::Create($PackageStream, $true)
$manifest = $package.ReadNavAppManifest()

if ($manifest.application) {
@{ "publisher" = "Microsoft"; "name" = "Application"; "appId" = ''; "version" = $manifest.Application }
}

foreach ($dependency in $manifest.dependencies) {
$appId = ''
if ($dependency.psobject.Properties.name -eq 'appid') {
Expand Down Expand Up @@ -560,7 +564,12 @@ try {
$depidx++
}

$result = Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param($appProjectFolder, $appSymbolsFolder, $appOutputFile, $EnableCodeCop, $EnableAppSourceCop, $EnablePerTenantExtensionCop, $EnableUICop, $CustomCodeCops, $rulesetFile, $enableExternalRulesets, $assemblyProbingPaths, $nowarn, $GenerateCrossReferences, $ReportSuppressedDiagnostics, $generateReportLayoutParam, $features, $preProcessorSymbols, $platformversion, $updateDependencies, $sourceRepositoryUrl, $sourceCommit, $buildBy, $buildUrl )
$errorLogFilePath = ""
if($generateErrorLog) {
$errorLogFilePath = (Join-Path $containerOutputFolder $($appName -replace '.app$','.errorLog.json'))
}

$result = Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param($appProjectFolder, $appSymbolsFolder, $appOutputFile, $EnableCodeCop, $EnableAppSourceCop, $EnablePerTenantExtensionCop, $EnableUICop, $CustomCodeCops, $rulesetFile, $enableExternalRulesets, $assemblyProbingPaths, $nowarn, $errorLogFilePath, $GenerateCrossReferences, $ReportSuppressedDiagnostics, $generateReportLayoutParam, $features, $preProcessorSymbols, $platformversion, $updateDependencies, $sourceRepositoryUrl, $sourceCommit, $buildBy, $buildUrl )

if ($updateDependencies) {
$appJsonFile = Join-Path $appProjectFolder 'app.json'
Expand Down Expand Up @@ -657,6 +666,10 @@ try {
$alcParameters += @("/nowarn:$nowarn")
}

if ($errorLogFilePath) {
$alcParameters += @("/errorLog:""$errorLogFilePath""")
}

if ($GenerateCrossReferences -and $platformversion.Major -ge 18) {
$alcParameters += @("/generatecrossreferences")
}
Expand Down Expand Up @@ -698,12 +711,12 @@ try {
Write-Host ".\alc.exe $([string]::Join(' ', $alcParameters))"

& .\alc.exe $alcParameters

if ($lastexitcode -ne 0 -and $lastexitcode -ne -1073740791) {
"App generation failed with exit code $lastexitcode"
}
} -ArgumentList $containerProjectFolder, $containerSymbolsFolder, (Join-Path $containerOutputFolder $appName), $EnableCodeCop, $EnableAppSourceCop, $EnablePerTenantExtensionCop, $EnableUICop, $CustomCodeCopFiles, $containerRulesetFile, $enableExternalRulesets, $assemblyProbingPaths, $nowarn, $GenerateCrossReferences, $ReportSuppressedDiagnostics, $GenerateReportLayoutParam, $features, $preProcessorSymbols, $platformversion, $updateDependencies, $sourceRepositoryUrl, $sourceCommit, $buildBy, $buildUrl
} -ArgumentList $containerProjectFolder, $containerSymbolsFolder, (Join-Path $containerOutputFolder $appName), $EnableCodeCop, $EnableAppSourceCop, $EnablePerTenantExtensionCop, $EnableUICop, $CustomCodeCopFiles, $containerRulesetFile, $enableExternalRulesets, $assemblyProbingPaths, $nowarn, $errorLogFilePath, $GenerateCrossReferences, $ReportSuppressedDiagnostics, $GenerateReportLayoutParam, $features, $preProcessorSymbols, $platformversion, $updateDependencies, $sourceRepositoryUrl, $sourceCommit, $buildBy, $buildUrl

if ($treatWarningsAsErrors) {
$regexp = ($treatWarningsAsErrors | ForEach-Object { if ($_ -eq '*') { ".*" } else { $_ } }) -join '|'
$result = $result | ForEach-Object { $_ -replace "^(.*)warning ($regexp):(.*)`$", '$1error $2:$3' }
Expand Down Expand Up @@ -755,7 +768,7 @@ try {
Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param($appSymbolsFolder, $appName)
$appFile = Join-Path -Path $appSymbolsFolder -ChildPath $appName
while (-not (Test-Path -Path $appFile)) { Start-Sleep -Seconds 1 }
} -ArgumentList $containerSymbolsFolder,"$($appName)"
} -ArgumentList $containerSymbolsFolder,"$($appName)"
}
}
}
Expand Down
Loading

0 comments on commit e932f36

Please sign in to comment.