Debian Codegraph @

src/fpm/manifest/install.f90

raw
1 !> Implementation of the installation configuration.
2 !>
3 !> An install table can currently have the following fields
4 !>
5 !>```toml
6 !>library = bool
7 !>module-dir = "path"
8 !>```
9 module fpm_manifest_install
10 use fpm_error, only : error_t, fatal_error, syntax_error
11 use tomlf, only : toml_table, toml_key, toml_stat
12 use fpm_toml, only : get_value, set_value, serializable_t, set_string
13 implicit none
14 private
15
16 public :: install_config_t, new_install_config
17
18 !> Configuration data for installation
19 type, extends(serializable_t) :: install_config_t
20
21 !> Install library with this project
22 logical :: library = .false.
23
24 !> Install tests with this project
25 logical :: test = .false.
26
27 !> Directory where compiled module files should be installed
28 character(len=:), allocatable :: module_dir
29
30 contains
31
32 !> Print information on this instance
33 procedure :: info
34
35 !> Serialization interface
36 procedure :: serializable_is_same => install_conf_same
37 procedure :: dump_to_toml
38 procedure :: load_from_toml
39
40 end type install_config_t
41
42 character(*), parameter, private :: class_name = 'install_config_t'
43
44 contains
45
46 !> Create a new installation configuration from a TOML data structure
47 subroutine new_install_config(self, table, error)
48
49 !> Instance of the install configuration
50 type(install_config_t), intent(out) :: self
51
52 !> Instance of the TOML data structure
53 type(toml_table), intent(inout) :: table
54
55 !> Error handling
56 type(error_t), allocatable, intent(out) :: error
57
58 call check(table, error)
59 if (allocated(error)) return
60
61 call get_value(table, "library", self%library, .false.)
62 call get_value(table, "test", self%test, .false.)
63 call get_value(table, "module-dir", self%module_dir)
64
65 end subroutine new_install_config
66
67
68 !> Check local schema for allowed entries
69 subroutine check(table, error)
70
71 !> Instance of the TOML data structure
72 type(toml_table), intent(inout) :: table
73
74 !> Error handling
75 type(error_t), allocatable, intent(out) :: error
76
77 type(toml_key), allocatable :: list(:)
78 integer :: ikey
79
80 call table%get_keys(list)
81 if (size(list) < 1) return
82
83 do ikey = 1, size(list)
84 select case(list(ikey)%key)
85 case default
86 call syntax_error(error, "Key "//list(ikey)%key//" is not allowed in install table")
87 exit
88 case("library","test","module-dir")
89 continue
90 end select
91 end do
92 if (allocated(error)) return
93
94 end subroutine check
95
96 !> Write information on install configuration instance
97 subroutine info(self, unit, verbosity)
98
99 !> Instance of the build configuration
100 class(install_config_t), intent(in) :: self
101
102 !> Unit for IO
103 integer, intent(in) :: unit
104
105 !> Verbosity of the printout
106 integer, intent(in), optional :: verbosity
107
108 integer :: pr
109 character(len=*), parameter :: fmt = '("#", 1x, a, t30, a)'
110
111 if (present(verbosity)) then
112 pr = verbosity
113 else
114 pr = 1
115 end if
116
117 if (pr < 1) return
118
119 write(unit, fmt) "Install configuration"
120 write(unit, fmt) " - library install", trim(merge("enabled ", "disabled", self%library))
121 write(unit, fmt) " - test install", trim(merge("enabled ", "disabled", self%test))
122 if (allocated(self%module_dir)) then
123 write(unit, fmt) " - module directory", self%module_dir
124 end if
125
126 end subroutine info
127
128 logical function install_conf_same(this,that)
129 class(install_config_t), intent(in) :: this
130 class(serializable_t), intent(in) :: that
131
132 install_conf_same = .false.
133
134 select type (other=>that)
135 type is (install_config_t)
136 if (this%library.neqv.other%library) return
137 if (this%test.neqv.other%test) return
138 if (allocated(this%module_dir).neqv.allocated(other%module_dir)) return
139 if (allocated(this%module_dir)) then
140 if (.not.(this%module_dir==other%module_dir)) return
141 end if
142 class default
143 ! Not the same type
144 return
145 end select
146
147 !> All checks passed!
148 install_conf_same = .true.
149
150 end function install_conf_same
151
152 !> Dump install config to toml table
153 subroutine dump_to_toml(self, table, error)
154
155 !> Instance of the serializable object
156 class(install_config_t), intent(inout) :: self
157
158 !> Data structure
159 type(toml_table), intent(inout) :: table
160
161 !> Error handling
162 type(error_t), allocatable, intent(out) :: error
163
164 call set_value(table, "library", self%library, error, class_name)
165 if (allocated(error)) return
166
167 call set_value(table, "test", self%test, error, class_name)
168 if (allocated(error)) return
169
170 call set_string(table, "module-dir", self%module_dir, error, class_name)
171 if (allocated(error)) return
172
173 end subroutine dump_to_toml
174
175 !> Read install config from toml table (no checks made at this stage)
176 subroutine load_from_toml(self, table, error)
177
178 !> Instance of the serializable object
179 class(install_config_t), intent(inout) :: self
180
181 !> Data structure
182 type(toml_table), intent(inout) :: table
183
184 !> Error handling
185 type(error_t), allocatable, intent(out) :: error
186
187 integer :: stat
188
189 call get_value(table, "library", self%library, error, class_name)
190 if (allocated(error)) return
191 call get_value(table, "test", self%test, error, class_name)
192 if (allocated(error)) return
193 call get_value(table, "module-dir", self%module_dir)
194 if (allocated(error)) return
195
196 end subroutine load_from_toml
197
198 end module fpm_manifest_install