aboutsummaryrefslogtreecommitdiff
path: root/build/root.build
blob: 53363999890020e42951129c835c37084b2c91b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# file      : build/root.build
# license   : GNU GPL v2; see accompanying LICENSE file

cxx.std = latest

using cxx

hxx{*}: extension = hxx
ixx{*}: extension = ixx
txx{*}: extension = txx
cxx{*}: extension = cxx

# List of the identifiers of the databases to compile and run the tests
# against. The valid identifiers are mysql, sqlite, pgsql, oracle, and mssql.
#
# @@ TODO: change to string_set once available.
#
config [strings] config.odb_tests.database

assert ($defined(config.odb_tests.database) && \
        $size($config.odb_tests.database) > 0) \
'at least one database must be configured via config.odb_tests.database variable'

databases = $config.odb_tests.database

mysql  = false
sqlite = false
pgsql  = false
oracle = false
mssql  = false

for db: $databases
{
  switch $db
  {
    case 'mysql'
      mysql = true

    case 'sqlite'
      sqlite = true

    case 'pgsql'
      pgsql = true

    case 'oracle'
      oracle = true

    case 'mssql'
      mssql = true

    default
      fail "invalid database '$db' specified in config.odb_tests.database value"
  }
}

# If true, then build and run the test drivers in the dynamic multi-database
# mode.
#
config [bool] config.odb_tests.multi_database ?= ($size($databases) > 1)
multi = $config.odb_tests.multi_database

assert ($multi || $size($databases) == 1) \
'only one database can be configured if config.odb_tests.multi_database value is false'

# Database connections.
#

# PostgreSQL
#
# The database user. Note that the named user must be allowed to connect to
# the database server without specifying credentials.
#
config [string] config.odb_tests.pgsql.user ?= 'odb_test'

# The database name. Note that it WILL BE MODIFIED by the tests.
#
config [string] config.odb_tests.pgsql.database ?= 'odb_test'

# The database host. Leaving this variable undefined results in using
# Unix-domain sockets. Machines without Unix-domain sockets will connect to
# localhost.
#
config [string] config.odb_tests.pgsql.host

# The database port or the socket file name extension for Unix-domain
# connections.
#
config [string] config.odb_tests.pgsql.port

# If true, then assume that libodb-pgsql supports the bulk operations.
#
# Note: config.odb_tests.pgsql.bulk_default is reflected from manifest.
#
config [bool] config.odb_tests.pgsql.bulk_default ?= false
config [bool] config.odb_tests.pgsql.bulk ?= ($cxx.target.class != 'windows' && \
                                              $config.odb_tests.pgsql.bulk_default)
pgsql_bulk = $config.odb_tests.pgsql.bulk

# MySQL
#
# The database user.
#
config [string] config.odb_tests.mysql.user ?= 'odb_test'

# The database password.
#
config [string] config.odb_tests.mysql.passwd

# The database name. Note that it WILL BE MODIFIED by the tests.
#
config [string] config.odb_tests.mysql.database ?= 'odb_test'

# The database host.
#
config [string] config.odb_tests.mysql.host

# The database port.
#
config [uint64] config.odb_tests.mysql.port

# The database socket path.
#
config [path] config.odb_tests.mysql.socket

define sql: file
sql{*}: extension = sql

define xml: file
xml{*}: extension = xml

