Skip to content

Commit

Permalink
Merge pull request #988 from Iximiel/patch-3
Browse files Browse the repository at this point in the history
mklib deletes tmp files also in case of failure
  • Loading branch information
GiovanniBussi authored Nov 29, 2023
2 parents dd113a1 + 1ff0a97 commit ba961ef
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions scripts/mklib.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#! /usr/bin/env bash

if [ "$1" = --description ] ; then
echo "compile a .cpp file into a shared library"
echo "compile one or more *.cpp files into a shared library"
echo " you can create and export the variable PLUMED_MKLIB_CFLAGS with some extra compile time flags to be used"
echo " you can create and export the variable PLUMED_MKLIB_LDFLAGS with some extra link time flags (and libraries) to be used"
exit 0
fi

Expand All @@ -10,18 +12,26 @@ if [ "$1" = --options ] ; then
exit 0
fi

source "$PLUMED_ROOT"/src/config/compile_options.sh

if [ $# == 0 ]
then
echo "ERROR"
echo "type 'plumed mklib file1.cpp [file2.cpp etc]'"
exit 1
fi

source "$PLUMED_ROOT"/src/config/compile_options.sh

lib="${1%%.cpp}".$soext
rm -f "$lib"

toRemove=""
remover() {
#if compilation fails or crashes the trap will delete the temporary files
for f in $toRemove; do
rm -f "${f}"
done
}
trap "remover" EXIT
objs=""

for file
Expand All @@ -44,9 +54,12 @@ do
#adding a simple tmpfile, to preprocess "in place" the input file,
#this assumes the user has write permission in the current directory
#which should be true since we are going to compile and output something here
tmpfile=$(mktemp ${file%.cpp}.XXXXXX).cpp
tmpfile=$(mktemp "${file%.cpp}.XXXXXX")
mv "${tmpfile}" "${tmpfile}.cpp"
tmpfile=${tmpfile}.cpp
cp "${file}" "${tmpfile}"

toRemove="${toRemove} ${tmpfile} ${tmpfile}.bak"

if grep -q '^#include "\(bias\|colvar\|function\|sasa\|vatom\)\/ActionRegister.h"' "${tmpfile}"; then
>&2 echo 'WARNING: using a legacy ActionRegister.h include path, please use <<#include "core/ActionRegister.h">>'
sed -i.bak 's%^#include ".*/ActionRegister.h"%#include "core/ActionRegister.h"%g' "${tmpfile}"
Expand All @@ -64,14 +77,14 @@ do
exit 1
}

rm -f ${tmpfile} ${tmpfile}.bak ${tmpfile%.cpp}
objs="$objs $obj"

done

if test "$PLUMED_IS_INSTALLED" = yes ; then
eval "$link_installed" "$PLUMED_MKLIB_LDFLAGS" -o "$lib" "$objs"
else
eval "$link_uninstalled" "$PLUMED_MKLIB_LDFLAGS" -o "$lib" "$objs"
link_command="$link_uninstalled"

if test "$PLUMED_IS_INSTALLED" = yes; then
link_command="$link_installed"
fi

eval "$link_command" "$PLUMED_MKLIB_LDFLAGS" $objs -o "$lib"

1 comment on commit ba961ef

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found broken examples in automatic/a-masterclass-22-09.txt
Found broken examples in automatic/a-masterclass-22-11.txt
Found broken examples in automatic/a-masterclass-22-12.txt
Found broken examples in automatic/performance-optimization.txt
Found broken examples in automatic/a-trieste-6.txt
Found broken examples in automatic/munster.txt
Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/ENVIRONMENTSIMILARITY.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNCPATHGENERAL.tmp
Found broken examples in automatic/FUNCPATHMSD.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GHBFIX.tmp
Found broken examples in automatic/INCLUDE.tmp
Found broken examples in automatic/MAZE_MEMETIC_SAMPLING.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_RANDOM_WALK.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in MiscelaneousPP.md

Please sign in to comment.