Skip to content

Instantly share code, notes, and snippets.

@bdollard
Last active December 17, 2015 22:09
Show Gist options
  • Save bdollard/5679633 to your computer and use it in GitHub Desktop.
Save bdollard/5679633 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Referenced in Leiningen Issue #1191, here:
# https://github.com/technomancy/leiningen/issues/1191
if [ ! -z `ls -A | egrep -v '^(main|child|setup.sh)$'` ]; then
echo "Cowardly refusing to continue in a directory with unrecognized files."
exit 0
fi
echo -n "Removing any stale projects from previous runs..."
rm -fr child main
echo "done."
echo -n "Setting up main and child projects..."
lein new main >/dev/null
lein new child >/dev/null
rm -f */.gitignore
rm -f */README.md
rm -fr */test/
rm -fr */doc/
cat > child/project.clj << PROJECT
(defproject child "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]]
:aot [child.MyCustomException])
PROJECT
cat > main/project.clj << PROJECT
(defproject main "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]]
:aot [child.MyCustomException])
PROJECT
cat > child/src/child/core.clj << CODE
(ns child.core (:import child.MyCustomException))
(defn my-fn [] (throw (MyCustomException.)))
CODE
cat > child/src/child/MyCustomException.clj << CODE
(ns child.MyCustomException
(:gen-class :extends java.lang.RuntimeException))
CODE
mkdir main/checkouts
( cd main/checkouts ; ln -sf ../../child child )
cat > main/src/main/core.clj << CODE
(ns main.core (:require [child.core :refer [my-fn]]))
(defn foo []
(try
(my-fn)
(catch Exception e
(str "caught exception of class " (type e)))))
CODE
echo "done."
cat <<OUTPUT
Or run the following commands to prove that AOT compilation does not run
recursively on checkouts:
bash $ cd main/
bash $ lein repl
user=> (use 'main.core) ; <= This should work, but doesn't.
user=> (foo) ; <= So then this can't work either.
user=> (exit)
bash $ cd checkouts/child
bash $ lein repl ; <= child.MyCustomExecption gets compiled now
user=> (use 'child.core) ; <= This works fine because child.MyCustomException
; has now been compiled
user=> (my-fn) ; <= MyCustomException get thrown as expected
user=> (exit)
bash $ cd ../..
bash $ lein repl
user=> (use 'main.core) ; <= This works now because child.MyCustomException
; was compiled above and the class file hasn't
; been removed (by running 'lein clean' for
; example)
user=> (foo) ; <= returns "caught exception of class
; child.MyCustomException" as expected
bash $ cd ..
OUTPUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment