Skip to content

Commit

Permalink
Import rbenv changes at 7e0e85b
Browse files Browse the repository at this point in the history
  • Loading branch information
yyuu committed Nov 30, 2014
1 parent fc8597c commit f0e8525
Show file tree
Hide file tree
Showing 20 changed files with 844 additions and 110 deletions.
5 changes: 4 additions & 1 deletion .gitignore
@@ -1,6 +1,9 @@
/build
/cache
/shims
/version
/versions
/sources
/cache
/libexec/*.dylib
/src/Makefile
/src/*.o
10 changes: 5 additions & 5 deletions .travis.yml
@@ -1,6 +1,6 @@
install: git clone --depth 1 https://github.com/sstephenson/bats.git
script: script/test
install: git clone https://github.com/sstephenson/bats.git
script: PATH="./bats/bin:$PATH" test/run && ( cd plugins/python-build bats ${CI:+--tap} test )
language: c
notifications:
email:
on_success: never
env:
- PYENV_NATIVE_EXT=
- PYENV_NATIVE_EXT=1
24 changes: 20 additions & 4 deletions libexec/pyenv
Expand Up @@ -12,6 +12,16 @@ if [ -n "$PYENV_DEBUG" ]; then
set -x
fi

if enable -f "${0%/*}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
abs_dirname() {
local path="$(realpath "$1")"
echo "${path%/*}"
}
else
if [ -n "$PYENV_NATIVE_EXT" ]; then
echo "pyenv: failed to load \`realpath' builtin" >&2
exit 1
fi
READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
Expand All @@ -37,6 +47,7 @@ abs_dirname() {
pwd
cd "$cwd"
}
fi

if [ -z "${PYENV_ROOT}" ]; then
PYENV_ROOT="${HOME}/.pyenv"
Expand All @@ -62,15 +73,20 @@ shopt -s nullglob

bin_path="$(abs_dirname "$0")"
for plugin_bin in "${PYENV_ROOT}/plugins/"*/bin; do
bin_path="${bin_path}:${plugin_bin}"
PATH="${plugin_bin}:${PATH}"
done
export PATH="${bin_path}:${PATH}"

hook_path="${PYENV_HOOK_PATH}:${PYENV_ROOT}/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks"
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${PYENV_ROOT}/pyenv.d"
if [ "${bin_path%/*}" != "$PYENV_ROOT" ]; then
# Add pyenv's own `pyenv.d` unless pyenv was cloned to PYENV_ROOT
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${bin_path%/*}/pyenv.d"
fi
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks"
for plugin_hook in "${PYENV_ROOT}/plugins/"*/etc/pyenv.d; do
hook_path="${hook_path}:${plugin_hook}"
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${plugin_hook}"
done
export PYENV_HOOK_PATH="$hook_path"
export PYENV_HOOK_PATH

shopt -u nullglob

Expand Down
2 changes: 1 addition & 1 deletion libexec/pyenv-exec
Expand Up @@ -18,7 +18,7 @@ set -e

# Provide pyenv completions
if [ "$1" = "--complete" ]; then
exec pyenv shims --short
exec pyenv-shims --short
fi

PYENV_VERSION="$(pyenv-version-name)"
Expand Down
8 changes: 7 additions & 1 deletion libexec/pyenv-hooks
Expand Up @@ -19,6 +19,11 @@ if [ -z "$PYENV_COMMAND" ]; then
exit 1
fi

if ! enable -f "${BASH_SOURCE%/*}"/pyenv-realpath.dylib realpath 2>/dev/null; then
if [ -n "$PYENV_NATIVE_EXT" ]; then
echo "pyenv: failed to load \`realpath' builtin" >&2
exit 1
fi
READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
Expand All @@ -42,13 +47,14 @@ realpath() {
echo "$(pwd)/$name"
cd "$cwd"
}
fi

IFS=: hook_paths=($PYENV_HOOK_PATH)

shopt -s nullglob
for path in "${hook_paths[@]}"; do
for script in "$path/$PYENV_COMMAND"/*.bash; do
echo $(realpath $script)
realpath "$script"
done
done
shopt -u nullglob
39 changes: 3 additions & 36 deletions libexec/pyenv-init
Expand Up @@ -28,31 +28,7 @@ if [ -z "$shell" ]; then
shell="$(basename "${shell:-$SHELL}")"
fi

READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
fi

resolve_link() {
$READLINK "$1"
}

abs_dirname() {
local cwd="$(pwd)"
local path="$1"

while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done

pwd
cd "$cwd"
}

root="$(abs_dirname "$0")/.."
root="${0%/*}/.."

if [ -z "$print" ]; then
case "$shell" in
Expand Down Expand Up @@ -92,22 +68,13 @@ fi

mkdir -p "${PYENV_ROOT}/"{shims,versions}

if [[ ":${PATH}:" != *:"${PYENV_ROOT}/shims":* ]]; then
case "$shell" in
fish )
echo "setenv PATH '${PYENV_ROOT}/shims' \$PATH"
;;
* )
echo 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
;;
esac
fi

case "$shell" in
fish )
echo "setenv PATH '${PYENV_ROOT}/shims' \$PATH"
echo "setenv PYENV_SHELL $shell"
;;
* )
echo 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
echo "export PYENV_SHELL=$shell"
;;
esac
Expand Down
60 changes: 25 additions & 35 deletions libexec/pyenv-rehash
Expand Up @@ -70,49 +70,47 @@ SH
# of the first shim in the shims directory, assume pyenv has been
# upgraded and the existing shims need to be removed.
remove_outdated_shims() {
for shim in *; do
local shim
for shim in "$SHIM_PATH"/*; do
if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/dev/null 2>&1; then
for shim in *; do rm -f "$shim"; done
rm -f "$SHIM_PATH"/*
fi
break
done
}

# List basenames of executables for every Python version
list_executable_names() {
local file
for file in "$PYENV_ROOT"/versions/*/bin/*; do
echo "${file##*/}"
done
}

