Add bundled report example

This commit is contained in:
Rodrigo Arias 2020-11-17 15:51:09 +01:00
parent fe0bd8b200
commit 33f6ae7e55
7 changed files with 92 additions and 30 deletions

31
garlic/bundleReport.nix Normal file
View File

@ -0,0 +1,31 @@
{
stdenv
, fig
}:
stdenv.mkDerivation {
name = "report.tar.gz";
src = ./report;
buildPhase = ''
pwd
ls -l
grep -o '@[^ @]*@' report.tex | sed 's/@//g' | sort -u > list
echo "fig:" > fun.nix
echo "'''" >> fun.nix
for line in $(cat list); do
localPath=$(echo $line | tr '.' '/')
echo "mkdir -p $localPath" >> fun.nix
echo "cp -r \''${$line}/* $localPath" >> fun.nix
echo "sed -i 's;@$line@;$localPath;g' report.tex" >> fun.nix
done
echo "'''" >> fun.nix
echo " ---------- this is the fun.nix -------------"
cat fun.nix
echo " --------------------------------------------"
'';
installPhase = ''
cp fun.nix $out
'';
}

View File

@ -8,27 +8,17 @@
, sedReport , sedReport
}: }:
let let
# TODO: We can select only which elements we need from fig by using:
# echo [ $(grep -o '@[^ @]*@' garlic/report.tex | sed 's/@//g') ]
# and them importing as valid nix lang.
# By now, we require all plots
figJSON = writeText "fig.json" (builtins.toJSON fig);
sedCmd = (import sedReport) fig; sedCmd = (import sedReport) fig;
in in
stdenv.mkDerivation { stdenv.mkDerivation {
name = "report"; name = "report.pdf";
src = ./.; src = ./report;
buildInputs = [ jq texlive.combined.scheme-basic ]; buildInputs = [ jq texlive.combined.scheme-basic ];
buildPhase = '' buildPhase = ''
${sedCmd} ${sedCmd}
cat report.tex make
pdflatex report.tex -o report.pdf
# Run again to fix figure references
pdflatex report.tex -o report.pdf
''; '';
installPhase = '' installPhase = ''
mkdir $out cp report.pdf $out
cp report.* $out
''; '';
} }

4
garlic/report/Makefile Normal file
View File

@ -0,0 +1,4 @@
all: 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] \begin{figure}[h]
\centering \centering
\includegraphics[width=0.45\textwidth]{@fig.nbody.baseline@/scatter.png} \includegraphics[width=0.45\textwidth]{@fig.nbody.small@/scatter.png}
\includegraphics[width=0.45\textwidth]{@fig.nbody.baseline@/box.png} \includegraphics[width=0.45\textwidth]{@fig.nbody.small@/box.png}
\caption{Nbody times with varying block size} \caption{Nbody times with varying block size}
\label{fig:nbody.test} \label{fig:nbody.test}
\end{figure} \end{figure}

28
garlic/reportTar.nix Normal file
View File

@ -0,0 +1,28 @@
{
stdenv
, fig
, writeText
, busybox
, jq
, texlive
, bundleReport
}:
let
genCmd = (import bundleReport) fig;
in
stdenv.mkDerivation {
name = "report.tar.gz";
src = ./report;
buildInputs = [ jq texlive.combined.scheme-basic ];
buildPhase = ''
${genCmd}
ls -ltR
cat report.tex
make
'';
installPhase = ''
cd ..
tar -czf $out report
'';
}

View File

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

View File

@ -186,10 +186,19 @@ let
report = callPackage ./garlic/report.nix { report = callPackage ./garlic/report.nix {
fig = bsc.garlic.fig; fig = bsc.garlic.fig;
}; };
sedReport = callPackage ./garlic/sedReport.nix { sedReport = callPackage ./garlic/sedReport.nix {
fig = bsc.garlic.fig; fig = bsc.garlic.fig;
}; };
bundleReport = callPackage ./garlic/bundleReport.nix {
fig = bsc.garlic.fig;
};
reportTar = callPackage ./garlic/reportTar.nix {
fig = bsc.garlic.fig;
};
# Use the configuration for the following target machine # Use the configuration for the following target machine
targetMachine = bsc.garlic.machines.mn4; targetMachine = bsc.garlic.machines.mn4;