report: build only required figures

Introduces a intermediate derivation that can be imported into the
report derivation, which contains a string cmd that expands the fig
variable as needed.
This commit is contained in:
Rodrigo Arias 2020-11-11 19:03:02 +01:00
parent 9a7e59a076
commit 5333058741
4 changed files with 28 additions and 5 deletions

View File

@ -5,6 +5,7 @@
, busybox
, jq
, texlive
, sedReport
}:
let
# TODO: We can select only which elements we need from fig by using:
@ -13,15 +14,15 @@ let
# By now, we require all plots
figJSON = writeText "fig.json" (builtins.toJSON fig);
sedCmd = (import sedReport) fig;
in
stdenv.mkDerivation {
name = "report";
src = ./.;
buildInputs = [ jq texlive.combined.scheme-basic ];
buildPhase = ''
ls -l
sed -i -e "s:@fig\.nbody\.test@:$(jq -r .nbody.test ${figJSON}):g" report.tex
jq . ${figJSON}
${sedCmd}
cat report.tex
pdflatex report.tex -o report.pdf
# Run again to fix figure references
pdflatex report.tex -o report.pdf

View File

@ -14,8 +14,8 @@ time $t$ is measured, as shown in the figure \ref{fig:nbody.test}.
%
\begin{figure}[h]
\centering
\includegraphics[width=0.45\textwidth]{@fig.nbody.test@/scatter.png}
\includegraphics[width=0.45\textwidth]{@fig.nbody.test@/box.png}
\includegraphics[width=0.45\textwidth]{@fig.nbody.baseline@/scatter.png}
\includegraphics[width=0.45\textwidth]{@fig.nbody.baseline@/box.png}
\caption{Nbody times with varying block size}
\label{fig:nbody.test}
\end{figure}

19
garlic/sedReport.nix Normal file
View File

@ -0,0 +1,19 @@
{
stdenv
, fig
}:
stdenv.mkDerivation {
name = "report";
src = ./.;
buildPhase = ''
grep -o '@[^ @]*@' report.tex | sed 's/@//g' | sort -u > list
echo "fig:" > fun.nix
echo "'''" >> fun.nix
sed 's:\(^.*\)$:sed -i "s;@\1@;''${\1};g" report.tex:g' list >> fun.nix
echo "'''" >> fun.nix
'';
installPhase = ''
cp fun.nix $out
'';
}

View File

@ -181,6 +181,9 @@ let
report = callPackage ./garlic/report.nix {
fig = self.bsc.garlic.fig;
};
sedReport = callPackage ./garlic/sedReport.nix {
fig = self.bsc.garlic.fig;
};
# Use the configuration for the following target machine
targetMachine = self.garlic.machines.mn4;