brew-install 这是什么jiba命名方法...
这个名字上看是 mac上的安装工具,实际上是 mac linux上都支持的打包了几个 散装库tools.cli tool.deps ...
https://github.com/clojure/brew-install
初学clojure 构建工具lein 天下无双. (推荐)
clojure 自己出的这个构建工具,一个是随意,一个是封闭(很难贡献, lein有375个 贡献者brewinstall 10个贡献者 2021年10月26日10:16:50 ) ,一个散, 这个项目写点,哪个项目写点,感觉有点独夫( clojure 正式项目,封闭点也可以,但这种周边的构建工具, 要么自己重视起来,写好,要吗 支持 lein boot 这种成熟的工具.)
今天在阅读 clojure linux 执行脚本的时候,被这个项目的打包方式组合方式伤到了.. 为clojure 深感痛心.
2021年10月26日14:37:24 研究了下, 感觉clojure还是有点优点. 例如直接调用git库里的项目 . 先 取消发布该文章吧
linux-install-1.10.3.986.sh linux-install-1.10.1.561.sh 变化相当大.
1.10.3 又加了个 io.github.clojure/tools.tools 库
clojure deps github 库 下载位置 /root/.gitlibs/
/root/.gitlibs/_repos/github.com/clojure/tools.tools
GITLIBS - the path to the gitlibs storage directory (default = ~/.gitlibs)
https://clojure.org/reference/deps_and_cli
相关项目和文件


