11
11
! >[executable.dependencies]
12
12
! >```
13
13
module fpm_manifest_executable
14
- use fpm_manifest_dependency, only : dependency_config_t, new_dependencies
15
- use fpm_error, only : error_t, syntax_error, bad_name_error
16
- use fpm_strings, only : string_t
17
- use fpm_toml, only : toml_table, toml_key, toml_stat, get_value, get_list
14
+ use fpm_manifest_dependency, only : dependency_config_t, new_dependencies, resize
15
+ use fpm_error, only : error_t, syntax_error, bad_name_error, fatal_error
16
+ use fpm_strings, only : string_t, operator (==)
17
+ use fpm_toml, only : toml_table, toml_key, toml_stat, get_value, get_list, serializable_t, add_table, &
18
+ set_string, set_list
18
19
implicit none
19
20
private
20
21
21
22
public :: executable_config_t, new_executable
22
23
23
24
24
25
! > Configuation meta data for an executable
25
- type :: executable_config_t
26
+ type, extends(serializable_t) :: executable_config_t
26
27
27
28
! > Name of the resulting executable
28
29
character (len= :), allocatable :: name
@@ -44,8 +45,15 @@ module fpm_manifest_executable
44
45
! > Print information on this instance
45
46
procedure :: info
46
47
48
+ ! > Serialization interface
49
+ procedure :: serializable_is_same = > exe_is_same
50
+ procedure :: dump_to_toml
51
+ procedure :: load_from_toml
52
+
47
53
end type executable_config_t
48
54
55
+ character (* ), parameter , private :: class_name = ' executable_config_t'
56
+
49
57
50
58
contains
51
59
@@ -186,4 +194,156 @@ subroutine info(self, unit, verbosity)
186
194
end subroutine info
187
195
188
196
197
+ logical function exe_is_same (this ,that )
198
+ class(executable_config_t), intent (in ) :: this
199
+ class(serializable_t), intent (in ) :: that
200
+
201
+ integer :: ii
202
+
203
+ exe_is_same = .false.
204
+
205
+ select type (other= >that)
206
+ type is (executable_config_t)
207
+ if (.not. this% link== other% link) return
208
+ if (.not. allocated (this% name).eqv. allocated (other% name)) return
209
+ if (.not. this% name== other% name) return
210
+ if (.not. allocated (this% source_dir).eqv. allocated (other% source_dir)) return
211
+ if (.not. this% source_dir== other% source_dir) return
212
+ if (.not. allocated (this% main).eqv. allocated (other% main)) return
213
+ if (.not. this% main== other% main) return
214
+ if (.not. allocated (this% dependency).eqv. allocated (other% dependency)) return
215
+ if (allocated (this% dependency)) then
216
+ if (.not. (size (this% dependency)==size (other% dependency))) return
217
+ do ii = 1 , size (this% dependency)
218
+ if (.not. (this% dependency(ii)==other% dependency(ii))) return
219
+ end do
220
+ end if
221
+ class default
222
+ ! Not the same type
223
+ return
224
+ end select
225
+
226
+ ! > All checks passed!
227
+ exe_is_same = .true.
228
+
229
+ end function exe_is_same
230
+
231
+ ! > Dump install config to toml table
232
+ subroutine dump_to_toml (self , table , error )
233
+
234
+ ! > Instance of the serializable object
235
+ class(executable_config_t), intent (inout ) :: self
236
+
237
+ ! > Data structure
238
+ type (toml_table), intent (inout ) :: table
239
+
240
+ ! > Error handling
241
+ type (error_t), allocatable , intent (out ) :: error
242
+
243
+ ! > Local variables
244
+ integer :: ierr, ii
245
+ type (toml_table), pointer :: ptr_deps,ptr
246
+ character (27 ) :: unnamed
247
+
248
+ call set_string(table, " name" , self% name, error)
249
+ if (allocated (error)) return
250
+ call set_string(table, " source-dir" , self% source_dir, error)
251
+ if (allocated (error)) return
252
+ call set_string(table, " main" , self% main, error)
253
+ if (allocated (error)) return
254
+
255
+ if (allocated (self% dependency)) then
256
+
257
+ ! Create dependency table
258
+ call add_table(table, " dependencies" , ptr_deps)
259
+ if (.not. associated (ptr_deps)) then
260
+ call fatal_error(error, class_name// " cannot create dependency table " )
261
+ return
262
+ end if
263
+
264
+ do ii = 1 , size (self% dependency)
265
+ associate (dep = > self% dependency(ii))
266
+
267
+ ! > Because dependencies are named, fallback if this has no name
268
+ ! > So, serialization will work regardless of size(self%dep) == self%ndep
269
+ if (len_trim (dep% name)==0 ) then
270
+ write (unnamed,1 ) ii
271
+ call add_table(ptr_deps, trim (unnamed), ptr)
272
+ else
273
+ call add_table(ptr_deps, dep% name, ptr)
274
+ end if
275
+ if (.not. associated (ptr)) then
276
+ call fatal_error(error, class_name// " cannot create entry for dependency " // dep% name)
277
+ return
278
+ end if
279
+ call dep% dump_to_toml(ptr, error)
280
+ if (allocated (error)) return
281
+ end associate
282
+ end do
283
+
284
+ endif
285
+
286
+ call set_list(table, " link" , self% link, error)
287
+ if (allocated (error)) return
288
+
289
+ 1 format (' UNNAMED_DEPENDENCY_' ,i0)
290
+
291
+ end subroutine dump_to_toml
292
+
293
+ ! > Read install config from toml table (no checks made at this stage)
294
+ subroutine load_from_toml (self , table , error )
295
+
296
+ ! > Instance of the serializable object
297
+ class(executable_config_t), intent (inout ) :: self
298
+
299
+ ! > Data structure
300
+ type (toml_table), intent (inout ) :: table
301
+
302
+ ! > Error handling
303
+ type (error_t), allocatable , intent (out ) :: error
304
+
305
+ ! > Local variables
306
+ type (toml_key), allocatable :: keys(:),dep_keys(:)
307
+ type (toml_table), pointer :: ptr_deps,ptr
308
+ integer :: ii, jj, ierr
309
+
310
+ call table% get_keys(keys)
311
+
312
+ call get_value(table, " name" , self% name)
313
+ if (allocated (error)) return
314
+ call get_value(table, " source-dir" , self% source_dir)
315
+ if (allocated (error)) return
316
+ call get_value(table, " main" , self% main)
317
+ if (allocated (error)) return
318
+ call get_list(table, " link" , self% link, error)
319
+
320
+ find_deps_table: do ii = 1 , size (keys)
321
+ if (keys(ii)% key==" dependencies" ) then
322
+
323
+ call get_value(table, keys(ii), ptr_deps)
324
+ if (.not. associated (ptr_deps)) then
325
+ call fatal_error(error,class_name// ' : error retrieving dependency table from TOML table' )
326
+ return
327
+ end if
328
+
329
+ ! > Read all dependencies
330
+ call ptr_deps% get_keys(dep_keys)
331
+ call resize(self% dependency, size (dep_keys))
332
+
333
+ do jj = 1 , size (dep_keys)
334
+
335
+ call get_value(ptr_deps, dep_keys(jj), ptr)
336
+ call self% dependency(jj)% load_from_toml(ptr, error)
337
+ if (allocated (error)) return
338
+
339
+ end do
340
+
341
+ exit find_deps_table
342
+
343
+ endif
344
+ end do find_deps_table
345
+
346
+ end subroutine load_from_toml
347
+
348
+
189
349
end module fpm_manifest_executable
0 commit comments