[CmdletBinding()] param( [string]$TinyTeXBin = 'C:\Users\vince\Documents\Projects\Tools\LaTeX\TinyTeX\bin\windows', [string]$OutputDirectory, [switch]$SubmissionOnly, [string]$PythonExecutable = 'python' ) $ErrorActionPreference = 'Stop' $source = Join-Path $PSScriptRoot 'latex' $versionMatch = [regex]::Match((Get-Content (Join-Path $source 'TikZRefinery.tex') -Raw), '\\newcommand\{\\DocumentVersion\}\{(?\d+(?:\.\d+){2,3}(?:-[A-Za-z0-9]+(?:[.-][A-Za-z0-9]+)*)?)\}') if (!$versionMatch.Success) { throw 'Could not read the report version.' } $version = $versionMatch.Groups['version'].Value if (!$OutputDirectory) { $OutputDirectory = Join-Path $PSScriptRoot "../work/report-autobuild-$version" } $output = (New-Item -ItemType Directory -Path $OutputDirectory -Force).FullName & $PythonExecutable (Join-Path $PSScriptRoot 'update-diagram-index.py') --build-directory $output --record-sources if ($LASTEXITCODE -ne 0) { throw 'Could not record diagram build sources.' } $editions = @('TikZRefinerySubmission') if (!$SubmissionOnly) { $editions += 'TikZRefinery' } function Invoke-TeXTool { param([string]$Name, [string[]]$Arguments, [string]$Transcript) & (Join-Path $TinyTeXBin "$Name.exe") @Arguments >> $Transcript if ($LASTEXITCODE -ne 0) { throw "$Name failed. See $Transcript" } } $results = @("TikZRefinery report autobuild | Version $version") Push-Location $source try { foreach ($edition in $editions) { $editionOutput = (New-Item -ItemType Directory -Path (Join-Path $output $edition) -Force).FullName $transcript = Join-Path $editionOutput 'autobuild.log' Set-Content -LiteralPath $transcript -Value "Building $edition for report $version" $pdfArgs = @('-interaction=nonstopmode','-halt-on-error','-file-line-error', "-output-directory=$editionOutput", "$edition.tex") Invoke-TeXTool pdflatex $pdfArgs $transcript $oldBibInput = $env:BIBINPUTS Push-Location $editionOutput try { $env:BIBINPUTS = "$source;$oldBibInput" Invoke-TeXTool bibtex @($edition) $transcript Invoke-TeXTool makeindex @("$edition.idx") $transcript } finally { $env:BIBINPUTS = $oldBibInput Pop-Location } # The glossary uses no-index mode. Refresh the separate makeidx index # once the chapter page numbers have settled. foreach ($pass in 1..2) { Invoke-TeXTool pdflatex $pdfArgs $transcript } Push-Location $editionOutput try { Invoke-TeXTool makeindex @("$edition.idx") $transcript } finally { Pop-Location } Invoke-TeXTool pdflatex $pdfArgs $transcript Invoke-TeXTool pdflatex $pdfArgs $transcript $log = Join-Path $editionOutput "$edition.log" $badPattern = '(^!|undefined references|undefined citations|Citation .+ undefined|Reference .+ undefined|Rerun to get cross-references right|Label\(s\) may have changed|not found on input line)' if (Select-String -LiteralPath $log -Pattern $badPattern) { throw "Unresolved final diagnostics for $edition. See $transcript" } $results += "PASS $edition.pdf | TinyTeX, bibliography, index" } } finally { Pop-Location } $pdfName = "TikZRefinery-$version.pdf" $zipName = "TikZRefinery-$version.zip" $pdf = Join-Path $output $pdfName $zip = Join-Path $output $zipName Copy-Item -LiteralPath (Join-Path $output 'TikZRefinerySubmission/TikZRefinerySubmission.pdf') -Destination $pdf Compress-Archive -LiteralPath $pdf -DestinationPath $zip -Force Add-Type -AssemblyName System.IO.Compression.FileSystem $archive = [IO.Compression.ZipFile]::OpenRead($zip) try { $entry = $archive.GetEntry($pdfName) if ($archive.Entries.Count -ne 1 -or !$entry -or $entry.Length -ne (Get-Item -LiteralPath $pdf).Length) { throw 'The ZIP does not contain the expected versioned PDF.' } } finally { $archive.Dispose() } $results += "PASS $zipName | $((Get-Item -LiteralPath $zip).Length) bytes" $results += "ZIP contains $pdfName" $indexArgs = @((Join-Path $PSScriptRoot 'update-diagram-index.py'), '--build-directory', $output) if ($SubmissionOnly) { $indexArgs += '--submission-only' } & $PythonExecutable @indexArgs if ($LASTEXITCODE -ne 0) { throw 'Diagram index failed. Classify new figures and check final build records.' } $results += 'PASS diagram index | authored figures, classification and final page map' $results | Set-Content -LiteralPath (Join-Path $output 'build-result.txt') -Encoding utf8 $results