linux-install-1.10.3.986.sh
#!/usr/bin/env bash
set -euo pipefail
# Start
do_usage() {
echo "Installs the Clojure command line tools."
echo -e
echo "Usage:"
echo "linux-install.sh [-p|--prefix <dir>]"
exit 1
}
default_prefix_dir="/usr/local"
# use getopt if the number of params grows
prefix_dir=$default_prefix_dir
prefix_param=${1:-}
prefix_value=${2:-}
if [[ "$prefix_param" = "-p" || "$prefix_param" = "--prefix" ]]; then
if [[ -z "$prefix_value" ]]; then
do_usage
else
prefix_dir="$prefix_value"
fi
fi
echo "Downloading and expanding tar"
curl -O https://download.clojure.org/install/clojure-tools-1.10.3.986.tar.gz
tar xzf clojure-tools-1.10.3.986.tar.gz
lib_dir="$prefix_dir/lib"
bin_dir="$prefix_dir/bin"
man_dir="$prefix_dir/share/man/man1"
clojure_lib_dir="$lib_dir/clojure"
echo "Installing libs into $clojure_lib_dir"
install -Dm644 clojure-tools/deps.edn "$clojure_lib_dir/deps.edn"
install -Dm644 clojure-tools/example-deps.edn "$clojure_lib_dir/example-deps.edn"
install -Dm644 clojure-tools/tools.edn "$clojure_lib_dir/tools.edn"
install -Dm644 clojure-tools/exec.jar "$clojure_lib_dir/libexec/exec.jar"
install -Dm644 clojure-tools/clojure-tools-1.10.3.986.jar "$clojure_lib_dir/libexec/clojure-tools-1.10.3.986.jar"
echo "Installing clojure and clj into $bin_dir"
sed -i -e 's@PREFIX@'"$clojure_lib_dir"'@g' clojure-tools/clojure
sed -i -e 's@BINDIR@'"$bin_dir"'@g' clojure-tools/clj
install -Dm755 clojure-tools/clojure "$bin_dir/clojure"
install -Dm755 clojure-tools/clj "$bin_dir/clj"
echo "Installing man pages into $man_dir"
install -Dm644 clojure-tools/clojure.1 "$man_dir/clojure.1"
install -Dm644 clojure-tools/clj.1 "$man_dir/clj.1"
echo "Removing download"
rm -rf clojure-tools
rm -rf clojure-tools-1.10.3.986.tar.gz
echo "Use clj -h for help."
clojure 调用脚本
#!/usr/bin/env bash
set -e
install_dir=PREFIX
version=${project.version}
function join { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
# Extract opts
print_classpath=false
describe=false
verbose=false
trace=false
force=false
repro=false
tree=false
pom=false
help=false
prep=false
jvm_opts=()
resolve_aliases=()
classpath_aliases=()
repl_aliases=()
mode="repl"
while [ $# -gt 0 ]
do
case "$1" in
-version)
>&2 echo "Clojure CLI version $version"
exit 0
;;
--version)
echo "Clojure CLI version $version"
exit 0
;;
-J*)
jvm_opts+=("${1:2}")
shift
;;
-R*)
resolve_aliases+=("${1:2}")
shift
>&2 echo "-R is deprecated, use -A with repl, -M for main, or -X for exec"
;;
-C*)
classpath_aliases+=("${1:2}")
shift
>&2 echo "-C is deprecated, use -A with repl, -M for main, or -X for exec"
;;
-O*)
>&2 echo "-O is no longer supported, use -A with repl, -M for main, or -X for exec"
exit 1
;;
-A)
>&2 echo "-A requires an alias"
exit 1
;;
-A*)
repl_aliases+=("${1:2}")
shift
;;
-M)
mode="main"
shift
break
;;
-M*)
mode="main"
main_aliases="${1:2}"
shift
break
;;
-X)
mode="exec"
shift
break
;;
-X*)
mode="exec"
exec_aliases="${1:2}"
shift
break
;;
-T:*)
mode="tool"
tool_aliases="${1:2}"
shift
break
;;
-T*)
mode="tool"
tool_name="${1:2}"
shift
break
;;
-T)
mode="tool"
shift
break
;;
-P)
prep=true
shift
;;
-Sdeps)
shift
deps_data="${1}"
shift
;;
-Scp)
shift
force_cp="${1}"
shift
;;
-Spath)
print_classpath=true
shift
;;
-Sverbose)
verbose=true
shift
;;
-Sthreads)
shift
threads="${1}"
shift
;;
-Strace)
trace=true
shift
;;
-Sdescribe)
describe=true
shift
;;
-Sforce)
force=true
shift
;;
-Srepro)
repro=true
shift
;;
-Stree)
tree=true
shift
;;
-Spom)
pom=true
shift
;;
-Sresolve-tags)
>&2 echo "Option changed, use: clj -X:deps git-resolve-tags"
exit 1
;;
-S*)
>&2 echo "Invalid option: $1"
exit 1
;;
-h|--help|"-?")
if [[ -n "$main_aliases" ]] || [[ ${#repl_aliases[@]} -gt 0 ]]; then
break
else
help=true
shift
fi
;;
--)
shift
break
;;
*)
break
;;
esac
done
# Find java executable
set +e
JAVA_CMD=${JAVA_CMD:-$(type -p java)}
set -e
if [[ -z "$JAVA_CMD" ]]; then
if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
JAVA_CMD="$JAVA_HOME/bin/java"
else
>&2 echo "Couldn't find 'java'. Please set JAVA_HOME."
exit 1
fi
fi
if "$help"; then
cat <<-END
Version: $version
You use the Clojure tools ('clj' or 'clojure') to run Clojure programs
on the JVM, e.g. to start a REPL or invoke a specific function with data.
The Clojure tools will configure the JVM process by defining a classpath
(of desired libraries), an execution environment (JVM options) and
specifying a main class and args.
Using a deps.edn file (or files), you tell Clojure where your source code
resides and what libraries you need. Clojure will then calculate the full
set of required libraries and a classpath, caching expensive parts of this
process for better performance.
The internal steps of the Clojure tools, as well as the Clojure functions
you intend to run, are parameterized by data structures, often maps. Shell
command lines are not optimized for passing nested data, so instead you
will put the data structures in your deps.edn file and refer to them on the
command line via 'aliases' - keywords that name data structures.
'clj' and 'clojure' differ in that 'clj' has extra support for use as a REPL
in a terminal, and should be preferred unless you don't want that support,
then use 'clojure'.
Usage:
Start a REPL clj [clj-opt*] [-Aaliases] [init-opt*]
Exec fn(s) clojure [clj-opt*] -X[aliases] a/fn? [kpath v]* kv-map?
Run tool clojure [clj-opt*] -T[name|aliases] a/fn [kpath v] kv-map?
Run main clojure [clj-opt*] -M[aliases] [init-opt*] [main-opt] [arg*]
Prepare clojure [clj-opt*] -P [other exec opts]
exec-opts:
-Aaliases Use concatenated aliases to modify classpath
-X[aliases] Use concatenated aliases to modify classpath or supply exec fn/args
-T[toolname|aliases] Invoke tool by name or via aliases ala -X
-M[aliases] Use concatenated aliases to modify classpath or supply main opts
-P Prepare deps - download libs, cache classpath, but don't exec
clj-opts:
-Jopt Pass opt through in java_opts, ex: -J-Xmx512m
-Sdeps EDN Deps data to use as the last deps file to be merged
-Spath Compute classpath and echo to stdout only
-Spom Generate (or update) pom.xml with deps and paths
-Stree Print dependency tree
-Scp CP Do NOT compute or cache classpath, use this one instead
-Srepro Ignore the ~/.clojure/deps.edn config file
-Sforce Force recomputation of the classpath (don't use the cache)
-Sverbose Print important path info to console
-Sdescribe Print environment and command parsing info as data
-Sthreads Set specific number of download threads
-Strace Write a trace.edn file that traces deps expansion
-- Stop parsing dep options and pass remaining arguments to clojure.main
--version Print the version to stdout and exit
-version Print the version to stderr and exit
init-opt:
-i, --init path Load a file or resource
-e, --eval string Eval exprs in string; print non-nil values
--report target Report uncaught exception to "file" (default), "stderr", or "none"
main-opt:
-m, --main ns-name Call the -main function from namespace w/args
-r, --repl Run a repl
path Run a script from a file or resource
- Run a script from standard input
-h, -?, --help Print this help message and exit
Programs provided by :deps alias:
-X:deps mvn-install Install a maven jar to the local repository cache
-X:deps git-resolve-tags Resolve git coord tags to shas and update deps.edn
-X:deps find-versions Find available versions of a library
-X:deps prep Prepare all unprepped libs in the dep tree
For more info, see:
https://clojure.org/guides/deps_and_cli
https://clojure.org/reference/repl_and_main
END
exit 0
fi
# Set tools classpath used for the various programs before the user's program
tools_cp="$install_dir/libexec/clojure-tools-$version.jar"
# Determine user config directory
if [[ -n "$CLJ_CONFIG" ]]; then
config_dir="$CLJ_CONFIG"
elif [[ -n "$XDG_CONFIG_HOME" ]]; then
config_dir="$XDG_CONFIG_HOME/clojure"
else
config_dir="$HOME/.clojure"
fi
# If user config directory does not exist, create it
if [[ ! -d "$config_dir" ]]; then
mkdir -p "$config_dir"
fi
if [[ ! -e "$config_dir/deps.edn" ]]; then
cp "$install_dir/example-deps.edn" "$config_dir/deps.edn"
fi
if [ "$install_dir/tools.edn" -nt "$config_dir/tools/tools.edn" ]; then
mkdir -p "$config_dir/tools"
cp "$install_dir/tools.edn" "$config_dir/tools/tools.edn"
fi
# Determine user cache directory
if [[ -n "$CLJ_CACHE" ]]; then
user_cache_dir="$CLJ_CACHE"
elif [[ -n "$XDG_CACHE_HOME" ]]; then
user_cache_dir="$XDG_CACHE_HOME/clojure"
else
user_cache_dir="$config_dir/.cpcache"
fi
# Chain deps.edn in config paths. repro=skip config dir
config_project="deps.edn"
if "$repro"; then
config_paths=("$install_dir/deps.edn" "deps.edn")
else
config_user="$config_dir/deps.edn"
config_paths=("$install_dir/deps.edn" "$config_dir/deps.edn" "deps.edn")
fi
# Determine whether to use user or project cache
if [[ -f deps.edn ]]; then
cache_dir=.cpcache
else
cache_dir="$user_cache_dir"
fi
# Construct location of cached classpath file
val="$(join '' ${resolve_aliases[@]})|$(join '' ${classpath_aliases[@]})|$(join '' ${repl_aliases[@]})|$exec_aliases|$main_aliases|$deps_data|$tool_name|$tool_aliases"
for config_path in "${config_paths[@]}"; do
if [[ -f "$config_path" ]]; then
val="$val|$config_path"
else
val="$val|NIL"
fi
done
ck=$(echo "$val" | cksum | cut -d" " -f 1)
libs_file="$cache_dir/$ck.libs"
cp_file="$cache_dir/$ck.cp"
jvm_file="$cache_dir/$ck.jvm"
main_file="$cache_dir/$ck.main"
basis_file="$cache_dir/$ck.basis"
# Print paths in verbose mode
if "$verbose"; then
echo "version = $version"
echo "install_dir = $install_dir"
echo "config_dir = $config_dir"
echo "config_paths =" "${config_paths[@]}"
echo "cache_dir = $cache_dir"
echo "cp_file = $cp_file"
echo
fi
# Check for stale classpath file
stale=false
if "$force" || "$trace" || "$tree" || "$prep" || [ ! -f "$cp_file" ]; then
stale=true
elif [[ -n "$tool_name" ]] && [ "$config_dir/tools/$tool_name.edn" -nt "$cp_file" ]; then
stale=true
else
for config_path in "${config_paths[@]}"; do
if [ "$config_path" -nt "$cp_file" ]; then
stale=true
break
fi
done
fi
# Make tools args if needed
if "$stale" || "$pom"; then
tools_args=()
if [[ -n "$deps_data" ]]; then
tools_args+=("--config-data" "$deps_data")
fi
if [[ ${#resolve_aliases[@]} -gt 0 ]]; then
tools_args+=("-R$(join '' ${resolve_aliases[@]})")
fi
if [[ ${#classpath_aliases[@]} -gt 0 ]]; then
tools_args+=("-C$(join '' ${classpath_aliases[@]})")
fi
if [[ -n "$main_aliases" ]]; then
tools_args+=("-M$main_aliases")
fi
if [[ ${#repl_aliases[@]} -gt 0 ]]; then
tools_args+=("-A$(join '' ${repl_aliases[@]})")
fi
if [[ -n "$exec_aliases" ]]; then
tools_args+=("-X$exec_aliases")
fi
if [ "$mode" == "tool" ]; then
tools_args+=("--tool-mode")
fi
if [[ -n "$tool_name" ]]; then
tools_args+=("--tool-name" "$tool_name")
fi
if [[ -n "$tool_aliases" ]]; then
tools_args+=("-T$tool_aliases")
fi
if [[ -n "$force_cp" ]]; then
tools_args+=("--skip-cp")
fi
if [[ -n "$threads" ]]; then
tools_args+=("--threads" "$threads")
fi
if "$trace"; then
tools_args+=("--trace")
fi
if "$tree"; then
tools_args+=("--tree")
fi
fi
# If stale, run make-classpath to refresh cached classpath
if [[ "$stale" = true && "$describe" = false ]]; then
if "$verbose"; then
>&2 echo "Refreshing classpath"
fi
"$JAVA_CMD" -classpath "$tools_cp" clojure.main -m clojure.tools.deps.alpha.script.make-classpath2 --config-user "$config_user" --config-project "$config_project" --basis-file "$basis_file" --libs-file "$libs_file" --cp-file "$cp_file" --jvm-file "$jvm_file" --main-file "$main_file" "${tools_args[@]}"
fi
if "$describe"; then
cp=
elif [[ -n "$force_cp" ]]; then
cp="$force_cp"
else
cp=$(cat "$cp_file")
fi
if "$prep"; then
exit 0
elif "$pom"; then
exec "$JAVA_CMD" -classpath "$tools_cp" clojure.main -m clojure.tools.deps.alpha.script.generate-manifest2 --config-user "$config_user" --config-project "$config_project" --gen=pom "${tools_args[@]}"
elif "$print_classpath"; then
echo "$cp"
elif "$describe"; then
for config_path in "${config_paths[@]}"; do
if [[ -f "$config_path" ]]; then
path_vector="$path_vector\"$config_path\" "
fi
done
cat <<-END
{:version "$version"
:config-files [$path_vector]
:config-user "$config_user"
:config-project "$config_project"
:install-dir "$install_dir"
:config-dir "$config_dir"
:cache-dir "$cache_dir"
:force $force
:repro $repro
:main-aliases "$main_aliases"
:repl-aliases "${repl_aliases[@]}"}
END
elif "$tree"; then
exit 0
elif "$trace"; then
>&2 echo "Wrote trace.edn"
else
set -f
if [[ -e "$jvm_file" ]]; then
set +e
IFS=$'\n' read -ra jvm_cache_opts -d '' <"$jvm_file"
set -e
fi
if [ "$mode" == "tool" ] || [ "$mode" == "exec" ]; then
exec "$JAVA_CMD" "${jvm_cache_opts[@]}" "${jvm_opts[@]}" "-Dclojure.basis=$basis_file" -classpath "$cp:$install_dir/libexec/exec.jar" clojure.main -m clojure.run.exec "$@"
else
if [[ -e "$main_file" ]]; then
set +e
IFS=$'\n' read -ra main_cache_opts -d '' <"$main_file"
set -e
fi
if [ "$#" -gt 0 ] && [ "$mode" == "repl" ]; then
>&2 echo "WARNING: Implicit use of clojure.main with options is deprecated, use -M"
fi
exec "$JAVA_CMD" "${jvm_cache_opts[@]}" "${jvm_opts[@]}" "-Dclojure.basis=$basis_file" -classpath "$cp" clojure.main "${main_cache_opts[@]}" "$@"
fi
fi
lein的 脚本
https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
#!/usr/bin/env bash
# Ensure this file is executable via `chmod a+x lein`, then place it
# somewhere on your $PATH, like ~/bin. The rest of Leiningen will be
# installed upon first run into the ~/.lein/self-installs directory.
function msg {
echo "$@" 1>&2
}
export LEIN_VERSION="2.9.7"
# Must be sha256sum, will be replaced by bin/release
export LEIN_CHECKSUM='82f01414acecddbb0ebd6d571505bb671a6fd093236bcdac2468cfe5f2eaa802'
case $LEIN_VERSION in
*SNAPSHOT) SNAPSHOT="YES" ;;
*) SNAPSHOT="NO" ;;
esac
if [[ "$CLASSPATH" != "" ]]; then
cat <<-'EOS' 1>&2
WARNING: You have $CLASSPATH set, probably by accident.
It is strongly recommended to unset this before proceeding.
EOS
fi
if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
delimiter=";"
else
delimiter=":"
fi
if [[ "$OSTYPE" == "cygwin" ]]; then
cygwin=true
else
cygwin=false
fi
function command_not_found {
msg "Leiningen couldn't find $1 in your \$PATH ($PATH), which is required."
exit 1
}
function make_native_path {
# ensure we have native paths
if $cygwin && [[ "$1" == /* ]]; then
echo -n "$(cygpath -wp "$1")"
elif [[ "$OSTYPE" == "msys" && "$1" == /?/* ]]; then
echo -n "$(sh -c "(cd $1 2</dev/null && pwd -W) || echo $1 | sed 's/^\\/\([a-z]\)/\\1:/g'")"
else
echo -n "$1"
fi
}
# usage : add_path PATH_VAR [PATH]...
function add_path {
local path_var="$1"
shift
while [ -n "$1" ];do
# http://bashify.com/?Useful_Techniques:Indirect_Variables:Indirect_Assignment
if [[ -z ${!path_var} ]]; then
export ${path_var}="$(make_native_path "$1")"
else
export ${path_var}="${!path_var}${delimiter}$(make_native_path "$1")"
fi
shift
done
}
function download_failed_message {
cat <<-EOS 1>&2
Failed to download $1 (exit code $2)
It's possible your HTTP client's certificate store does not have the
correct certificate authority needed. This is often caused by an
out-of-date version of libssl. It's also possible that you're behind a
firewall and haven't set HTTP_PROXY and HTTPS_PROXY.
EOS
}
function checksum_failed_message {
cat <<-EOS 1>&2
Failed to properly download $1
The checksum was mismatched. and we could not verify the downloaded
file. We expected a sha256 of
$2 and actually had
$3.
We used '$SHASUM_CMD' to verify the downloaded file.
EOS
}
function self_install {
if [ -r "$LEIN_JAR" ]; then
cat <<-EOS 1>&2
The self-install jar already exists at $LEIN_JAR.
If you wish to re-download, delete it and rerun "$0 self-install".
EOS
exit 1
fi
msg "Downloading Leiningen to $LEIN_JAR now..."
mkdir -p "$(dirname "$LEIN_JAR")"
LEIN_URL="https://github.com/technomancy/leiningen/releases/download/$LEIN_VERSION/leiningen-$LEIN_VERSION-standalone.jar"
$HTTP_CLIENT "$LEIN_JAR.pending" "$LEIN_URL"
local exit_code=$?
if [ $exit_code == 0 ]; then
printf "$LEIN_CHECKSUM $LEIN_JAR.pending\n" > "$LEIN_JAR.pending.shasum"
$SHASUM_CMD -c "$LEIN_JAR.pending.shasum"
if [ $? == 0 ]; then
mv -f "$LEIN_JAR.pending" "$LEIN_JAR"
else
got_sum="$($SHASUM_CMD "$LEIN_JAR.pending" | cut -f 1 -d ' ')"
checksum_failed_message "$LEIN_URL" "$LEIN_CHECKSUM" "$got_sum"
rm "$LEIN_JAR.pending" 2> /dev/null
exit 1
fi
else
rm "$LEIN_JAR.pending" 2> /dev/null
download_failed_message "$LEIN_URL" "$exit_code"
exit 1
fi
}
NOT_FOUND=1
ORIGINAL_PWD="$PWD"
while [ ! -r "$PWD/project.clj" ] && [ "$PWD" != "/" ] && [ $NOT_FOUND -ne 0 ]
do
cd ..
if [ "$(dirname "$PWD")" = "/" ]; then
NOT_FOUND=0
cd "$ORIGINAL_PWD"
fi
done
export LEIN_HOME="${LEIN_HOME:-"$HOME/.lein"}"
for f in "/etc/leinrc" "$LEIN_HOME/leinrc" ".leinrc"; do
if [ -e "$f" ]; then
source "$f"
fi
done
if $cygwin; then
export LEIN_HOME=$(cygpath -w "$LEIN_HOME")
fi
LEIN_JAR="$LEIN_HOME/self-installs/leiningen-$LEIN_VERSION-standalone.jar"
# normalize $0 on certain BSDs
if [ "$(dirname "$0")" = "." ]; then
SCRIPT="$(which "$(basename "$0")")"
if [ -z "$SCRIPT" ]; then
SCRIPT="$0"
fi
else
SCRIPT="$0"
fi
# resolve symlinks to the script itself portably
while [ -h "$SCRIPT" ] ; do
ls=$(ls -ld "$SCRIPT")
link=$(expr "$ls" : '.*-> \(.*\)$')
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT="$(dirname "$SCRIPT"$)/$link"
fi
done
BIN_DIR="$(dirname "$SCRIPT")"
export LEIN_JVM_OPTS="${LEIN_JVM_OPTS-"-XX:+TieredCompilation -XX:TieredStopAtLevel=1"}"
# This needs to be defined before we call HTTP_CLIENT below
if [ "$HTTP_CLIENT" = "" ]; then
if type -p curl >/dev/null 2>&1; then
if [ "$https_proxy" != "" ]; then
CURL_PROXY="-x $https_proxy"
fi
HTTP_CLIENT="curl $CURL_PROXY -f -L -o"
else
HTTP_CLIENT="wget -O"
fi
fi
# This needs to be defined before we call SHASUM_CMD below
if [ "$SHASUM_CMD" = "" ]; then
if type -p sha256sum >/dev/null 2>&1; then
export SHASUM_CMD="sha256sum"
elif type -p shasum >/dev/null 2>&1; then
export SHASUM_CMD="shasum --algorithm 256"
elif type -p sha256 >/dev/null 2>&1; then
export SHASUM_CMD="sha256 -q"
else
command_not_found sha256sum
fi
fi
# When :eval-in :classloader we need more memory
grep -E -q '^\s*:eval-in\s+:classloader\s*$' project.clj 2> /dev/null && \
export LEIN_JVM_OPTS="$LEIN_JVM_OPTS -Xms64m -Xmx512m"
if [ -r "$BIN_DIR/../src/leiningen/version.clj" ]; then
# Running from source checkout
LEIN_DIR="$(cd $(dirname "$BIN_DIR");pwd -P)"
# Need to use lein release to bootstrap the leiningen-core library (for aether)
if [ ! -r "$LEIN_DIR/leiningen-core/.lein-bootstrap" ]; then
cat <<-'EOS' 1>&2
Leiningen is missing its dependencies.
Please run "lein bootstrap" in the leiningen-core/ directory
with a stable release of Leiningen. See CONTRIBUTING.md for details.
EOS
exit 1
fi
# If project.clj for lein or leiningen-core changes, we must recalculate
LAST_PROJECT_CHECKSUM=$(cat "$LEIN_DIR/.lein-project-checksum" 2> /dev/null)
PROJECT_CHECKSUM=$(sum "$LEIN_DIR/project.clj" "$LEIN_DIR/leiningen-core/project.clj")
if [ "$PROJECT_CHECKSUM" != "$LAST_PROJECT_CHECKSUM" ]; then
if [ -r "$LEIN_DIR/.lein-classpath" ]; then
rm "$LEIN_DIR/.lein-classpath"
fi
fi
# Use bin/lein to calculate its own classpath.
if [ ! -r "$LEIN_DIR/.lein-classpath" ] && [ "$1" != "classpath" ]; then
msg "Recalculating Leiningen's classpath."
cd "$LEIN_DIR"
LEIN_NO_USER_PROFILES=1 "$LEIN_DIR/bin/lein" classpath .lein-classpath
sum "$LEIN_DIR/project.clj" "$LEIN_DIR/leiningen-core/project.clj" > \
.lein-project-checksum
cd -
fi
mkdir -p "$LEIN_DIR/target/classes"
export LEIN_JVM_OPTS="$LEIN_JVM_OPTS -Dclojure.compile.path=$LEIN_DIR/target/classes"
add_path CLASSPATH "$LEIN_DIR/leiningen-core/src/" "$LEIN_DIR/leiningen-core/resources/" \
"$LEIN_DIR/test:$LEIN_DIR/target/classes" "$LEIN_DIR/src" ":$LEIN_DIR/resources"
if [ -r "$LEIN_DIR/.lein-classpath" ]; then
add_path CLASSPATH "$(cat "$LEIN_DIR/.lein-classpath" 2> /dev/null)"
else
add_path CLASSPATH "$(cat "$LEIN_DIR/leiningen-core/.lein-bootstrap" 2> /dev/null)"
fi
else # Not running from a checkout
add_path CLASSPATH "$LEIN_JAR"
if [ "$LEIN_USE_BOOTCLASSPATH" != "no" ]; then
LEIN_JVM_OPTS="-Xbootclasspath/a:$LEIN_JAR $LEIN_JVM_OPTS"
fi
if [ ! -r "$LEIN_JAR" -a "$1" != "self-install" ]; then
self_install
fi
fi
if [ ! -x "$JAVA_CMD" ] && ! type -f java >/dev/null
then
msg "Leiningen couldn't find 'java' executable, which is required."
msg "Please either set JAVA_CMD or put java (>=1.6) in your \$PATH ($PATH)."
exit 1
fi
export LEIN_JAVA_CMD="${LEIN_JAVA_CMD:-${JAVA_CMD:-java}}"
if [[ -z "${DRIP_INIT+x}" && "$(basename "$LEIN_JAVA_CMD")" == *drip* ]]; then
export DRIP_INIT="$(printf -- '-e\n(require (quote leiningen.repl))')"
export DRIP_INIT_CLASS="clojure.main"
fi
# Support $JAVA_OPTS for backwards-compatibility.
export JVM_OPTS="${JVM_OPTS:-"$JAVA_OPTS"}"
# Handle jline issue with cygwin not propagating OSTYPE through java subprocesses: https://github.com/jline/jline2/issues/62
cygterm=false
if $cygwin; then
case "$TERM" in
rxvt* | xterm* | vt*) cygterm=true ;;
esac
fi
if $cygterm; then
LEIN_JVM_OPTS="$LEIN_JVM_OPTS -Djline.terminal=jline.UnixTerminal"
stty -icanon min 1 -echo > /dev/null 2>&1
fi
# TODO: investigate http://skife.org/java/unix/2011/06/20/really_executable_jars.html
# If you're packaging this for a package manager (.deb, homebrew, etc)
# you need to remove the self-install and upgrade functionality or see lein-pkg.
if [ "$1" = "self-install" ]; then
if [ -r "$BIN_DIR/../src/leiningen/version.clj" ]; then
cat <<-'EOS' 1>&2
Running self-install from a checkout is not supported.
See CONTRIBUTING.md for SNAPSHOT-specific build instructions.
EOS
exit 1
fi
msg "Manual self-install is deprecated; it will run automatically when necessary."
self_install
elif [ "$1" = "upgrade" ] || [ "$1" = "downgrade" ]; then
if [ "$LEIN_DIR" != "" ]; then
msg "The upgrade task is not meant to be run from a checkout."
exit 1
fi
if [ $SNAPSHOT = "YES" ]; then
cat <<-'EOS' 1>&2
The upgrade task is only meant for stable releases.
See the "Bootstrapping" section of CONTRIBUTING.md.
EOS
exit 1
fi
if [ ! -w "$SCRIPT" ]; then
msg "You do not have permission to upgrade the installation in $SCRIPT"
exit 1
else
TARGET_VERSION="${2:-stable}"
echo "The script at $SCRIPT will be upgraded to the latest $TARGET_VERSION version."
echo -n "Do you want to continue [Y/n]? "
read RESP
case "$RESP" in
y|Y|"")
echo
msg "Upgrading..."
TARGET="/tmp/lein-${$}-upgrade"
if $cygwin; then
TARGET=$(cygpath -w "$TARGET")
fi
LEIN_SCRIPT_URL="https://github.com/technomancy/leiningen/raw/$TARGET_VERSION/bin/lein"
$HTTP_CLIENT "$TARGET" "$LEIN_SCRIPT_URL"
if [ $? == 0 ]; then
cmp -s "$TARGET" "$SCRIPT"
if [ $? == 0 ]; then
msg "Leiningen is already up-to-date."
fi
mv "$TARGET" "$SCRIPT" && chmod +x "$SCRIPT"
unset CLASSPATH
exec "$SCRIPT" version
else
download_failed_message "$LEIN_SCRIPT_URL"
fi;;
*)
msg "Aborted."
exit 1;;
esac
fi
else
if $cygwin; then
# When running on Cygwin, use Windows-style paths for java
ORIGINAL_PWD=$(cygpath -w "$ORIGINAL_PWD")
fi
# apply context specific CLASSPATH entries
if [ -f .lein-classpath ]; then
add_path CLASSPATH "$(cat .lein-classpath)"
fi
if [ -n "$DEBUG" ]; then
msg "Leiningen's classpath: $CLASSPATH"
fi
if [ -r .lein-fast-trampoline ]; then
export LEIN_FAST_TRAMPOLINE='y'
fi
if [ "$LEIN_FAST_TRAMPOLINE" != "" ] && [ -r project.clj ]; then
INPUTS="$* $(cat project.clj) $LEIN_VERSION $(test -f "$LEIN_HOME/profiles.clj" && cat "$LEIN_HOME/profiles.clj") $(test -f profiles.clj && cat profiles.clj)"
INPUT_CHECKSUM=$(echo "$INPUTS" | $SHASUM_CMD | cut -f 1 -d " ")
# Just don't change :target-path in project.clj, mkay?
TRAMPOLINE_FILE="target/trampolines/$INPUT_CHECKSUM"
else
if hash mktemp 2>/dev/null; then
# Check if mktemp is available before using it
TRAMPOLINE_FILE="$(mktemp /tmp/lein-trampoline-XXXXXXXXXXXXX)"
else
TRAMPOLINE_FILE="/tmp/lein-trampoline-$$"
fi
trap 'rm -f $TRAMPOLINE_FILE' EXIT
fi
if $cygwin; then
TRAMPOLINE_FILE=$(cygpath -w "$TRAMPOLINE_FILE")
fi
if [ "$INPUT_CHECKSUM" != "" ] && [ -r "$TRAMPOLINE_FILE" ]; then
if [ -n "$DEBUG" ]; then
msg "Fast trampoline with $TRAMPOLINE_FILE."
fi
exec sh -c "exec $(cat "$TRAMPOLINE_FILE")"
else
export TRAMPOLINE_FILE
"$LEIN_JAVA_CMD" \
-Dfile.encoding=UTF-8 \
-Dmaven.wagon.http.ssl.easy=false \
-Dmaven.wagon.rto=10000 \
$LEIN_JVM_OPTS \
-Dleiningen.input-checksum="$INPUT_CHECKSUM" \
-Dleiningen.original.pwd="$ORIGINAL_PWD" \
-Dleiningen.script="$SCRIPT" \
-classpath "$CLASSPATH" \
clojure.main -m leiningen.core.main "$@"
EXIT_CODE=$?
if $cygterm ; then
stty icanon echo > /dev/null 2>&1
fi
if [ -r "$TRAMPOLINE_FILE" ] && [ "$LEIN_TRAMPOLINE_WARMUP" = "" ]; then
TRAMPOLINE="$(cat "$TRAMPOLINE_FILE")"
if [ "$INPUT_CHECKSUM" = "" ]; then # not using fast trampoline
rm "$TRAMPOLINE_FILE"
fi
if [ "$TRAMPOLINE" = "" ]; then
exit $EXIT_CODE
else
exec sh -c "exec $TRAMPOLINE"
fi
else
exit $EXIT_CODE
fi
fi
fi
网友评论