summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authoralalazo <massimiliano.culpo@googlemail.com>2016-03-22 15:57:35 +0100
committeralalazo <massimiliano.culpo@googlemail.com>2016-03-22 15:57:35 +0100
commit6e847b7d76acf2fb6cda3ef251c311c011008d40 (patch)
tree60beafd21cc2f45a6acfbaa2de7301b3d98729a1 /bin
parent4b22c2406c163c83998de8938b5fefa18886057e (diff)
parente32eb7e990119288e0bbffe1786b5cd20547e0ad (diff)
downloadspack-6e847b7d76acf2fb6cda3ef251c311c011008d40.tar.gz
spack-6e847b7d76acf2fb6cda3ef251c311c011008d40.tar.bz2
spack-6e847b7d76acf2fb6cda3ef251c311c011008d40.tar.xz
spack-6e847b7d76acf2fb6cda3ef251c311c011008d40.zip
Merge branch 'develop' of https://github.com/LLNL/spack into qa/coding_standard
Conflicts: .travis.yml
Diffstat (limited to 'bin')
-rwxr-xr-xbin/sbang84
-rwxr-xr-xbin/spack8
2 files changed, 88 insertions, 4 deletions
diff --git a/bin/sbang b/bin/sbang
new file mode 100755
index 0000000000..ebfbe2e7a1
--- /dev/null
+++ b/bin/sbang
@@ -0,0 +1,84 @@
+#!/bin/bash
+#
+# `sbang`: Run scripts with long shebang lines.
+#
+# Many operating systems limit the length of shebang lines, making it
+# hard to use interpreters that are deep in the directory hierarchy.
+# `sbang` can run such scripts, either as a shebang interpreter, or
+# directly on the command line.
+#
+# Usage
+# -----------------------------
+# Suppose you have a script, long-shebang.sh, like this:
+#
+# 1 #!/very/long/path/to/some/interpreter
+# 2
+# 3 echo "success!"
+#
+# Invoking this script will result in an error on some OS's. On
+# Linux, you get this:
+#
+# $ ./long-shebang.sh
+# -bash: ./long: /very/long/path/to/some/interp: bad interpreter:
+# No such file or directory
+#
+# On Mac OS X, the system simply assumes the interpreter is the shell
+# and tries to run with it, which is likely not what you want.
+#
+#
+# `sbang` on the command line
+# -----------------------------
+# You can use `sbang` in two ways. The first is to use it directly,
+# from the command line, like this:
+#
+# $ sbang ./long-shebang.sh
+# success!
+#
+#
+# `sbang` as the interpreter
+# -----------------------------
+# You can also use `sbang` *as* the interpreter for your script. Put
+# `#!/bin/bash /path/to/sbang` on line 1, and move the original
+# shebang to line 2 of the script:
+#
+# 1 #!/bin/bash /path/to/sbang
+# 2 #!/long/path/to/real/interpreter with arguments
+# 3
+# 4 echo "success!"
+#
+# $ ./long-shebang.sh
+# success!
+#
+# On Linux, you could shorten line 1 to `#!/path/to/sbang`, but other
+# operating systems like Mac OS X require the interpreter to be a
+# binary, so it's best to use `sbang` as a `bash` argument.
+# Obviously, for this to work, `sbang` needs to have a short enough
+# path that *it* will run without hitting OS limits.
+#
+#
+# How it works
+# -----------------------------
+# `sbang` is a very simple bash script. It looks at the first two
+# lines of a script argument and runs the last line starting with
+# `#!`, with the script as an argument. It also forwards arguments.
+#
+
+# First argument is the script we want to actually run.
+script="$1"
+
+# Search the first two lines of script for interpreters.
+lines=0
+while read line && ((lines < 2)) ; do
+ if [[ "$line" = '#!'* ]]; then
+ interpreter="${line#\#!}"
+ fi
+ lines=$((lines+1))
+done < "$script"
+
+# Invoke any interpreter found, or raise an error if none was found.
+if [ -n "$interpreter" ]; then
+ exec $interpreter "$@"
+else
+ echo "error: sbang found no interpreter in $script"
+ exit 1
+fi
diff --git a/bin/spack b/bin/spack
index 93263217ac..31165bba9d 100755
--- a/bin/spack
+++ b/bin/spack
@@ -42,9 +42,9 @@ SPACK_EXTERNAL_LIBS = os.path.join(SPACK_LIB_PATH, "external")
sys.path.insert(0, SPACK_EXTERNAL_LIBS)
import warnings
-# Avoid warnings when nose is installed with the python exe being used to run
-# spack. Note this must be done after Spack's external libs directory is added
-# to sys.path.
+# Avoid warnings when nose is installed with the python exe being used to run
+# spack. Note this must be done after Spack's external libs directory is added
+# to sys.path.
with warnings.catch_warnings():
warnings.filterwarnings("ignore", ".*nose was already imported")
import nose
@@ -62,7 +62,7 @@ for pyc_file in orphaned_pyc_files:
try:
os.remove(pyc_file)
except OSError as e:
- print "WARNING: Spack may fail mysteriously. Couldn't remove orphaned .pyc file: %s" % pyc
+ print "WARNING: Spack may fail mysteriously. Couldn't remove orphaned .pyc file: %s" % pyc_file
# If there is no working directory, use the spack prefix.
try: