From d4082e602cf238d9c2b7f87a0ae9bfe544df7abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Wed, 19 May 2021 22:57:46 +0300 Subject: [PATCH] more robust extract-and-generate --- Makefile | 8 +++++++- extract-and-generate | 25 ++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 690439f..7b4717d 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,12 @@ SLIDES = slides-2021-03-29.pdf NON_ARCHIVABLES = notes.txt referatui.txt slides-2021-03-29.txt ARCHIVABLES = $(filter-out $(NON_ARCHIVABLES),$(shell git ls-files .)) +ifeq ($(shell git rev-parse --is-inside-git-dir),true) +GIT_DEP=$(shell git rev-parse --show-toplevel)/.git +else +GIT_DEP= +endif + .PHONY: test test: tests.sql .faux.db ./db -f tests.sql @@ -64,7 +70,7 @@ $(SOURCE): wget http://download.geofabrik.de/europe/$@ REF = $(shell git describe --abbrev=12 --always --dirty) -version.tex: Makefile $(shell git rev-parse --show-toplevel)/.git +version.tex: Makefile $(GIT_DEP) ( \ TZ=UTC date '+\gdef\VCDescribe{%F ($(REF))}%'; \ ) > $@ diff --git a/extract-and-generate b/extract-and-generate index 2d97d49..e78656e 100755 --- a/extract-and-generate +++ b/extract-and-generate @@ -1,19 +1,15 @@ #!/bin/bash set -euo pipefail -fail() { - >&2 echo "$1" - exit 1 -} - dir=$(mktemp -d) +fname=mj-msc-all.pdf -echo "Extracting all files from the report ..." -pdfdetach -saveall -o "$dir" mj-msc-all.pdf +echo "Extracting all files from the report to $dir ..." +pdfdetach -saveall -o "$dir" "$fname" -echo "Re-generating the report..." +echo "Generating $dir/$fname..." fail=0 -make -C "$dir" -j $(nproc) mj-msc-all.pdf 2>&1 > make.log || fail=1 +make -C "$dir" -j $(nproc) "$fname" > "$dir/make.log" 2>&1 || fail=1 if [[ $fail == 1 ]]; then >&2 echo "Generation failed. Here are the last 10 log lines:" @@ -22,7 +18,10 @@ if [[ $fail == 1 ]]; then fi open=open -if [[ $(uname) == Linux ]] - open=xdg-open -fi -"$open" "$dir/mj-msc-all.pdf" +[[ $(uname) == Linux ]] && open=xdg-open + +echo "Opening $dir/$fname ..." +"$open" "$dir/$fname" + +echo "Editor has been closed. Removing $dir" +rm -fr "$dir"