# The basename of each argument passed to `make_shims` will be
# registered for installation as a shim. In this way, plugins may call
# `make_shims` with a glob to register many shims at once.
make_shims() {
local shims=("$@")

for file in "${shims[@]}"; do
local shim="${file##*/}"
local file shim
for file; do
shim="${file##*/}"
register_shim "$shim"
done
}

# Create an empty array for the list of registered shims and an empty
# string to use as a search index.
registered_shims=()
registered_shims_index=""
registered_shims=" "

# We will keep track of shims registered for installation with the
# global `registered_shims` array and with a global search index
# string. The array will let us iterate over all registered shims. The
# index string will let us quickly check whether a shim with the given
# name has been registered or not.
# Registers the name of a shim to be generated.
register_shim() {
local shim="$@"
registered_shims["${#registered_shims[@]}"]="$shim"
registered_shims_index="$registered_shims_index/$shim/"
registered_shims="${registered_shims}${1} "
}

# To install all the registered shims, we iterate over the
# `registered_shims` array and create a link if one does not already
# exist.
# Install all the shims registered via `make_shims` or `register_shim` directly.
install_registered_shims() {
local shim
for shim in "${registered_shims[@]}"; do
[ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim"
local shim file
for shim in $registered_shims; do
file="${SHIM_PATH}/${shim}"
[ -e "$file" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$file"
done
}

Expand All @@ -122,26 +120,21 @@ install_registered_shims() {
# removed.
remove_stale_shims() {
local shim
for shim in *; do
if [[ "$registered_shims_index" != *"/$shim/"* ]]; then
for shim in "$SHIM_PATH"/*; do
if [[ "$registered_shims" != *" ${shim##*/} "* ]]; then
rm -f "$shim"
fi
done
}


# Change to the shims directory.
cd "$SHIM_PATH"
shopt -s nullglob

# Create the prototype shim, then register shims for all known
# executables.
create_prototype_shim
remove_outdated_shims
make_shims ../versions/*/bin/*
make_shims $(list_executable_names | sort -u)

# Restore the previous working directory.
cd "$OLDPWD"

# Allow plugins to register shims.
OLDIFS="$IFS"
Expand All @@ -152,8 +145,5 @@ for script in "${scripts[@]}"; do
source "$script"
done

# Change back to the shims directory to install the registered shims
# and remove stale shims.
cd "$SHIM_PATH"
install_registered_shims
remove_stale_shims
2 changes: 1 addition & 1 deletion libexec/pyenv-whence
Expand Up @@ -8,7 +8,7 @@ set -e
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
echo --path
exec pyenv shims --short
exec pyenv-shims --short
fi

if [ "$1" = "--path" ]; then
Expand Down
2 changes: 1 addition & 1 deletion libexec/pyenv-which
Expand Up @@ -12,7 +12,7 @@ set -e

# Provide pyenv completions
if [ "$1" = "--complete" ]; then
exec pyenv shims --short
exec pyenv-shims --short
fi

remove_from_path() {
Expand Down
20 changes: 0 additions & 20 deletions script/test

This file was deleted.

25 changes: 25 additions & 0 deletions src/Makefile.in
@@ -0,0 +1,25 @@
CC = @CC@

CFLAGS = @CFLAGS@
LOCAL_CFLAGS = @LOCAL_CFLAGS@
DEFS = @DEFS@
LOCAL_DEFS = @LOCAL_DEFS@

CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) $(CFLAGS)

SHOBJ_CC = @SHOBJ_CC@
SHOBJ_CFLAGS = @SHOBJ_CFLAGS@
SHOBJ_LD = @SHOBJ_LD@
SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@
SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@
SHOBJ_LIBS = @SHOBJ_LIBS@
SHOBJ_STATUS = @SHOBJ_STATUS@

.c.o:
$(SHOBJ_CC) $(SHOBJ_CFLAGS) $(CCFLAGS) -c -o $@ $<

../libexec/pyenv-realpath.dylib: realpath.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ realpath.o $(SHOBJ_LIBS)

clean:
rm -f *.o ../libexec/*.dylib
31 changes: 31 additions & 0 deletions src/bash.h
@@ -0,0 +1,31 @@
#ifndef __BASH_H__
#define __BASH_H__

#define EXECUTION_SUCCESS 0
#define EXECUTION_FAILURE 1
#define EX_USAGE 258

#define BUILTIN_ENABLED 1

typedef struct word_desc {
char *word;
int flags;
} WORD_DESC;

typedef struct word_list {
struct word_list *next;
WORD_DESC *word;
} WORD_LIST;

typedef int sh_builtin_func_t(WORD_LIST *);

struct builtin {
char *name;
sh_builtin_func_t *function;
int flags;
char * const *long_doc;
const char *short_doc;
char *unused;
};

#endif

0 comments on commit f0e8525

Please sign in to comment.