Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make utilities posix compatible #15139

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ samples: ## Build example programs
docs: ## Generate standard library documentation
$(call check_llvm_config)
./bin/crystal docs src/docs_main.cr $(DOCS_OPTIONS) --project-name=Crystal --project-version=$(CRYSTAL_VERSION) --source-refname=$(CRYSTAL_CONFIG_BUILD_COMMIT)
cp -av doc/ docs/
cp -R -P -p doc/ docs/

.PHONY: crystal
crystal: $(O)/$(CRYSTAL_BIN) ## Build the compiler
Expand All @@ -168,7 +168,7 @@ install: $(O)/$(CRYSTAL_BIN) man/crystal.1.gz ## Install the compiler at DESTDIR
$(INSTALL) -m 0755 "$(O)/$(CRYSTAL_BIN)" "$(BINDIR)/$(CRYSTAL_BIN)"

$(INSTALL) -d -m 0755 $(DATADIR)
cp $(if $(deref_symlinks),-rvL --preserve=all,-av) src "$(DATADIR)/src"
cp -R -p $(if $(deref_symlinks),-L,-P) src "$(DATADIR)/src"
rm -rf "$(DATADIR)/$(LLVM_EXT_OBJ)" # Don't install llvm_ext.o

$(INSTALL) -d -m 0755 "$(MANDIR)/man1/"
Expand Down Expand Up @@ -206,8 +206,8 @@ uninstall: ## Uninstall the compiler from DESTDIR
install_docs: docs ## Install docs at DESTDIR
$(INSTALL) -d -m 0755 $(DATADIR)

cp -av docs "$(DATADIR)/docs"
cp -av samples "$(DATADIR)/examples"
cp -R -P -p docs "$(DATADIR)/docs"
cp -R -P -p samples "$(DATADIR)/examples"

.PHONY: uninstall_docs
uninstall_docs: ## Uninstall docs from DESTDIR
Expand Down
35 changes: 14 additions & 21 deletions bin/crystal
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,16 @@ resolve_symlinks() {
_resolve_symlinks "$1"
}

_resolve_symlinks() {
_resolve_symlinks() (
_assert_no_path_cycles "$@" || return

local dir_context path

if path=$(readlink -- "$1"); then
dir_context=$(dirname -- "$1")
_resolve_symlinks "$(_prepend_dir_context_if_necessary "$dir_context" "$path")" "$@"
else
printf '%s\n' "$1"
fi
}
)

_prepend_dir_context_if_necessary() {
if [ "$1" = . ]; then
Expand All @@ -60,9 +58,7 @@ _prepend_path_if_relative() {
esac
}

_assert_no_path_cycles() {
local target path

_assert_no_path_cycles() (
target=$1
shift

Expand All @@ -71,7 +67,7 @@ _assert_no_path_cycles() {
return 1
fi
done
}
)

canonicalize_path() {
if [ -d "$1" ]; then
Expand All @@ -85,35 +81,32 @@ _canonicalize_dir_path() {
{ cd "$1" 2>/dev/null && pwd -P; }
}

_canonicalize_file_path() {
local dir file
_canonicalize_file_path() (
dir=$(dirname -- "$1")
file=$(basename -- "$1")
{ cd "$dir" 2>/dev/null >/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file"; }
}
)

##############################################################################

# Based on http://stackoverflow.com/q/370047/641451
remove_path_item() {
local path item

remove_path_item() (
path="$1"

printf "%s" "$path" | awk -v item="$2" -v RS=: -v ORS=: '$0 != item' | sed 's/:$//'
}
)

##############################################################################

__has_colors() {
local num_colors=$(tput colors 2>/dev/null)
__has_colors() (
num_colors=$(tput colors 2>/dev/null)

if [ -n "$num_colors" ] && [ "$num_colors" -gt 2 ]; then
return 0
else
return 1
fi
}
)
__error_msg() {
if __has_colors; then
# bold red coloring
Expand Down Expand Up @@ -148,7 +141,7 @@ export CRYSTAL_HAS_WRAPPER=true
PARENT_CRYSTAL="$CRYSTAL"

# check if the parent crystal command is a path that refers to this script
if [ -z "${PARENT_CRYSTAL##*/*}" -a "$(realpath "$PARENT_CRYSTAL")" = "$SCRIPT_PATH" ]; then
if [ -z "${PARENT_CRYSTAL##*/*}" ] && [ "$(realpath "$PARENT_CRYSTAL")" = "$SCRIPT_PATH" ]; then
# ignore it and use `crystal` as parent compiler command
PARENT_CRYSTAL="crystal"
fi
Expand All @@ -174,8 +167,8 @@ PARENT_CRYSTAL_EXISTS=$(test !$?)
if ($PARENT_CRYSTAL_EXISTS); then
if [ -z "$CRYSTAL_CONFIG_LIBRARY_PATH" ] || [ -z "$CRYSTAL_LIBRARY_PATH" ]; then
CRYSTAL_INSTALLED_LIBRARY_PATH="$($PARENT_CRYSTAL env CRYSTAL_LIBRARY_PATH 2> /dev/null || echo "")"
export CRYSTAL_LIBRARY_PATH=${CRYSTAL_LIBRARY_PATH:-$CRYSTAL_INSTALLED_LIBRARY_PATH}
export CRYSTAL_CONFIG_LIBRARY_PATH=${CRYSTAL_CONFIG_LIBRARY_PATH:-$CRYSTAL_INSTALLED_LIBRARY_PATH}
export CRYSTAL_LIBRARY_PATH="${CRYSTAL_LIBRARY_PATH:-$CRYSTAL_INSTALLED_LIBRARY_PATH}"
export CRYSTAL_CONFIG_LIBRARY_PATH="${CRYSTAL_CONFIG_LIBRARY_PATH:-$CRYSTAL_INSTALLED_LIBRARY_PATH}"
fi
fi

Expand Down
Loading