if ($build.mode != 'skeleton')
{
  if ($cxx.target.system == 'win32-msvc')
    cxx.poptions += -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS

  switch $cxx.class
  {
    case 'gcc'
    {
      cxx.coptions += -Wno-unknown-pragmas
    }
    case 'msvc'
    {
      cxx.coptions += /wd4068 /wd4251 /wd4275 /wd4800
    }
  }

  # @@ BUILD2 Clang issues the following warnings while compile the
  #           odb-generated headers:
  #
  #    In file included from odb-tests/common/view/olv/test1-odb-sqlite.cxx:10:
  #    odb-tests/common/view/olv/test1-odb-sqlite.hxx:68:80: warning: instantiation of variable 'odb::query_columns<test1::object1, odb::id_common, odb::access::object_traits_impl< ::test1::object1, id_common>>::id' required here, but no definition is available [-Wundefined-var-template]
  #       68 |   id (query_columns< ::test1::object1, id_common, typename A::common_traits >::id,
  #          |                                                                                ^
  #    odb-tests/common/view/olv/test1-odb.hxx:91:21: note: forward declaration of template entity is here
  #       91 |     static id_type_ id;
  #          |                     ^
  #    odb-tests/common/view/olv/test1-odb-sqlite.hxx:68:80: note: add an explicit instantiation declaration to suppress this warning if 'odb::query_columns<test1::object1, odb::id_common, odb::access::object_traits_impl< ::test1::object1, id_common>>::id' is explicitly instantiated in another translation unit
  #       68 |   id (query_columns< ::test1::object1, id_common, typename A::common_traits >::id,
  #
  #    Note: -Wno-undefined-var-template is temporarily added to suppress them.
  #
  if ($cxx.id.type == 'clang')
    cxx.coptions += -Wno-undefined-var-template

  # Import odb that we are testing.
  #
  import! [metadata] odb = odb%exe{odb}

  # Import the mysql client for creating the database schemas, etc.
  #
  if $mysql
  {
    import! mysql_client = mysql%exe{mysql}
    testscript{*}: mysql_client = $mysql_client
  }

  # Import the psql client for creating the database schemas, etc.
  #
  if $pgsql
  {
    import! pgsql_client = psql%exe{psql}
    testscript{*}: pgsql_client = $pgsql_client
  }

  # Note that we need ((-.+)?) instead of just (-.+)? because we use this
  # capture as a back-reference in the pattern.
  #
  [rule_name=odb_compile]                                     \
  <hxx{~'/(.+)-odb((-.+)?)/'}                                 \
   ixx{~'/\1-odb\2/'}                                         \
   cxx{~'/\1-odb\2/'}>: hxx{~'/\1/'} libue{~'/.+-meta/'} $odb
  {{
    pops = $cxx.lib_poptions($<[1])
    depdb hash $pops

    hp = $path($>[0])
    bn = $base($leaf($hp))
    db = $regex.replace($bn, '.+-odb(-(.+))?', '\2')

    if ($db == '') # *-odb.?xx target group?
      db = ($multi ? 'common' : $databases[0])
    end

    # If the external SQL schema file will be generated, then add it as a
    # dynamic target group member.
    #
    # @@ BUILD2 Probably we should add support for --generate-dep ODB compiler
    # option. Then presumably this will be take care of automatically.
    #
    # We assume that the '--generate-schema' and '--schema-format' strings
    # will never appear as standalone option values.
    #
    if ($db != 'common' && $regex.find_match($odb_options, '--generate-schema'))
      schema_format = ($db == 'sqlite' ? 'embedded' : 'sql')

      for o: $odb_options
        if ($o == '--schema-format')
          schema_format = [null] # Indicate that the schema format comes next.
        elif ($schema_format == [null])
          schema_format = $o
        end
      end
    else
      schema_format = ''
    end

    t = ($schema_format == 'sql'                                             \
         ? $directory($hp)/$regex.replace($bn, '(.+)-odb(-.+)?', '\1\2').sql \
         : '')

    depdb dyndep --dyn-target --target-what 'generated schema' --format lines \
    -- echo "$t"

    $odb --std c++11                            \
         ($multi ? --multi-database dynamic : ) \
         --database $db                         \
         --output-dir $out_base                 \
         $odb_options                           \
         "-I$src_base"                          \
         $pops                                  \
         $path($<[0])
  }}

  # Every exe{} in this project is by default a test.
  #
  exe{*}: test = true

  # Specify the test target for cross-testing.
  #
  test.target = $cxx.target
}

# The helper targets which can be used as prerequisites of test drivers
# which require either a specific database client or multiple clients for
# all the enabled databases.
#
alias{mysql-client}: $mysql_client:
{
  include = $mysql
  clean = false
}

alias{pgsql-client}: $pgsql_client:
{
  include = $pgsql
  clean = false
}

alias{database-client}: alias{mysql-client pgsql-client}