|
4 | 4 | , ghostscript ? pkgs.ghostscript
|
5 | 5 | , ref ? null
|
6 | 6 | , doPdfGeneration ? true
|
| 7 | + # Attempts to render every page individually to make sure the dependencies |
| 8 | + # are set correctly. |
| 9 | +, doCheck ? true |
7 | 10 | # Checks whether the generated output matches the checked-in SSS32.ps.
|
8 | 11 | # When doing development you may want to shut this off to obtain the
|
9 | 12 | # output file that you need to check in.
|
| 13 | + # |
| 14 | + # Has no effect if doChecks is not set. |
10 | 15 | , doOutputDiff ? true
|
11 | 16 | }:
|
12 | 17 |
|
@@ -199,23 +204,50 @@ let
|
199 | 204 | %%EOF
|
200 | 205 | '';
|
201 | 206 | };
|
| 207 | + checkSinglePage = page: renderBooklet { |
| 208 | + name = "test-single-page.ps"; |
| 209 | + pages = [ page ]; |
| 210 | + }; |
202 | 211 | in
|
203 | 212 | stdenv.mkDerivation {
|
204 | 213 | name = "codex32${shortId}";
|
205 | 214 |
|
206 | 215 | nativeBuildInputs = if doPdfGeneration then [ ghostscript ] else [ ];
|
207 | 216 |
|
208 |
| - phases = [ "buildPhase" ]; |
| 217 | + phases = [ "buildPhase" ] ++ lib.optionals doCheck [ "checkPhase" ]; |
| 218 | + |
209 | 219 | buildPhase = ''
|
210 | 220 | set -e
|
211 | 221 |
|
| 222 | + FULL_BW="${renderBooklet fullBooklet}" |
| 223 | +
|
| 224 | + # Copy output Postscript into place |
212 | 225 | mkdir "$out"
|
213 | 226 | cd "$out"
|
214 |
| - ln -s ${renderBooklet fullBooklet} SSS32.ps |
215 |
| -
|
216 |
| - ${lib.optionalString doOutputDiff "diff -C 5 ${src}/SSS32.ps SSS32.ps"} |
| 227 | + ln -s "$FULL_BW" SSS32.ps |
| 228 | + # Patch to include version |
217 | 229 | sed -i 's/(revision \(.*\))/(revision \1${shortId})/' ./SSS32.ps
|
| 230 | + # Produce PDF, if requested. |
218 | 231 | ${lib.optionalString doPdfGeneration "ps2pdf -dPDFSETTINGS=/prepress SSS32.ps"}
|
219 | 232 | '';
|
| 233 | + |
| 234 | + checkPhase = toString |
| 235 | + (map |
| 236 | + (page: "ghostscriptTest ${checkSinglePage page}") |
| 237 | + fullBooklet.pages |
| 238 | + ) + '' |
| 239 | + ghostscriptTest() { |
| 240 | + echo "Ghostscript testing $1" |
| 241 | + local output; |
| 242 | + if ! output="$(gs -dNOPAUSE -dNODISPLAY "$1" < /dev/null 2>&1)"; then |
| 243 | + echo "Failed to run ghostscript on $1" |
| 244 | + echo "$output" |
| 245 | + exit 1 |
| 246 | + fi |
| 247 | + } |
| 248 | +
|
| 249 | + ghostscriptTest "$FULL_BW" |
| 250 | + ${lib.optionalString doOutputDiff "diff -C 5 ${src}/SSS32.ps SSS32.ps"} |
| 251 | + ''; |
220 | 252 | }
|
221 | 253 |
|
0 commit comments