This commit is contained in:
Yevgen Muntyan 2008-11-26 16:14:30 -06:00
parent ba0b230b31
commit 6f17b8b3c8
4 changed files with 130 additions and 1 deletions

View File

@ -19,3 +19,18 @@ EXTRA_DIST += $(RESOURCES) $(QT_QRC_DEPS)
BUILT_SOURCES += $(ugly_qrc_cpp)
CLEANFILES += $(ugly_qrc_cpp)
nodist_@MODULE@_SOURCES += $(ugly_qrc_cpp)
dist-hook:
copyfile() { \
dest="$(distdir)/`dirname $$1`"; \
test -f $(distdir)/$(subdir)/$$1 || { \
$(MKDIR_P) "$$dest" || exit 1; \
echo cp -p "$(srcdir)/$$1" "$$dest/"; \
cp -p "$(srcdir)/$$1" "$$dest/" || exit 1; \
}; \
} ; \
for qrc in $(RESOURCES); do \
for f in `grep '<file' < $(srcdir)/$$qrc | sed -e 's%<file.*>\(.*\)</file>%\1%'`; do \
copyfile $$f; \
done; \
done

27
ugly/repo/qtest.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "@test@-t.h"
#include <moo/unit-tests.h>
#include <QtCore>
namespace moo {
namespace test {
class Tester {
public:
int exec(int argc, char *argv[])
{
UnitTestMainClass test;
return QTest::qExec(&test, argc, argv);
}
};
}
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
moo::test::Tester t;
return t.exec(argc, argv);
}
#include "@test@-test.moc"

49
ugly/repo/qtest.mk Normal file
View File

@ -0,0 +1,49 @@
# -%- lang: sh; indent-width: 8; use-tabs: true -%-
# UGLY_MK_TRIGGER = QTESTS
# UGLY_MK_VARS = EXTRA_PROGRAMS
# UGLY_MK_TYPE = sh
##################################################################################
#
# qtest
#
# input: QTESTS - list of tests. There must be corresponding -t.h files which
# contain the testing classes.
#
MODULE=`echo $MODULE | sed 's/\./_/'`
cat <<\EOFEOF
TESTS =
ugly_qtest_cpp = $(top_srcdir)/ugly/qtest.cpp
if MOO_ENABLE_UNIT_TESTS
TESTS += $(QTESTS:=-test)
EXTRA_PROGRAMS += $(QTESTS:=-test)
BUILT_SOURCES += $(QTESTS:=-test.cpp) $(QTESTS:=-test.moc)
CLEANFILES += $(QTESTS:=-test.cpp) $(QTESTS:=-test.moc)
%-test.cpp: $(ugly_qtest_cpp)
sed -e 's/@test@/$*/g' $(ugly_qtest_cpp) > $*-test.cpp.tmp && mv $*-test.cpp.tmp $*-test.cpp
%-test.moc: %-t.h
$(ugly_moc_wrapper) $(QT_MOC) $(srcdir) $*-test.moc $*-t.h
EOFEOF
for name in $QTESTS; do
var=`echo $name | sed 's/-/_/g'`
cat <<EOFEOF
${var}_test_SOURCES = ${name}-t.h
nodist_${var}_test_SOURCES = ${name}-test.cpp
${var}_test_LDADD = \$(patsubst %.cpp,%.o,\$(filter %.cpp,\$(filter-out main.cpp,\$(${MODULE}_SOURCES) \$(nodist_${MODULE}_SOURCES)))) \$(qtest_ldadd)
EOFEOF
done
cat <<\EOFEOF
endif
EXTRA_DIST += $(QTESTS:=-t.h) $(ugly_qtest_cpp)
EOFEOF

View File

@ -52,6 +52,11 @@ extract_var() {
echo "$value"
}
extract_vars() {
# extract_vars Makefile
grep -E '^[A-Za-z0-9_]+[ \t]*=' $1 | sed 's/^\([a-zA-Z0-9_]*\)[ \t]*=[ \t]*\(.*\)/export \1='"'"'\2'"'"'/g'
}
extract_meta_var() {
current_func=extract_meta_var
# extract_meta_var Makefile NAME
@ -68,7 +73,20 @@ write_mk() {
echo ""
echo "# begin $1"
echo ""
cat ugly/$1 | sed 's/@MODULE@/'$2'/g'
case "`extract_meta_var ugly/$1 UGLY_MK_TYPE`" in
sh)
MODULE="$2" /bin/sh -c ". $global_vars && /bin/sh ugly/$1"
;;
"")
cat ugly/$1 | sed 's/@MODULE@/'$2'/g'
;;
*)
echo "oops"
exit 1
;;
esac
echo ""
echo 'UGLY_DEPS += $(top_srcdir)/ugly/'$1
echo 'EXTRA_DIST += $(top_srcdir)/ugly/'$1
@ -108,6 +126,9 @@ do_makefile() {
preprocess $infile $out_pp
global_vars=`dirname $out`/.globalvars
extract_vars $out_pp > $global_vars
modname=`extract_var $out_pp MODULE | sed 's/\./_/g'`
debug "processing $infile, output: $out, subdir: $subdir, topdir: $rel_topdir, module: $modname"
@ -154,6 +175,22 @@ do_makefile() {
fi
done
for file_mk in $want_mk; do
debug "writing code for $file_mk"
vars=`extract_meta_var ugly/$file_mk UGLY_MK_VARS`
debug "extra vars: $vars"
for var in $vars; do
eval "var_written=\$var_${var}_written"
if [ "$var_written" = "true" ]; then
continue
fi
debug_v writing "$var"
eval "var_${var}_written=true"
echo "$var =" >> $out_tmp
done
done
for mod in $all_modnames; do
eval "mod_written=\$${mod}_written"
if $mod_written; then
@ -245,6 +282,7 @@ _EOFEOF
_EOFEOF
rm -f $out_pp
rm -f $global_vars
mv $out_tmp $out || exit $?
}