Updated build script
This commit is contained in:
parent
7468dce444
commit
30a0c7a782
108
build.sh
108
build.sh
@ -1,21 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This script builds every document in this repo,
|
||||
# (handout and solutions, if they exist), and creates
|
||||
# a zip of all resulting files.
|
||||
|
||||
|
||||
|
||||
# Where we're running this script
|
||||
run_dir=$(pwd)
|
||||
target="output"
|
||||
|
||||
rm -drf "${target}"
|
||||
rm -f "output.zip"
|
||||
# Output files
|
||||
target_dir="${run_dir}/output"
|
||||
target_zip="${run_dir}/output.zip"
|
||||
|
||||
|
||||
|
||||
|
||||
# Clean up previous build
|
||||
rm -drf "${target_dir}"
|
||||
rm -f "${target_zip}"
|
||||
|
||||
|
||||
# Build one document.
|
||||
# Args: <target_dir> <job_name> <doc_dir> <main_file>
|
||||
# target_dir: move output pdf to this directory
|
||||
# job_name: name of this document. Output is saved as job_name.pdf
|
||||
# doc_dir: cd here before building.
|
||||
# main_file: build this tex file. Usually main.tex
|
||||
function build() {
|
||||
local doc_dir="$(dirname "${1}")"
|
||||
local main_file="$(basename "${1}")"
|
||||
local job_name="$(basename "${doc_dir}")"
|
||||
local target_dir="${1}"
|
||||
local job_name="${2}"
|
||||
local doc_dir="${3}"
|
||||
local main_file="${4}"
|
||||
|
||||
echo "|> Building ${job_name}..."
|
||||
cd "${doc_dir}"
|
||||
|
||||
|
||||
# Build handout
|
||||
echo "\\def\\argNoSolutions{1}\\input{main.tex}" | \
|
||||
echo "\\def\\argNoSolutions{1}\\input{${main_file}}" | \
|
||||
tectonic \
|
||||
--outfmt pdf \
|
||||
--chatter minimal \
|
||||
@ -24,8 +47,10 @@ function build() {
|
||||
stat=$?
|
||||
|
||||
if [[ $stat == 0 ]]; then
|
||||
mv texput.pdf "${OUTPUT}/${job_name}.pdf"
|
||||
mkdir -p "${target_dir}"
|
||||
mv texput.pdf "${target_dir}/${job_name}.pdf"
|
||||
else
|
||||
rmdir --ignore-fail-on-non-empty "${target_dir}"
|
||||
rm -f texput.pdf
|
||||
echo "|> Handout build failed"
|
||||
echo ""
|
||||
@ -33,7 +58,7 @@ function build() {
|
||||
|
||||
|
||||
# Build solutions
|
||||
echo "\\def\\argYesSolutions{1}\\input{main.tex}" | \
|
||||
echo "\\def\\argYesSolutions{1}\\input{${main_file}}" | \
|
||||
tectonic \
|
||||
--outfmt pdf \
|
||||
--chatter minimal \
|
||||
@ -42,39 +67,62 @@ function build() {
|
||||
stat=$?
|
||||
|
||||
if [[ $stat == 0 ]]; then
|
||||
mv texput.pdf "${OUTPUT}/${job_name}.sols.pdf"
|
||||
echo ""
|
||||
mkdir -p "${target_dir}"
|
||||
mv texput.pdf "${target_dir}/${job_name}.sols.pdf"
|
||||
else
|
||||
rmdir --ignore-fail-on-non-empty "${target_dir}"
|
||||
rm -f texput.pdf
|
||||
echo "|> Solution build failed"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Clean up if files contents are identical
|
||||
if cmp --silent -- "${target_dir}/${job_name}.sols.pdf" "${target_dir}/${job_name}.pdf"; then
|
||||
echo "|> Versions identical, removing ${job_name}.sols.pdf"
|
||||
rm "${target_dir}/${job_name}.sols.pdf"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
cd "${run_dir}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for d in ./Advanced/*/ ; do
|
||||
doc_dir=$(realpath "${d}")
|
||||
OUTPUT="${run_dir}/${target}/Advanced"
|
||||
mkdir -p "${OUTPUT}"
|
||||
|
||||
build "${doc_dir}/main.tex"
|
||||
|
||||
for d in "${run_dir}/Misc/Warm-Ups"/*.tex ; do
|
||||
file="$(basename "${d}")"
|
||||
build \
|
||||
"${target_dir}/Warm-Ups" \
|
||||
"${file%.*}" \
|
||||
"${run_dir}/Misc/Warm-Ups" \
|
||||
"${file}"
|
||||
done
|
||||
|
||||
for d in "${run_dir}/Advanced"/*/ ; do
|
||||
doc_dir=$(realpath "${d}")
|
||||
job_name="$(basename "${doc_dir}")"
|
||||
|
||||
build \
|
||||
"${target_dir}/Advanced" \
|
||||
"${job_name}" \
|
||||
"${doc_dir}" \
|
||||
"main.tex"
|
||||
done
|
||||
|
||||
for d in "${run_dir}/Intermediate"/*/ ; do
|
||||
doc_dir=$(realpath "${d}")
|
||||
job_name="$(basename "${doc_dir}")"
|
||||
|
||||
build \
|
||||
"${target_dir}/Intermediate" \
|
||||
"${job_name}" \
|
||||
"${doc_dir}" \
|
||||
"main.tex"
|
||||
done
|
||||
|
||||
|
||||
for d in ./Intermediate/*/ ; do
|
||||
doc_dir=$(realpath "${d}")
|
||||
OUTPUT="${run_dir}/${target}/Intermediate"
|
||||
mkdir -p "${OUTPUT}"
|
||||
|
||||
build "${doc_dir}/main.tex"
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
cd "${target}"
|
||||
zip -FSr ../output.zip .
|
||||
# cd so paths in zip are relative
|
||||
cd "${target_dir}"
|
||||
zip -FSr "${target_zip}" .
|
Loading…
x
Reference in New Issue
Block a user