Skip to content

Commit 819e0eb

Browse files
committed
preprocess_config_t: make serializable and test
1 parent 5c6dcfc commit 819e0eb

File tree

4 files changed

+102
-6
lines changed

4 files changed

+102
-6
lines changed

src/fpm/manifest/fortran.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ module fpm_manifest_fortran
2525
procedure :: dump_to_toml
2626
procedure :: load_from_toml
2727

28-
2928
end type fortran_config_t
3029

3130
character(len=*), parameter, private :: class_name = 'fortran_config_t'

src/fpm/manifest/install.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module fpm_manifest_install
3131

3232
end type install_config_t
3333

34-
character(*), parameter :: class_name = 'install_config_t'
34+
character(*), parameter, private :: class_name = 'install_config_t'
3535

3636
contains
3737

src/fpm/manifest/preprocess.f90

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212

1313
module fpm_manifest_preprocess
1414
use fpm_error, only : error_t, syntax_error
15-
use fpm_strings, only : string_t
16-
use fpm_toml, only : toml_table, toml_key, toml_stat, get_value, get_list
15+
use fpm_strings, only : string_t, operator(==)
16+
use fpm_toml, only : toml_table, toml_key, toml_stat, get_value, get_list, serializable_t, set_value, set_list, &
17+
set_string
1718
implicit none
1819
private
1920

2021
public :: preprocess_config_t, new_preprocess_config, new_preprocessors
2122

2223
!> Configuration meta data for a preprocessor
23-
type :: preprocess_config_t
24+
type, extends(serializable_t) :: preprocess_config_t
2425

2526
!> Name of the preprocessor
2627
character(len=:), allocatable :: name
@@ -39,8 +40,15 @@ module fpm_manifest_preprocess
3940
!> Print information on this instance
4041
procedure :: info
4142

43+
!> Serialization interface
44+
procedure :: serializable_is_same => preprocess_is_same
45+
procedure :: dump_to_toml
46+
procedure :: load_from_toml
47+
4248
end type preprocess_config_t
4349

50+
character(*), parameter, private :: class_name = 'preprocess_config_t'
51+
4452
contains
4553

4654
!> Construct a new preprocess configuration from TOML data structure
@@ -154,7 +162,7 @@ subroutine info(self, unit, verbosity)
154162
pr = 1
155163
end if
156164

157-
if (pr < 1) return
165+
if (pr < 1) return
158166

159167
write(unit, fmt) "Preprocessor"
160168
if (allocated(self%name)) then
@@ -181,4 +189,75 @@ subroutine info(self, unit, verbosity)
181189

182190
end subroutine info
183191

192+
logical function preprocess_is_same(this,that)
193+
class(preprocess_config_t), intent(in) :: this
194+
class(serializable_t), intent(in) :: that
195+
196+
preprocess_is_same = .false.
197+
198+
select type (other=>that)
199+
type is (preprocess_config_t)
200+
if (allocated(this%name).neqv.allocated(other%name)) return
201+
if (allocated(this%name)) then
202+
if (.not.(this%name==other%name)) return
203+
endif
204+
if (.not.(this%suffixes==other%suffixes)) return
205+
if (.not.(this%directories==other%directories)) return
206+
if (.not.(this%macros==other%macros)) return
207+
208+
class default
209+
! Not the same type
210+
return
211+
end select
212+
213+
!> All checks passed!
214+
preprocess_is_same = .true.
215+
216+
end function preprocess_is_same
217+
218+
!> Dump install config to toml table
219+
subroutine dump_to_toml(self, table, error)
220+
221+
!> Instance of the serializable object
222+
class(preprocess_config_t), intent(inout) :: self
223+
224+
!> Data structure
225+
type(toml_table), intent(inout) :: table
226+
227+
!> Error handling
228+
type(error_t), allocatable, intent(out) :: error
229+
230+
call set_string(table, "name", self%name, error)
231+
if (allocated(error)) return
232+
call set_list(table, "suffixes", self%suffixes, error)
233+
if (allocated(error)) return
234+
call set_list(table, "directories", self%directories, error)
235+
if (allocated(error)) return
236+
call set_list(table, "macros", self%macros, error)
237+
if (allocated(error)) return
238+
239+
end subroutine dump_to_toml
240+
241+
!> Read install config from toml table (no checks made at this stage)
242+
subroutine load_from_toml(self, table, error)
243+
244+
!> Instance of the serializable object
245+
class(preprocess_config_t), intent(inout) :: self
246+
247+
!> Data structure
248+
type(toml_table), intent(inout) :: table
249+
250+
!> Error handling
251+
type(error_t), allocatable, intent(out) :: error
252+
253+
call get_value(table, "name", self%name)
254+
call get_list(table, "suffixes", self%suffixes, error)
255+
if (allocated(error)) return
256+
call get_list(table, "directories", self%directories, error)
257+
if (allocated(error)) return
258+
call get_list(table, "macros", self%macros, error)
259+
if (allocated(error)) return
260+
261+
end subroutine load_from_toml
262+
184263
end module fpm_manifest_preprocess

test/fpm_test/test_toml.f90

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module test_toml
1111
use fpm_manifest_fortran
1212
use fpm_manifest_library
1313
use fpm_manifest_executable
14+
use fpm_manifest_preprocess
1415
use fpm_versioning, only: new_version
1516
use fpm_strings, only: string_t, operator(==), split
1617
use fpm_model, only: fortran_features_t, package_t, FPM_SCOPE_LIB, FPM_UNIT_MODULE, fpm_model_t, &
@@ -50,6 +51,8 @@ subroutine collect_toml(testsuite)
5051
& new_unittest("serialize-install-config", install_config_roundtrip), &
5152
& new_unittest("serialize-fortran-config", fortran_features_roundtrip), &
5253
& new_unittest("serialize-library-config", library_config_roundtrip), &
54+
& new_unittest("serialize-executable-config", executable_config_roundtrip), &
55+
& new_unittest("serialize-preprocess-config", preprocess_config_roundtrip), &
5356
& new_unittest("serialize-string-array", string_array_roundtrip), &
5457
& new_unittest("serialize-fortran-features", fft_roundtrip), &
5558
& new_unittest("serialize-fortran-invalid", fft_invalid, should_fail=.true.), &
@@ -1253,4 +1256,19 @@ subroutine executable_config_roundtrip(error)
12531256

12541257
end subroutine executable_config_roundtrip
12551258

1259+
1260+
subroutine preprocess_config_roundtrip(error)
1261+
1262+
!> Error handling
1263+
type(error_t), allocatable, intent(out) :: error
1264+
1265+
type(preprocess_config_t) :: prep
1266+
1267+
prep%name = "preprocessor config"
1268+
prep%macros = [string_t('Whatever'),string_t('FPM_BOOTSTRAP')]
1269+
1270+
call prep%test_serialization('preprocess_config', error)
1271+
1272+
end subroutine preprocess_config_roundtrip
1273+
12561274
end module test_toml

0 commit comments

Comments
 (0)