43
43
! >
44
44
module fpm_manifest_profile
45
45
use fpm_error, only : error_t, syntax_error, fatal_error, fpm_stop
46
- use fpm_toml, only : toml_table, toml_key, toml_stat, get_value
46
+ use fpm_toml, only : toml_table, toml_key, toml_stat, get_value, serializable_t, set_value, set_string
47
47
use fpm_strings, only: lower
48
48
use fpm_environment, only: get_os_type, OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_WINDOWS, &
49
49
OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD
@@ -53,19 +53,26 @@ module fpm_manifest_profile
53
53
& info_profile, find_profile, DEFAULT_COMPILER
54
54
55
55
! > Name of the default compiler
56
- character (len=* ), parameter :: DEFAULT_COMPILER = ' gfortran'
56
+ character (len=* ), parameter :: DEFAULT_COMPILER = ' gfortran'
57
57
integer , parameter :: OS_ALL = - 1
58
58
character (len= :), allocatable :: path
59
59
60
60
! > Type storing file name - file scope compiler flags pairs
61
- type :: file_scope_flag
61
+ type, extends(serializable_t) :: file_scope_flag
62
62
63
63
! > Name of the file
64
64
character (len= :), allocatable :: file_name
65
65
66
66
! > File scope flags
67
67
character (len= :), allocatable :: flags
68
68
69
+ contains
70
+
71
+ ! > Serialization interface
72
+ procedure :: serializable_is_same = > file_scope_same
73
+ procedure :: dump_to_toml = > file_scope_dump
74
+ procedure :: load_from_toml = > file_scope_load
75
+
69
76
end type file_scope_flag
70
77
71
78
! > Configuration meta data for a profile
@@ -78,7 +85,7 @@ module fpm_manifest_profile
78
85
79
86
! > Value repesenting OS
80
87
integer :: os_type
81
-
88
+
82
89
! > Fortran compiler flags
83
90
character (len= :), allocatable :: flags
84
91
@@ -110,16 +117,16 @@ module fpm_manifest_profile
110
117
function new_profile (profile_name , compiler , os_type , flags , c_flags , cxx_flags , &
111
118
link_time_flags , file_scope_flags , is_built_in ) &
112
119
& result(profile)
113
-
120
+
114
121
! > Name of the profile
115
122
character (len=* ), intent (in ) :: profile_name
116
-
123
+
117
124
! > Name of the compiler
118
125
character (len=* ), intent (in ) :: compiler
119
-
126
+
120
127
! > Type of the OS
121
128
integer , intent (in ) :: os_type
122
-
129
+
123
130
! > Fortran compiler flags
124
131
character (len=* ), optional , intent (in ) :: flags
125
132
@@ -190,7 +197,7 @@ subroutine validate_compiler_name(compiler_name, is_valid)
190
197
is_valid = .false.
191
198
end select
192
199
end subroutine validate_compiler_name
193
-
200
+
194
201
! > Check if os_name is a valid name of a supported OS
195
202
subroutine validate_os_name (os_name , is_valid )
196
203
@@ -373,10 +380,10 @@ subroutine get_flags(profile_name, compiler_name, os_type, key_list, table, prof
373
380
& flags, c_flags, cxx_flags, link_time_flags, file_scope_flags)
374
381
profindex = profindex + 1
375
382
end subroutine get_flags
376
-
383
+
377
384
! > Traverse operating system tables to obtain number of profiles
378
385
subroutine traverse_oss_for_size (profile_name , compiler_name , os_list , table , profiles_size , error )
379
-
386
+
380
387
! > Name of profile
381
388
character (len= :), allocatable , intent (in ) :: profile_name
382
389
@@ -447,7 +454,7 @@ end subroutine traverse_oss_for_size
447
454
448
455
! > Traverse operating system tables to obtain profiles
449
456
subroutine traverse_oss (profile_name , compiler_name , os_list , table , profiles , profindex , error )
450
-
457
+
451
458
! > Name of profile
452
459
character (len= :), allocatable , intent (in ) :: profile_name
453
460
@@ -468,7 +475,7 @@ subroutine traverse_oss(profile_name, compiler_name, os_list, table, profiles, p
468
475
469
476
! > Index in the list of profiles
470
477
integer , intent (inout ) :: profindex
471
-
478
+
472
479
type (toml_key), allocatable :: key_list(:)
473
480
character (len= :), allocatable :: os_name, l_os_name
474
481
type (toml_table), pointer :: os_node
@@ -513,7 +520,7 @@ end subroutine traverse_oss
513
520
514
521
! > Traverse compiler tables
515
522
subroutine traverse_compilers (profile_name , comp_list , table , error , profiles_size , profiles , profindex )
516
-
523
+
517
524
! > Name of profile
518
525
character (len= :), allocatable , intent (in ) :: profile_name
519
526
@@ -522,10 +529,10 @@ subroutine traverse_compilers(profile_name, comp_list, table, error, profiles_si
522
529
523
530
! > Table containing compiler tables
524
531
type (toml_table), pointer , intent (in ) :: table
525
-
532
+
526
533
! > Error handling
527
534
type (error_t), allocatable , intent (out ) :: error
528
-
535
+
529
536
! > Number of profiles in list of profiles
530
537
integer , intent (inout ), optional :: profiles_size
531
538
@@ -534,8 +541,8 @@ subroutine traverse_compilers(profile_name, comp_list, table, error, profiles_si
534
541
535
542
! > Index in the list of profiles
536
543
integer , intent (inout ), optional :: profindex
537
-
538
- character (len= :), allocatable :: compiler_name
544
+
545
+ character (len= :), allocatable :: compiler_name
539
546
type (toml_table), pointer :: comp_node
540
547
type (toml_key), allocatable :: os_list(:)
541
548
integer :: icomp, stat
@@ -544,7 +551,7 @@ subroutine traverse_compilers(profile_name, comp_list, table, error, profiles_si
544
551
if (size (comp_list)<1 ) return
545
552
do icomp = 1 , size (comp_list)
546
553
call validate_compiler_name(comp_list(icomp)% key, is_valid)
547
- if (is_valid) then
554
+ if (is_valid) then
548
555
compiler_name = comp_list(icomp)% key
549
556
call get_value(table, compiler_name, comp_node, stat= stat)
550
557
if (stat /= toml_stat% success) then
@@ -567,7 +574,7 @@ subroutine traverse_compilers(profile_name, comp_list, table, error, profiles_si
567
574
else
568
575
call fatal_error(error,' *traverse_compilers*:Error: Compiler name not specified or invalid.' )
569
576
end if
570
- end do
577
+ end do
571
578
end subroutine traverse_compilers
572
579
573
580
! > Construct new profiles array from a TOML data structure
@@ -596,9 +603,9 @@ subroutine new_profiles(profiles, table, error)
596
603
default_profiles = get_default_profiles(error)
597
604
if (allocated (error)) return
598
605
call table% get_keys(prof_list)
599
-
606
+
600
607
if (size (prof_list) < 1 ) return
601
-
608
+
602
609
profiles_size = 0
603
610
604
611
do iprof = 1 , size (prof_list)
@@ -633,7 +640,7 @@ subroutine new_profiles(profiles, table, error)
633
640
634
641
profiles_size = profiles_size + size (default_profiles)
635
642
allocate (profiles(profiles_size))
636
-
643
+
637
644
do profindex= 1 , size (default_profiles)
638
645
profiles(profindex) = default_profiles(profindex)
639
646
end do
@@ -954,4 +961,71 @@ subroutine find_profile(profiles, profile_name, compiler, os_type, found_matchin
954
961
end do
955
962
end if
956
963
end subroutine find_profile
964
+
965
+
966
+ logical function file_scope_same (this ,that )
967
+ class(file_scope_flag), intent (in ) :: this
968
+ class(serializable_t), intent (in ) :: that
969
+
970
+ file_scope_same = .false.
971
+
972
+ select type (other= >that)
973
+ type is (file_scope_flag)
974
+ if (allocated (this% file_name).neqv. allocated (other% file_name)) return
975
+ if (allocated (this% file_name)) then
976
+ if (.not. (this% file_name== other% file_name)) return
977
+ endif
978
+ if (allocated (this% flags).neqv. allocated (other% flags)) return
979
+ if (allocated (this% flags)) then
980
+ if (.not. (this% flags== other% flags)) return
981
+ endif
982
+
983
+ class default
984
+ ! Not the same type
985
+ return
986
+ end select
987
+
988
+ ! > All checks passed!
989
+ file_scope_same = .true.
990
+
991
+ end function file_scope_same
992
+
993
+ ! > Dump to toml table
994
+ subroutine file_scope_dump (self , table , error )
995
+
996
+ ! > Instance of the serializable object
997
+ class(file_scope_flag), intent (inout ) :: self
998
+
999
+ ! > Data structure
1000
+ type (toml_table), intent (inout ) :: table
1001
+
1002
+ ! > Error handling
1003
+ type (error_t), allocatable , intent (out ) :: error
1004
+
1005
+ call set_string(table, " file-name" , self% file_name, error)
1006
+ if (allocated (error)) return
1007
+ call set_string(table, " flags" , self% flags, error)
1008
+ if (allocated (error)) return
1009
+
1010
+ end subroutine file_scope_dump
1011
+
1012
+ ! > Read from toml table (no checks made at this stage)
1013
+ subroutine file_scope_load (self , table , error )
1014
+
1015
+ ! > Instance of the serializable object
1016
+ class(file_scope_flag), intent (inout ) :: self
1017
+
1018
+ ! > Data structure
1019
+ type (toml_table), intent (inout ) :: table
1020
+
1021
+ ! > Error handling
1022
+ type (error_t), allocatable , intent (out ) :: error
1023
+
1024
+ call get_value(table, " file-name" , self% file_name)
1025
+ call get_value(table, " flags" , self% flags)
1026
+
1027
+ end subroutine file_scope_load
1028
+
1029
+
1030
+
957
1031
end module fpm_manifest_profile
0 commit comments