Skip to content

Instantly share code, notes, and snippets.

@np
Created August 1, 2013 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save np/6135273 to your computer and use it in GitHub Desktop.
Save np/6135273 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Walk-through (without changing the configuration):
# $ mkdir ~/.agda-pkg
# $ cd ~/.agda-pkg
# $ mkdir github patchtag
# $ darcs get --lazy http://www.cse.chalmers.se/~nad/repos/lib/ stdlib
# $ mkdir github/crypto-agda
# $ cd github/crypto-agda
# $ git clone https://github.com/crypto-agda/agda-nplib
# $ git clone https://github.com/crypto-agda/explore
# $ git clone https://github.com/crypto-agda/crypto-agda
# $ cd crypto-agda
# $ agda-pkg -i. -pstdlib -pcrypto-agda/agda-nplib -pcrypto-agda/explore crypto-agda.agda
# This will pick the right include directives for you (-i<dir>)
set -e
# $XDG_DATA_HOME ?
AGDA_PKG_ROOT="$HOME/.agda-pkg"
# You might want to tweak those to reflect your own directory organisation
AGDA_PKG_STDLIB="$AGDA_PKG_ROOT/stdlib"
AGDA_PKG_GITHUB_ROOT="$AGDA_PKG_ROOT/github"
AGDA_PKG_PATCHTAG_ROOT="$AGDA_PKG_ROOT/patchtag"
# You can override those config variables through a simple script
# to be sourced.
for conf in "$HOME"/.agda-pkg/config \
"$XDG_CONFIG_HOME"/agda-pkg/config \
/etc/agda-pkg/config; do
if [ -e "$conf" ]; then
. "$conf"
break
fi
done
# TODO: Deal with customization specifically for those
AGDA_PKG_SUBDIRS=(lib src .)
AGDA_PKG_SUBROOTS=("$AGDA_PKG_GITHUB_ROOT" "$AGDA_PKG_PATCHTAG_ROOT")
pkgdir(){
local pkg="$1"
case "$1" in
(stdlib) echo "$AGDA_PKG_STDLIB"; return 0;;
esac
local fs=()
for root in "${AGDA_PKG_SUBROOTS[@]}"; do
local bpkg="$(basename "$pkg")"
local f="$root/$pkg/$bpkg.agda"
local fs=("${fs[@]}" "$f")
if [ -e "$f" ]; then
# TODO: read the subdir from special syntax in $f
# Default heuristic
for subdir in "${AGDA_PKG_SUBDIRS[@]}"; do
if [ -e "$root/$pkg/$subdir" ]; then
echo "$root/$pkg/$subdir"
return 0
fi
done
fi
done
echo "Could not find the package \`$pkg'. None of the following files exist:" >>/dev/stderr
for f in "${fs[@]}"; do
echo " $f" >>/dev/stderr
done
exit 1
}
# Let's parse -p<pkg> and --pkg=<pkg> flags
pkgs=()
args=()
for arg; do
case "$arg" in
(-p*) pkgs=("${pkgs[@]}" "${arg#-p}") ;;
(--pkg=*) pkgs=("${pkgs[@]}" "${arg#--pkg=}") ;;
(*) args=("${args[@]}" "$arg") ;;
esac
done
incl=()
for pkg in "${pkgs[@]}"; do
incl=("${incl[@]}" -i"$(pkgdir "$pkg")")
done
# Debugging
echo "args: ${args[@]}" >>/dev/stderr
echo "pkgs: ${pkgs[@]}" >>/dev/stderr
echo "incl: ${incl[@]}" >>/dev/stderr
echo agda "${incl[@]}" "${args[@]}" >>/dev/stderr
exec agda "${incl[@]}" "${args[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment