Skip to content

Instantly share code, notes, and snippets.

@kyptin
Last active December 17, 2015 08:09
Show Gist options
  • Save kyptin/5578301 to your computer and use it in GitHub Desktop.
Save kyptin/5578301 to your computer and use it in GitHub Desktop.
Setup nested "checkout" projects for Leiningen, to demonstrate the (current) lack of a desired feature.
#!/bin/bash
# Referenced in Leiningen Issue #1180, here:
# https://github.com/technomancy/leiningen/issues/1180
if [ ! -z `ls -A | egrep -v '^(main|child|grandchild|setup-nested-lein-projects.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 grandchild child main
echo "done."
echo -n "Setting up main, child, and grandchild projects..."
lein new main >/dev/null
lein new child >/dev/null
lein new grandchild >/dev/null
rm -f */.gitignore
rm -f */README.md
rm -fr */test/
rm -fr */doc/
cat > grandchild/project.clj << PROJECT
(defproject grandchild "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]])
PROJECT
cat > child/project.clj << PROJECT
(defproject child "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]])
PROJECT
cat > main/project.clj << PROJECT
(defproject main "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]])
PROJECT
cat > grandchild/src/grandchild/core.clj << CODE
(ns grandchild.core)
(defn my-map [f coll] (map f coll))
CODE
mkdir child/checkouts
( cd child/checkouts ; ln -sf ../../grandchild grandchild )
cat > child/src/child/core.clj << CODE
(ns child.core (:require [grandchild.core :refer [my-map]]))
(defn my-fn [n] (my-map inc (range n)))
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 [n] (map #(* % %) (my-fn n)))
CODE
echo "done."
cat <<OUTPUT
You can run the following commands to prove that the single-level checkout
system (i.e. "child" checkouts) works correctly:
bash $ cd child/
bash $ lein repl
user=> (use 'child.core)
user=> (my-fn 5)
user=> (exit)
bash $ cd ..
Or run the following commands to prove that the two-level checkout system
(i.e. "grandchild" 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