Skip to content
Snippets Groups Projects
Commit 74df119a authored by Markus Blatt's avatar Markus Blatt
Browse files

Made a lib of the module search funcionality. This now used in the duneproject...

Made a lib of the module search funcionality. This now used in the duneproject script to let the user decide which modules this project is to depend on.

[[Imported from SVN: r4604]]
parent b49e31ae
No related branches found
No related tags found
No related merge requests found
......@@ -11,151 +11,15 @@ if test "x$DEBUG" = "xyes"; then
set -v
fi
###############################################
###
### Configuration
###
# name of the "control" files
CONTROL="dune.module"
# Read the modules find part
. $(cd $(dirname $0); pwd)/dunemodules.inc
###############################################
###
### LIB
###
#
# read paramters from a $CONTROL file
#
# paramters:
# $1 file to read
#
parse_control() {
if test -f "$1"; then
export module=$(echo $(grep Module: "$1" | cut -d ':' -f2))
local deps=$(echo $(grep Depends: "$1" | cut -d ':' -f2))
local sugs=$(echo $(grep Suggests: "$1" | cut -d ':' -f2))
local path=$(dirname "$1")
if test "x$module" != "x"; then
if check_modname "$module"; then
export HAVE_${module}=yes
export PATH_${module}="$path"
export DEPS_${module}="$deps"
export SUGS_${module}="$sugs"
else
echo "ERROR: $CONTROL files $1 contains an invalid Module entry"
exit 1
fi
else
echo "ERROR: $CONTROL files $1 does not contain a Module entry"
exit 1
fi
else
echo "ERROR: could not read file $1"
exit 1
fi
}
#
# search a directory recursively for $CONTROL files
#
# paramters:
# $1 directory to search for modules
#
find_modules() {
if test -d "$1"; then
local dir=$(cd "$1" && pwd)
while read m; do
if test "x$m" != "x"; then
export module=""
parse_control "$m"
export MODULES="$MODULES $module"
fi
done <<EOF
$(find "$dir" -name $CONTROL )
EOF
else
echo "ERROR: could not find directory $1"
false
fi
}
#
# sort $MODULES according to the dependencies
#
sort_modules() {
for m in "$@"; do
_sort_module $m
done
if test x"$ONLY" != x; then
SORTEDMODULES=$ONLY
fi
export MODULES=$SORTEDMODULES
}
#
# recursive part of sort_modules
# evaluate dependencies of one module
#
# paramters:
# $1 name of the modules
#
_sort_module() {
local module=$1
shift 1
if ! check_modname $module; then echo "ERROR: invalid module name $module"; exit 1; fi
if test "x$(eval echo \$SORT_DONE_${command}_${module})" != "xyes"; then
# resolve dependencies
for dep in $(eval "echo \$DEPS_$module"); do
if ! check_modname $dep; then echo "ERROR: invalid module name $dep"; exit 1; fi
if test "x$(eval echo \$HAVE_$dep)" != "x"; then
_sort_module $dep
else
echo "ERROR: could not find module $dep"
exit 1
fi
done
# resolve suggestions
for dep in $(eval "echo \$SUGS_$module"); do
if ! check_modname $dep; then echo "ERROR: invalid module name $dep"; exit 1; fi
if test "x$(eval echo \$HAVE_$dep)" != "x"; then
_sort_module $dep
fi
done
# insert this module into the list
export SORT_DONE_${command}_${module}=yes
export SORTEDMODULES="$SORTEDMODULES $module"
fi
}
#
# load the $CONTROL file, skip all control variables
# and run a command
#
# parameters:
# $1 command to execute
# $2 full path of the $CONTROL file
#
eval_control() {
local command=$1
local file=$2
shift 2
if test -f "$file"; then
# open subshell
(
set -e
# load functions defined in $file
# if $command is not defined in $file,
# then the default implementation will be executed
eval "$(grep -v -e '^[[:alnum:]]\+:' $file)"
# execute $command
$command
) || false
else
echo "ERROR: could not find $file"
exit 1
fi
}
#
# for each module load the $CONTROL script part and run $command
......@@ -179,19 +43,6 @@ build_modules() {
done
}
#
# make sure the module name fits the naming convention
#
# parameters:
# $1 module name
#
check_modname() {
if ! echo "$1" | grep -q '^[a-zA-Z0-9_]\+$'; then
return 1
fi
return 0
}
#
# load command options from an opts file
# the name of the opts file is stored in the global variable $OPTS_FILE
......
###############################################
###
### Configuration
###
# name of the "control" files
CONTROL="dune.module"
###############################################
#
# read paramters from a $CONTROL file
#
# paramters:
# $1 file to read
#
parse_control() {
if test -f "$1"; then
export module=$(echo $(grep Module: "$1" | cut -d ':' -f2))
local deps=$(echo $(grep Depends: "$1" | cut -d ':' -f2))
local sugs=$(echo $(grep Suggests: "$1" | cut -d ':' -f2))
local path=$(dirname "$1")
if test "x$module" != "x"; then
if check_modname "$module"; then
export HAVE_${module}=yes
export PATH_${module}="$path"
export DEPS_${module}="$deps"
export SUGS_${module}="$sugs"
else
echo "ERROR: $CONTROL files $1 contains an invalid Module entry"
exit 1
fi
else
echo "ERROR: $CONTROL files $1 does not contain a Module entry"
exit 1
fi
else
echo "ERROR: could not read file $1"
exit 1
fi
}
#
# search a directory recursively for $CONTROL files
#
# paramters:
# $1 directory to search for modules
#
find_modules() {
if test -d "$1"; then
local dir=$(cd "$1" && pwd)
while read m; do
if test "x$m" != "x"; then
export module=""
parse_control "$m"
export MODULES="$MODULES $module"
fi
done <<EOF
$(find "$dir" -name $CONTROL )
EOF
else
echo "ERROR: could not find directory $1"
false
fi
}
#
# sort $MODULES according to the dependencies
#
sort_modules() {
for m in "$@"; do
_sort_module $m
done
if test x"$ONLY" != x; then
SORTEDMODULES=$ONLY
fi
export MODULES=$SORTEDMODULES
}
#
# recursive part of sort_modules
# evaluate dependencies of one module
#
# paramters:
# $1 name of the modules
#
_sort_module() {
local module=$1
shift 1
if ! check_modname $module; then echo "ERROR: invalid module name $module"; exit 1; fi
if test "x$(eval echo \$SORT_DONE_${command}_${module})" != "xyes"; then
# resolve dependencies
for dep in $(eval "echo \$DEPS_$module"); do
if ! check_modname $dep; then echo "ERROR: invalid module name $dep"; exit 1; fi
if test "x$(eval echo \$HAVE_$dep)" != "x"; then
_sort_module $dep
else
echo "ERROR: could not find module $dep"
exit 1
fi
done
# resolve suggestions
for dep in $(eval "echo \$SUGS_$module"); do
if ! check_modname $dep; then echo "ERROR: invalid module name $dep"; exit 1; fi
if test "x$(eval echo \$HAVE_$dep)" != "x"; then
_sort_module $dep
fi
done
# insert this module into the list
export SORT_DONE_${command}_${module}=yes
export SORTEDMODULES="$SORTEDMODULES $module"
fi
}
#
# load the $CONTROL file, skip all control variables
# and run a command
#
# parameters:
# $1 command to execute
# $2 full path of the $CONTROL file
#
eval_control() {
local command=$1
local file=$2
shift 2
if test -f "$file"; then
# open subshell
(
set -e
# load functions defined in $file
# if $command is not defined in $file,
# then the default implementation will be executed
eval "$(grep -v -e '^[[:alnum:]]\+:' $file)"
# execute $command
$command
) || false
else
echo "ERROR: could not find $file"
exit 1
fi
}
#
# make sure the module name fits the naming convention
#
# parameters:
# $1 module name
#
check_modname() {
if ! echo "$1" | grep -q '^[a-zA-Z0-9_]\+$'; then
return 1
fi
return 0
}
......@@ -5,7 +5,7 @@
#
# * anpasen, dass bei installiertem Dune das DUNEDIR nicht an
# autogen.sh uebergeben weden muss.
#
# * Check whether the module and module directory does not exists already,
set -e
......@@ -25,6 +25,13 @@ while [ "$DATACORRECT" != "y" -a "$DATACORRECT" != "Y" ]; do
while [ -z $MODULE ]; do
read -p "Name of the module? (to be used in dune.module file, eg:dune_grid (only alphanumeric character)): " MODULE
done
# Read the modules find part
. $(cd $(dirname $0); pwd)/dunemodules.inc
find_modules .
DEPENDENCIES=""
while [ -z $DEPENDENCIES ]; do
read -p "Modules this module depends on (separated by spaces). Available modules are $MODULES :" DEPENDENCIES
done
VERSION=""
while [ -z $VERSION ]; do
read -p "Project/Module version? " VERSION
......@@ -37,7 +44,7 @@ while [ "$DATACORRECT" != "y" -a "$DATACORRECT" != "Y" ]; do
echo
echo -n "creating Project \"$PROJECT\", version $VERSION "
echo "with maintainer \"$MAINTAINER\""
echo "which depends on \"$DEPENDENCIES\""
read -p "Are these informations correct? [y/N] " DATACORRECT
echo
echo "Look at README and dune.module files in the \"$PROJECT\" directory "
......@@ -58,7 +65,7 @@ cat > "$PROJECT/dune.module" <<C_DELIM
#Name of the module
Module:$MODULE
#depending on
Depends:dune_common dune_grid dune_disc dune_istl
Depends:$DEPENDENCIES
C_DELIM
################## CONFIGURE.AC ##################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment