@@ -811,38 +811,43 @@ function find_providers() {
##
#---------------------------------------------------------------------
function codex_cache_spell_lookup() {
- local SECTION
local spell="$1"
shift
- while [ $# -gt 0 ] ; do
- debug "libcodex" "looking up $spell in ${1}'s cache"
- codex_check_cache $1
- SECTION=`grep -m 1 "^$spell " $1/$SPELL_INDEX_FILE | cut -d' ' -f2`
- [[ $SECTION ]] && echo "$SECTION/$spell" && return
- shift
- done
- return 1
+ debug "libcodex" "looking up $spell in the caches of: $*"
+ codex_check_cache "$@"
+ awk -vidx="/$SPELL_INDEX_FILE" -vOFS=/ -vspell="$spell" '
+ BEGIN { for (i in ARGV) ARGV[i] = ARGV[i] idx }
+ found = $1 == spell { print $2, $1; exit }
+ END { exit !found }
+ ' "$@"
}
#---------------------------------------------------------------------
## @param grimoire-path
+## @param [grimoire-path ...]
## @Stdout error if cache doesn't exist after creation
## Checks that the cache exists. if it doesn't exist, make it.
## If it still doesn't exist, the barf an error
##
#---------------------------------------------------------------------
function codex_check_cache() {
- codex_is_canonicalized $1 || return 1
- [[ -x $1 ]] || return 1
-
- if ! [ -f $1/$SPELL_INDEX_FILE ] || ! [ -f $1/$PROVIDE_INDEX_FILE ]; then
+ ret=0
+ while ! [ $# = 0 ]; do
+ if ! codex_is_canonicalized "$1" || ! [ -x "$1" ]; then
+ ret=1
+ continue
+ fi
+ if ! [ -f "$1/$SPELL_INDEX_FILE" ] || ! [ -f "$1/$PROVIDE_INDEX_FILE" ];
then
codex_create_cache
- fi
- if ! [ -f $1/$SPELL_INDEX_FILE ] || ! [ -f $1/$PROVIDE_INDEX_FILE ]; then
- error_message "${PROBLEM_COLOR}Eeek, $1 is not a
grimoire!${DEFAULT_COLOR}"
- exit 1
- fi
+ fi
+ if ! [ -f "$1/$SPELL_INDEX_FILE" ] || ! [ -f "$1/$PROVIDE_INDEX_FILE" ];
then
+ error_message "${PROBLEM_COLOR}Eeek, $1 is not a
grimoire!${DEFAULT_COLOR}"
+ exit 1
+ fi
+ shift
+ done
+ return "$ret"
}
#---------------------------------------------------------------------
diff --git a/var/lib/sorcery/modules/libgcc b/var/lib/sorcery/modules/libgcc
index f3d5b8a..7c1f622 100755
--- a/var/lib/sorcery/modules/libgcc
+++ b/var/lib/sorcery/modules/libgcc
@@ -34,8 +34,12 @@
## @return 1 otherwise
#---------------------------------------------------------------------
function real_using_gcc() {
+ : ${CC:=gcc}
+ # Check if it's GCC we're using
+ case "$CC" in *gcc);; *) return 1;; esac
+
local needed_version=${1%+}
- local installed_version=$(gcc -dumpversion)
+ local installed_version=$("$CC" -dumpversion)
if [[ "$needed_version" == "$1" ]]; then
grep -qE "^$(esc_str $needed_version)(\.0)*$" <<< "$installed_version"
diff --git a/var/lib/sorcery/modules/liblock b/var/lib/sorcery/modules/liblock
index 8dc6676..ad012ff 100755
--- a/var/lib/sorcery/modules/liblock
+++ b/var/lib/sorcery/modules/liblock
@@ -78,17 +78,16 @@ trylock_resources()
debug "trylock_resources" "lockfile=${lockfile}"
- [[ -d $LOCK_DIR ]] || mkdir -p "$LOCK_DIR"
-
- if [[ -d ${lockfile} ]] || ! mkdir "${lockfile}" 2>/dev/null; then
- # we try to remove stale locks here and try again
- sleep 0.1
- global_clean_resources
- if ! mkdir "${lockfile}" 2>/dev/null; then
- return 1
- fi
+ [ -e "$lockfile/$$" ] && return
+
+ mkdir -p "$LOCK_DIR"
+ if ! mkdir "${lockfile}" 2>/dev/null; then
+ # we try to remove stale locks here and try again
+ sleep 0.1
+ global_clean_resources
+ mkdir "${lockfile}" 2>/dev/null || return
fi
- [[ -e ${lockfile}/$$ ]] || ln -s /proc/$$ "${lockfile}/$$"
+ ln -sf /proc/$$ "${lockfile}/$$"
return 0
}
@@ -179,22 +178,16 @@ clean_resources()
#---------------------------------------------------------------------
global_clean_resources()
{
- if [ -d "${LOCK_DIR}" ]; then
- # we remove old locks (>1 minute) that are not owned by any process.
- find "${LOCK_DIR}" -maxdepth 1 -mindepth 1 -mmin +1 -type d -empty -exec
rmdir {} \;
-
- # we remove locks that are owned by dead processes
- find "${LOCK_DIR}" -maxdepth 2 -mindepth 2 | \
-
- while read file; do
- # check if the process still exist (we use procfs mounted on /proc)
- if [ ! -d "${file}" ]; then
- debug "global_clean_resources" "removing stale lock ${file}"
- rm -f "${file}" 2>/dev/null &&
- rmdir $(smgl_dirname "${file}") 2>/dev/null
- fi
- done
- fi
+ [ -d "$LOCK_DIR" ] || return 0
+
+ # Release locks from dead processes
+ find -L "$LOCK_DIR" -mindepth 2 -maxdepth 2 \
+ -type l -print -exec rm -f {} + |
+ debug_stream global_clean_resources 'removing stale lock'
+ # Try to clean up empty locks
+ 2>/dev/null \
+ find "$LOCK_DIR" -d -mindepth 1 -maxdepth 1 -type d \
+ -exec rmdir {} +
}
#---------------------------------------------------------------------
diff --git a/var/lib/sorcery/modules/libmisc b/var/lib/sorcery/modules/libmisc
index 7389534..064c17f 100755
--- a/var/lib/sorcery/modules/libmisc
+++ b/var/lib/sorcery/modules/libmisc
@@ -195,6 +195,24 @@ function error_message() {
#---------------------------------------------------------------------
## @param type
+##
+## Enters debug messages from stdin if the type of debug message != 'no'
+##
+## The 'type' is usually the name of the file the debug statement
+## comes from. i.e. DEBUG_liblock, DEBUG_libsorcery, DEBUG_cast etc.
+##
+#---------------------------------------------------------------------
+debug_stream() {
+ local debugVar="DEBUG_${1//[!a-zA-Z0-9_]/_}"
+ if ! [ "$DEBUG" ] || [ "${!debugVar}" = "no" ]; then
+ cat > /dev/null
+ else
+ awk -vpfx="$1($$): $2:" '{print pfx, $0; fflush()}' >> "$DEBUG"
+ fi
+}
+
+#---------------------------------------------------------------------
+## @param type
## @param message
##
## Enters a debug message if the type of debug message != 'no'
@@ -1429,63 +1447,42 @@ function set_architecture() {
$STD_DEBUG
local specdir
- local i j
+ local i
unset SPECFILE
# If given an argument, treat as the architecture to use
local arch=${1}
# If no arch is specified, see if this is a cross-install, if so, set arch
to
- # the target arch
- if [[ ! $arch ]] &&
- [[ $CROSS_INSTALL == on ]] &&
- [[ $TARGET ]]
- then
- debug "libmisc" "set_architecture: using cross-install's target arch"
- arch=${arch:-$TARGET}
- fi
-
- # If no arch given and this isn't a cross-install, then default to the
ARCHITECTURE var
- if ! [[ $arch ]] ; then
- arch=$ARCHITECTURE
- fi
+ # the target arch; otherwise default to the ARCHITECTURE var
+ [ "$CROSS_INSTALL" = on ] || TARGET=
+ : ${arch:=${TARGET:-$ARCHITECTURE}}
# Find the specfile to use
- local find_compat=0
- find --version|grep -q 'version 4\.1\(\.\|$\)' && find_compat=1
- for specdir in ${ARCH_SPECS[@]} ; do
- if [[ $find_compat == 1 ]] ; then
- # older find still exists run in slower compatibility mode
- SPECFILE=$(find ${specdir} -perm -400 -type f -name "$arch" -print
2>/dev/null)
- else
- # -L so symlinks work, -type f so it won't match dirs, -quit so it
- # stops searching when it finds the answer
- SPECFILE=$(find -L ${specdir} -perm -400 -type f -name "$arch" -print
-quit 2>/dev/null)
- fi
- [ $SPECFILE ] && break
- done
- if [[ ! $SPECFILE ]] ; then
- message "${PROBLEM_COLOR}Cannot find arch spec for $arch!"
- message "Reverting to null!"
- message "Please run sorcery afterwards and pick another
architecture!$DEFAULT_COLOR"
- echo
- sleep 2
- SPECFILE=$(find -L ${specdir} -perm -400 -type f -name "null" -print
-quit 2>/dev/null)
- fi
+ SPECFILE=$(find -L "${ARCH_SPECS[@]}" \( -name "$arch" -o -name null \) \
+ -perm -400 -type f 2>/dev/null |
+ awk '! /[/]null$/ { exit } END { print }')
+ case "$SPECFILE" in
+ */null)
+ message "${PROBLEM_COLOR}Cannot find arch spec for $arch!"
+ message "Reverting to null!"
+ message "Please run sorcery afterwards and pick another
architecture!$DEFAULT_COLOR"
+ echo
+ sleep 2
+ esac
debug "libmisc" "set_architecture: SPECFILE=$SPECFILE"
# turn the path into an array, but remove $specdir from the start first
unset SMGL_COMPAT_ARCHS
+ specdir="${SPECFILE%/*/*/*/*/*}"
explode "${SPECFILE#$specdir/}" '/' SMGL_COMPAT_ARCHS
- unset ARCHITECTURE
- # Reverse the array so that the most specific arch is first
- j=0
- for(( i=${#SMGL_COMPAT_ARCHS[@]}-1; i>=0; i--)) ; do
- ARCHITECTURE[j++]=${SMGL_COMPAT_ARCHS[i]}
- done
+ # Reverse the array so that the most specific arch is first
+ ARCHITECTURE=(
+ $(for i in "${SMGL_COMPAT_ARCHS[@]}"; do echo "$i"; done | tac)
+ )
- source "$SPECFILE"
+ source "$SPECFILE"
}
#---------------------------------------------------------------------
diff --git a/var/lib/sorcery/modules/liboscompat
b/var/lib/sorcery/modules/liboscompat
new file mode 100644
index 0000000..5bc110e
--- /dev/null
+++ b/var/lib/sorcery/modules/liboscompat
@@ -0,0 +1,36 @@
+#!/bin/bash
+#---------------------------------------------------------------------
+##
+## @Synopsis Functions for OS compatibility.
+##
+##
+## This file contains functions that improve system compatibility.
+##
+##
+## @Copyright Copyright 2019 by the Source Mage Team
+##
+#---------------------------------------------------------------------
+
+# basic install replacement
+if ! type install >/dev/null 2>/dev/null; then
+ install() {
+ local o=0 g=0 m=644 d
+ while case "$1" in
+ -o|-g|-m) eval ${1#-}'="$2"'; shift;;
+ -p|-D) ;; # always
+ -d) eval ${1#-}=1 ;;
+ *) false ;;
+ esac
+ do shift; done
+ if [ "$d" ]; then
+ mkdir -p "$1"
+ else
+ mkdir -p "${2%/*}"
+ rm -f "$2"
+ cp "$1" "$2"
+ chmod "$m" "$2"
+ chown "$o:$g" "$2"
+ touch -r "$1" "$2"
+ fi
+ }
+fi
[SM-Commit] GIT changes to master sorcery by Ismael Luceno (b1f08e0907a0eb7470fa148dd8cf120083e19e5a),
Ismael Luceno, 02/05/2019