From f548ce5889cd69ed0c9fb17e2dccf47fbeb41784 Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Testillano Date: Sat, 8 Apr 2017 18:10:16 +0200 Subject: [PATCH] Make testing library dynamic. Refactor DEPLOY.sh --- SConstruct | 6 +- example/diameter/launcher/DEPLOY.sh | 136 +++++++----------- example/diameter/launcher/SConscript | 7 +- .../resources/scripts/select_dynlib.sh | 9 +- source/testing/SConscript | 2 +- 5 files changed, 69 insertions(+), 91 deletions(-) diff --git a/SConstruct b/SConstruct index a163297..fbfad0e 100644 --- a/SConstruct +++ b/SConstruct @@ -183,7 +183,11 @@ env.Alias('doc', env.Command('doc.dummy', [], 'cd docs/doxygen; doxygen')) # # See http://www.scons.org/wiki/InstallTargets and http://www.scons.org/doc/production/HTML/scons-user/c2938.html install_include = env.Install (target_usr_local_include, Glob("include/anna/*")) -install_lib = env.Install (target_usr_local_lib, Glob("source/*/" + variant + "/*.a")) +static_lib_files = 'source/*/' + variant + '/*.a' +dynamic_lib_files = 'source/*/' + variant + '/*.so' +files_grabbed = [Glob(e) for e in [static_lib_files, dynamic_lib_files]] + +install_lib = env.Install (target_usr_local_lib, files_grabbed) install_dynlib = env.Install (target_usr_local_lib, Glob("dynamic/launcher/default/" + variant + "/*.so")) install_example = env.Install (target_opt_bin, Glob("example/*/*/" + variant + "/example_*")) postinstall_example = env.Command('./example/postinstall.out', None, './example/postinstall.sh') diff --git a/example/diameter/launcher/DEPLOY.sh b/example/diameter/launcher/DEPLOY.sh index ce1c91a..7ea9942 100755 --- a/example/diameter/launcher/DEPLOY.sh +++ b/example/diameter/launcher/DEPLOY.sh @@ -3,32 +3,21 @@ ############# # VARIABLES # ############# -SETUPS_DIR=../../../source/diameter/stack/setups -MSGDTD=../../../include/anna/diameter/codec/message.dtd -DCTDTD=../../../include/anna/diameter/stack/dictionary.dtd -SERVICES=./resources/services_examples -STACK_EXAMPLES=./resources/stack_examples +SCR_DIR=`readlink -f $(dirname $0)` +PROJECT_ROOT=$(readlink -f ../../..) +SETUPS_DIR=$PROJECT_ROOT/source/diameter/stack/setups +MSGDTD=$PROJECT_ROOT/include/anna/diameter/codec/message.dtd +DCTDTD=$PROJECT_ROOT/include/anna/diameter/stack/dictionary.dtd +SERVICES=$SCR_DIR/resources/services_examples +STACK_EXAMPLES=$SCR_DIR/resources/stack_examples SRVDTD=$SERVICES/services.dtd - -# Executables in priority order: -EXEC_installed=/opt/bin/anna/example_diameter_launcher -EXECS=( $EXEC_installed ./release/example_diameter_launcher ./debug/example_diameter_launcher ) - -# Stack management -STACKMGMT_EXEC_installed=/opt/bin/anna/example_diameter_stackManagement -STACKMGMT_EXECS=( $STACKMGMT_EXEC_installed ../stackManagement/release/example_diameter_stackManagement ../stackManagement/debug/example_diameter_stackManagement ) - -# Dynamic library: -#DYNLIB_installed=/usr/local/lib/libanna_dynamicLauncherProcedure.so -#DYNLIBS=( $DYNLIB_installed ../../../dynamic/launcher/default/release/libanna_dynamicLauncherProcedure.so ../../../dynamic/launcher/default/debug/libanna_dynamicLauncherProcedure.so ) +VARIANT= ############# # FUNCTIONS # ############# _exit () { - echo - echo $1 - echo + echo -e "\n$1\n" exit 1 } @@ -85,7 +74,8 @@ EOF ############# # EXECUTION # ############# -cd `dirname $0` +cd $SCR_DIR + echo echo "---------------------------------------" echo "Anna Diameter Launcher (ADML) deployment" @@ -95,39 +85,13 @@ echo " (--help or -h for more info)" echo echo "Basic checkings ..." -# Launcher executable: -available= -for EXEC in ${EXECS[@]}; do - echo -n "Looking executable at '$EXEC' ... " - [ -x $EXEC ] && { available=yes ; echo "available !" ; break ; } - echo "not found" -done -[ -z "$available" ] && _exit "Anna Diameter Launcher (ADML) is not installed neither linked. See README.md (Install section)." - -# Dynamic library variant: -dynlib_variant= -[ -f ./release/example_diameter_launcher ] && dynlib_variant=release -[ -f ./debug/example_diameter_launcher ] && dynlib_variant=debug -[ -z "$dynlib_variant" ] && _exit "Unknown dynamic library variant" - -# Dictionary creation: -available= -for STACKMGMT_EXEC in ${STACKMGMT_EXECS[@]}; do - echo -n "Looking stack management executable at '$STACKMGMT_EXEC' ... " - [ -x $STACKMGMT_EXEC ] && { available=yes ; echo "available !" ; break ; } - echo "not found" -done -[ -z "$available" ] && _exit "Anna Diameter Stack Management Tool is not installed neither linked. See README.md (Install section)." -STACKMGMT_EXEC=`readlink -f $STACKMGMT_EXEC` - -# Dynamic library: -#available= -#for DYNLIB in ${DYNLIBS[@]}; do -# echo -n "Looking dynamic library at '$DYNLIB' ... " -# [ -x $DYNLIB ] && { available=yes ; echo "available !" ; break ; } -# echo "not found" -#done -#[ -z "$available" ] && _exit "Anna Diameter Launcher Dynamic Procedure Library (ADML) is not installed neither linked. See README.md (Install section)." +# Get variant and main executables: +[ -f $SCR_DIR/release/example_diameter_launcher ] && VARIANT=release +[ -f $SCR_DIR/debug/example_diameter_launcher ] && VARIANT=debug +[ -z "$VARIANT" ] && _exit "Cannot locate neither 'release' nor 'debug' variant !" +echo "Variant: $VARIANT" +ADML_EXEC=$SCR_DIR/$VARIANT/example_diameter_launcher +STACKMGMT_EXEC=$(readlink -f $SCR_DIR/../stackManagement/$VARIANT/example_diameter_stackManagement) [ ! -d $SETUPS_DIR ] && _exit "Diameter stacks not found ($SETUPS_DIR)." @@ -201,41 +165,47 @@ mkdir -p $DPATH/test-reports # Dynamic libs: mkdir -p $DPATH/dynlibs -cd ../../../dynamic/launcher -DYNLIBS=( $(find . -name "*.so") ) -for dl in ${DYNLIBS[@]} +DYNLIBS=( $(find $PROJECT_ROOT -name "*.so" | grep -w $VARIANT) ) + +for dynlib in ${DYNLIBS[@]} do - dir=$(dirname $dl | xargs dirname) - mkdir -p $DPATH/dynlibs/$dir - cp $dir/$dynlib_variant/*.so $DPATH/dynlibs/$dir - cp $dir/*.xml $DPATH/dynlibs/$dir 2>/dev/null - cp $dir/dynamic.suffix $DPATH/dynlibs/$dir 2>/dev/null - cp -r $dir/services $DPATH/dynlibs/$dir 2>/dev/null + dynlib_bn=$(basename $dynlib) + if [ "$dynlib_bn" != "libanna_dynamicLauncherProcedure.so" ] + then + cp $dynlib $DPATH/dynlibs + else + ########## ADML Dynamic libs system ########## + # Create structure from $PROJECT_ROOT/dynamic/launcher + suffix_path=$(echo $dynlib | awk -F"$PROJECT_ROOT/dynamic/launcher/" '{ print $2 }') + target=$(dirname $DPATH/dynlibs/$(dirname $suffix_path)) + mkdir -p $target + cp $dynlib $target + + # Additional resources + dynlib_dn=$(dirname $dynlib) + dynlib_dn_dn=$(dirname $dynlib_dn) + cp $dynlib_dn_dn/*.xml $target 2>/dev/null + cp $dynlib_dn_dn/dynamic.suffix $target 2>/dev/null + cp -r $dynlib_dn_dn/services $target 2>/dev/null + fi done -cd - >/dev/null -cp ./resources/scripts/select_dynlib.sh $DPATH/dynlibs/select.sh + +# ADML dynamic libs selection script: +cp $SCR_DIR/resources/scripts/select_dynlib.sh $DPATH/dynlibs/select.sh + +# Default dynamic library: cd $DPATH/dynlibs ln -s default/libanna_dynamicLauncherProcedure.so cd - >/dev/null +# Basic setup: [ "$option" = "b" ] && mkdir -p $DPATH/services -# ADML executable: -if [ "$EXEC" = "$EXEC_installed" ] -then - ln -s $EXEC_installed $DPATH/ADML-launcher -else - cp $EXEC $DPATH/ADML-launcher -fi - -# Stack management tool: -if [ "$STACKMGMT_EXEC" = "$STACKMGMT_EXEC_installed" ] -then - ln -s $STACKMGMT_EXEC_installed $DPATH/stacks/stack-mgmt -fi -# Copy binary just in case: +# Copy executables: +cp $ADML_EXEC $DPATH/ADML-launcher [ ! -f $DPATH/stacks/stack-mgmt ] && cp $STACKMGMT_EXEC $DPATH/stacks/stack-mgmt +# Copy resources: cp -rL $DEPLOYMENTS_DIR/* $DPATH cp $SETUPS_DIR/*xml $DPATH/stacks cp $SETUPS_DIR/*sh $DPATH/stacks @@ -267,11 +237,7 @@ then fi # Help: +echo "Done !" +echo "(see README at '$DPATH')" echo -echo "Go to '$DPATH' and see README file" -echo -echo "Done!" -echo -echo - diff --git a/example/diameter/launcher/SConscript b/example/diameter/launcher/SConscript index 8e1b064..5caeec9 100644 --- a/example/diameter/launcher/SConscript +++ b/example/diameter/launcher/SConscript @@ -12,7 +12,7 @@ pwd = str(Dir ('.').abspath); anna_libpaths = [] anna_libs = [] -modules = [ 'core', 'io', 'xml', 'app', 'http', 'comm', 'timex', 'http', 'statistics', 'time', 'diameter', 'diameter_comm', 'testing' ]; +modules = [ 'core', 'io', 'xml', 'app', 'http', 'comm', 'timex', 'http', 'statistics', 'time', 'diameter', 'diameter_comm' ]; for module in modules: anna_libs.append ("anna_" + module) module = module.replace("_", ".") @@ -20,9 +20,12 @@ for module in modules: # dynamic lib: anna_libs.append ("anna_dynamicLauncherProcedure") +anna_libs.append ("anna_testing") variant = env ['VARIANT'] dynamic_libpath = os.path.join (pwd, "../../../../dynamic/launcher/default/" + variant) anna_libpaths.append (dynamic_libpath) +dynamic_libpath = os.path.join (pwd, "../../../../source/testing/" + variant) +anna_libpaths.append (dynamic_libpath) anna_rlibs = list(anna_libs) anna_rlibs.reverse() @@ -46,6 +49,8 @@ localEnv.Append(LIBPATH = anna_libpaths) current_directory = Dir ('.').abspath dynamic_include = os.path.join (pwd, "../../../../dynamic/launcher/default/") localEnv.Append (CPPPATH = [current_directory, dynamic_include]) +#dynamic_include = os.path.join (pwd, "../../../../include/anna/testing/") +#localEnv.Append (CPPPATH = [current_directory, dynamic_include]) result = localEnv.Program (pName, Glob ('*.cpp')) Return ('result') diff --git a/example/diameter/launcher/resources/scripts/select_dynlib.sh b/example/diameter/launcher/resources/scripts/select_dynlib.sh index 40a0072..3a2a952 100755 --- a/example/diameter/launcher/resources/scripts/select_dynlib.sh +++ b/example/diameter/launcher/resources/scripts/select_dynlib.sh @@ -1,18 +1,19 @@ #!/bin/bash +dynamicProcedureLibName=libanna_dynamicLauncherProcedure.so echo echo "------------------------------------------------" echo "Dynamic library selection for launcher procedure" echo "------------------------------------------------" cd $(dirname $0) option=$1 -rm -f libanna_dynamicLauncherProcedure.so +rm -f $dynamicProcedureLibName if [ -z "$option" ] then echo " (you could provide directly the path to the .so file)" echo echo "Available options:" tmpfile=$(mktemp) - find . -name "*.so" > $tmpfile + find . -name "$dynamicProcedureLibName" > $tmpfile echo for line in $(cat $tmpfile); do echo " $line" ; done dflt=$(grep "^./default/" $tmpfile) @@ -24,7 +25,9 @@ then fi [ ! -f $option ] && { echo -e "\nInvalid file !\n" ; exit 1 ; } -ln -sf $option libanna_dynamicLauncherProcedure.so +option_bn=$(basename $option) +[ "$option_bn" != "$dynamicProcedureLibName" ] && { echo -e "\nInvalid file (must be a dynamic procedure library) !\n" ; exit 1 ; } +ln -sf $option $dynamicProcedureLibName echo echo "Library enabled" echo diff --git a/source/testing/SConscript b/source/testing/SConscript index e9ea1e5..b706a38 100644 --- a/source/testing/SConscript +++ b/source/testing/SConscript @@ -2,7 +2,7 @@ Import ('env') sources = Glob('*.cpp') -result = env.StaticLibrary ('anna_testing', sources); +result = env.SharedLibrary ('anna_testing', sources); Return ('result') -- 2.20.1