diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-06-21 10:39:59 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-06-21 10:39:59 +0200 |
commit | 6cd8b9f561b912f264ba4f723845935c40a3cb95 (patch) | |
tree | 5983e0af3d2ee621242ca6707a58c89b9914d8f0 /build | |
parent | 236cd9bb1dd022e64d690c9b0080d1a15c5f61c7 (diff) |
Add support for running tests in dynamic multi-database mode
Only possible in the development build system at this stage.
Diffstat (limited to 'build')
-rw-r--r-- | build/bootstrap.make | 107 | ||||
-rwxr-xr-x | build/configure | 15 | ||||
-rw-r--r-- | build/import/odb/hxx-cxx.make | 97 |
3 files changed, 187 insertions, 32 deletions
diff --git a/build/bootstrap.make b/build/bootstrap.make index 178f2aa..7d5b84e 100644 --- a/build/bootstrap.make +++ b/build/bootstrap.make @@ -27,21 +27,64 @@ def_goal := $(.DEFAULT_GOAL) # $(call include,$(bld_root)/cxx/configuration.make) +# Databases. +# +databases := mysql sqlite pgsql oracle mssql +$(dist): databases := $(databases) + # Aliases # -.PHONY: $(out_base)/ \ - $(out_base)/.test \ - $(out_base)/.dist \ - $(out_base)/.clean +default := $(out_base)/ +driver := $(out_base)/driver +test := $(out_base)/.test +dist := $(out_base)/.dist +clean := $(out_base)/.clean + +.PHONY: $(default) \ + $(test) \ + $(dist) \ + $(clean) + +ifeq ($(db_id),common) +define db-test-target +test_$1 := $$(out_base)/.test-$1 +.PHONY: $$(test_$1) +$$(test): $$(test_$1) -ifdef %interactive% +endef +$(foreach d,$(databases),$(eval $(call db-test-target,$d))) + +define db-test-dir +$$(test_$1): $$(addprefix $$(out_base)/,$$(addsuffix /.test-$1,$2)) + +endef +endif +ifdef %interactive% .PHONY: test dist clean +test: $(test) +dist: $(dist) +clean: $(clean) -test: $(out_base)/.test -dist: $(out_base)/.dist -clean: $(out_base)/.clean +ifeq ($(db_id),common) +define db-test-alias +.PHONY: test-$1 +test-$1: $$(test_$1) +endef +$(foreach d,$(databases),$(eval $(call db-test-alias,$d))) +endif +endif + +# Return the list of ODB-generated files given a list of header files. +# +ifdef db_id +ifneq ($(db_id),common) +odb-gen = $(foreach f,$(1:.hxx=),$(addprefix $f,-odb.hxx -odb.ixx -odb.cxx .sql)) +else +odb-gen = $(foreach f,$(1:.hxx=),$(addprefix $f, -odb.hxx -odb.ixx -odb.cxx \ +$(foreach d,$(databases),-odb-$d.hxx -odb-$d.ixx -odb-$d.cxx -$d.sql))) +endif endif # By default the ODB header is called test.hxx. @@ -50,13 +93,50 @@ $(out_base)/.dist: export odb_header_stem := test # Database schema creation. # -ifeq ($(filter $(db_id),sqlite),) -$(out_base)/.test: schema-body = \ -$(call message,sql $$1,$(dcf_root)/$(db_id)-driver $$1,$1)$(literal_newline)$(literal_tab) +ifneq ($(db_id),sqlite) +$(out_base)/.test $(addprefix $(out_base)/.test-,$(databases)): schema-body = \ +$(call message,sql $$1,$(dcf_root)/$1-driver $$1,$2)$(literal_newline)$(literal_tab) + +ifneq ($(db_id),common) $(out_base)/.test: schema = \ -$(foreach s,$(if $1,$1,$(out_base)/test.sql),$(call schema-body,$s))@: +$(foreach s,$(if $1,$1,$(out_base)/test.sql),$(call schema-body,$(db_id),$s))@: +else +define db-schema +$$(out_base)/.test-$1: schema-$1 = \ +$$(foreach s,$$(if $$1,$$(filter %-$1.sql,$$1),$$(out_base)/test-$1.sql),$$(call schema-body,$1,$$s))@: + +endef +$(foreach d,$(filter-out sqlite,$(databases)),$(eval $(call db-schema,$d))) +endif endif +# Test rule templates. +# + +# $1 database name in the multi-database mode and empty otherwise +# +define test-schemaless-rule +$$(test$(if $1,_$1)): $$(driver) $$(src_base)/test.std + $$(call message,test$(if $1, [$1]) $$<,$$< $1 --options-file \ +$$(dcf_root)/$(if $1,$1,$(db_id)).options >$$(out_base)/test.out) + $$(call message,,diff -u $$(src_base)/test.std $$(out_base)/test.out) + $$(call message,,rm -f $$(out_base)/test.out) + +endef + +# $1 database name in the multi-database mode and empty otherwise +# $2 optional list of schema files, by default test.sql +# +define test-rule +$$(test$(if $1,_$1)): $$(driver) $$(src_base)/test.std + $$(call schema$(if $1,-$1),$2) + $$(call message,test$(if $1, [$1]) $$<,$$< $1 --options-file \ +$$(dcf_root)/$(if $1,$1,$(db_id)).options >$$(out_base)/test.out) + $$(call message,,diff -u $$(src_base)/test.std $$(out_base)/test.out) + $$(call message,,rm -f $$(out_base)/test.out) + +endef + # Dist setup. # ifneq ($(filter $(MAKECMDGOALS),dist),) @@ -67,9 +147,6 @@ ifeq ($(dist_prefix),) $(error dist_prefix is not set) endif -databases := mysql sqlite pgsql oracle mssql -$(dist): databases := $(databases) - # $1 project template without the -vcN.vc[x]proj suffix. # $2 project name without the -vcN.vc[x]proj suffix. # diff --git a/build/configure b/build/configure index aecf319..1184b5b 100755 --- a/build/configure +++ b/build/configure @@ -18,6 +18,8 @@ $echo "configuring '$project_name'" $echo $echo +databases="mysql sqlite pgsql oracle mssql" + $echo $echo "Please select the database you would like to use:" $echo @@ -26,10 +28,19 @@ $echo "(2) SQLite" $echo "(3) PostgreSQL" $echo "(4) Oracle" $echo "(5) Microsoft SQL Server" +$echo "(6) Dynamic multi-database support (all above databases)" $echo -db_id=`read_option "mysql sqlite pgsql oracle mssql"` +db_id=`read_option "$databases common"` echo "db_id := $db_id" >$1 -source $scf_root/$db_id/configure +if [ $db_id != "common" ]; then + source $scf_root/$db_id/configure +else + # For multi-database support we configure every database. + # + for db in $databases; do + source $scf_root/$db/configure + done +fi diff --git a/build/import/odb/hxx-cxx.make b/build/import/odb/hxx-cxx.make index a67d6b7..683827e 100644 --- a/build/import/odb/hxx-cxx.make +++ b/build/import/odb/hxx-cxx.make @@ -9,45 +9,95 @@ # $(call include,$(bld_root)/cxx/configuration.make) +odb_databases := mysql sqlite pgsql oracle mssql + odb_pattern := \ $(out_base)/%-odb.$(cxx_s_suffix) \ $(out_base)/%-odb.$(cxx_h_suffix) \ $(out_base)/%-odb.$(cxx_i_suffix) \ $(out_base)/%.sql -$(odb_pattern): odb_options := \ ---hxx-suffix .$(cxx_h_suffix) \ ---ixx-suffix .$(cxx_i_suffix) \ +odb_patterns := $(odb_pattern) + +define odb-db-pattern +odb_$1_pattern := \ +$$(out_base)/%-odb-$1.$$(cxx_s_suffix) \ +$$(out_base)/%-odb-$1.$$(cxx_h_suffix) \ +$$(out_base)/%-odb-$1.$$(cxx_i_suffix) \ +$$(out_base)/%-$1.sql + +odb_patterns += $$(odb_$1_pattern) + +endef # Trailing newline is important. + +$(foreach d,$(odb_databases),$(eval $(call odb-db-pattern,$d))) + +$(odb_patterns): odb_options := \ +--hxx-suffix .$(cxx_h_suffix) \ +--ixx-suffix .$(cxx_i_suffix) \ --cxx-suffix .$(cxx_s_suffix) -$(odb_pattern): odb-expand-cpp-options-impl = \ +$(odb_patterns): odb-expand-cpp-options-impl = \ $(if $1,$(shell sed -e 's%include: \(.*\)%\1%' -e t -e d $1)) -$(odb_pattern): odb-expand-cpp-options = \ +$(odb_patterns): odb-expand-cpp-options = \ $(call odb-expand-cpp-options-impl,$(filter %.cpp-options,$1)) -.PRECIOUS: $(odb_pattern) +# We only check for the long option name to avoid false positives. +# +$(odb_pattern): odb-default-database = \ +$(if $(filter --multi-database ,$(odb_options)),--database common ) + +$(odb_pattern): odb-default-database-message = \ +$(if $(filter --multi-database ,$(odb_options)),[common] ) + +.PRECIOUS: $(odb_patterns) ifeq ($(out_base),$(src_base)) $(odb_pattern): $(src_base)/%.$(cxx_h_suffix) - $(call message,odb $<,$(odb) $(cpp_options) \ -$(call odb-expand-cpp-options,$^) $(cxx_pp_extra_options) $(odb_options) \ ---output-dir $(dir $@) $<) + $(call message,odb $(call odb-default-database-message)$<,$(odb) \ +$(cpp_options) $(call odb-expand-cpp-options,$^) $(cxx_pp_extra_options) \ +$(odb_options) $(call odb-default-database)--output-dir $(dir $@) $<) + +define odb-db-rule +$$(odb_$1_pattern): $$(src_base)/%.$$(cxx_h_suffix) + $$(call message,odb [$1] $$<,$$(odb) $$(cpp_options) \ +$$(call odb-expand-cpp-options,$$^) $$(cxx_pp_extra_options) $$(odb_options) \ +--database $1 --output-dir $$(dir $$@) $$<) + +endef # Trailing newline is important. else $(odb_pattern): $(src_base)/%.$(cxx_h_suffix) | $$(dir $$@). - $(call message,odb $<,$(odb) $(cpp_options) \ -$(call odb-expand-cpp-options,$^) $(cxx_pp_extra_options) $(odb_options) \ ---output-dir $(dir $@) $<) + $(call message,odb $(call odb-default-database-message)$<,$(odb) \ +$(cpp_options) $(call odb-expand-cpp-options,$^) $(cxx_pp_extra_options) \ +$(odb_options) $(call odb-default-database)--output-dir $(dir $@) $<) $(odb_pattern): $(out_base)/%.$(cxx_h_suffix) | $$(dir $$@). - $(call message,odb $<,$(odb) $(cpp_options) \ -$(call odb-expand-cpp-options,$^) $(cxx_pp_extra_options) $(odb_options) \ ---output-dir $(dir $@) $<) + $(call message,odb $(call odb-default-database-message)$<,$(odb) \ +$(cpp_options) $(call odb-expand-cpp-options,$^) $(cxx_pp_extra_options) \ +$(odb_options) $(call odb-default-database) --output-dir $(dir $@) $<) + +define odb-db-rule +$$(odb_$1_pattern): $$(src_base)/%.$$(cxx_h_suffix) | $$$$(dir $$$$@). + $$(call message,odb [$1] $$<,$$(odb) $$(cpp_options) \ +$$(call odb-expand-cpp-options,$$^) $$(cxx_pp_extra_options) $$(odb_options) \ +--database $1 --output-dir $$(dir $$@) $$<) + +$$(odb_$1_pattern): $$(out_base)/%.$$(cxx_h_suffix) | $$$$(dir $$$$@). + $$(call message,odb [$1] $$<,$$(odb) $$(cpp_options) \ +$$(call odb-expand-cpp-options,$$^) $$(cxx_pp_extra_options) $$(odb_options) \ +--database $1 --output-dir $$(dir $$@) $$<) + +endef # Trailing newline is important. endif +$(foreach d,$(odb_databases),$(eval $(call odb-db-rule,$d))) + +# Clean. +# .PHONY: $(out_base)/%-odb.cxx.hxx.clean $(out_base)/%-odb.cxx.hxx.clean: cxx_s_suffix := $(cxx_s_suffix) @@ -59,3 +109,20 @@ $(out_base)/%-odb.cxx.hxx.clean: $(call message,rm $$1,rm -f $$1,$(@:.cxx.hxx.clean=.$(cxx_h_suffix))) $(call message,rm $$1,rm -f $$1,$(@:.cxx.hxx.clean=.$(cxx_i_suffix))) $(call message,rm $$1,rm -f $$1,$(@:-odb.cxx.hxx.clean=.sql)) + +define odb-db-clean-rule +.PHONY: $$(out_base)/%-odb-$1.cxx.hxx.clean + +$$(out_base)/%-odb-$1.cxx.hxx.clean: cxx_s_suffix := $$(cxx_s_suffix) +$$(out_base)/%-odb-$1.cxx.hxx.clean: cxx_h_suffix := $$(cxx_h_suffix) +$$(out_base)/%-odb-$1.cxx.hxx.clean: cxx_i_suffix := $$(cxx_i_suffix) + +$$(out_base)/%-odb-$1.cxx.hxx.clean: + $$(call message,rm $$$$1,rm -f $$$$1,$$(@:.cxx.hxx.clean=.$$(cxx_s_suffix))) + $$(call message,rm $$$$1,rm -f $$$$1,$$(@:.cxx.hxx.clean=.$$(cxx_h_suffix))) + $$(call message,rm $$$$1,rm -f $$$$1,$$(@:.cxx.hxx.clean=.$$(cxx_i_suffix))) + $$(call message,rm $$$$1,rm -f $$$$1,$$(@:-odb-$1.cxx.hxx.clean=-$1.sql)) + +endef # Trailing newline is important. + +$(foreach d,$(odb_databases),$(eval $(call odb-db-clean-rule,$d))) |