Skip to content

Instantly share code, notes, and snippets.

@kyptin
Last active December 17, 2015 22:00
Show Gist options
  • Save kyptin/5679109 to your computer and use it in GitHub Desktop.
Save kyptin/5679109 to your computer and use it in GitHub Desktop.
Setup 3 levels of nested "checkout" projects for Leiningen, to demonstrate the (current) lack of a desired feature.
#!/bin/bash
# Referenced in Leiningen Issue #1190, here:
# https://github.com/technomancy/leiningen/issues/1190
if [ ! -z `ls -A | egrep -v '^(main|child|grandchild|greatgrandchild|setup-3level-lein-checkouts.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 greatgrandchild grandchild child main
echo "done."
echo -n "Setting up main, child, grandchild, greatgrandchild projects..."
lein new main >/dev/null
lein new child >/dev/null
lein new grandchild >/dev/null
lein new greatgrandchild >/dev/null
rm -f */.gitignore
rm -f */README.md
rm -fr */test/
rm -fr */doc/
echo '(defproject greatgrandchild "0.1.0")' > greatgrandchild/project.clj
echo '(defproject grandchild "0.1.0")' > grandchild/project.clj
echo '(defproject child "0.1.0")' > child/project.clj
cat > main/project.clj << PROJECT
(defproject main "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]])
PROJECT
mkdir grandchild/checkouts
( cd grandchild/checkouts ; ln -sf ../../greatgrandchild greatgrandchild )
mkdir child/checkouts
( cd child/checkouts ; ln -sf ../../grandchild grandchild )
mkdir main/checkouts
( cd main/checkouts ; ln -sf ../../child child )
cat > greatgrandchild/src/greatgrandchild/core.clj << CODE
(ns greatgrandchild.core)
(defn square [n] (* n n))
CODE
cat > grandchild/src/grandchild/core.clj << CODE
(ns grandchild.core (:require [greatgrandchild.core :as ggc]))
(defn squares [n] (map ggc/square (range n)))
CODE
cat > child/src/child/core.clj << CODE
(ns child.core (:require [grandchild.core :as gc]))
(defn inc-squares [n] (map inc (gc/squares n)))
CODE
cat > main/src/main/core.clj << CODE
(ns main.core (:require [child.core]))
(defn foo [n] (map + (child/inc-squares n) (range n)))
CODE
echo "done."
cat <<OUTPUT
Run the following commands to prove that second-level checkouts
(i.e. "grandchild" checkouts) DO work:
bash $ cd child/
bash $ lein repl
user=> (use 'child.core)
user=> (inc-squares 5)
user=> (exit)
bash $ cd ..
Run the following commands to prove that third-level checkouts
(i.e. "greatgrandchild" checkouts) do NOT work:
bash $ cd main/
bash $ lein repl
user=> (use 'main.core) ; <= This should work, but doesn't.
user=> (foo 5) ; <= So then this can't work either.
user=> (exit)
bash $ cd ..
OUTPUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment