| 1 |
!> Implementation of the metapackage configuration data. |
| 2 |
!> |
| 3 |
!> A metapackage table can currently have the following fields |
| 4 |
!> |
| 5 |
!>```toml |
| 6 |
!>[metapackages] |
| 7 |
!>fpm = "0.1.0" |
| 8 |
!>openmp = bool |
| 9 |
!>stdlib = bool |
| 10 |
!>``` |
| 11 |
module fpm_manifest_metapackages |
| 12 |
use fpm_error, only: error_t, fatal_error, syntax_error |
| 13 |
use tomlf, only: toml_table, toml_key |
| 14 |
use fpm_toml, only: get_value, set_value, set_string, add_table, serializable_t |
| 15 |
use fpm_environment |
| 16 |
implicit none |
| 17 |
private |
| 18 |
|
| 19 |
public :: metapackage_config_t, new_meta_config, is_meta_package |
| 20 |
public :: metapackage_request_t, new_meta_request |
| 21 |
|
| 22 |
!> Configuration data for a single metapackage request |
| 23 |
type, extends(serializable_t) :: metapackage_request_t |
| 24 |
|
| 25 |
!> Request flag |
| 26 |
logical :: on = .false. |
| 27 |
|
| 28 |
!> Metapackage name |
| 29 |
character(len=:), allocatable :: name |
| 30 |
|
| 31 |
!> Version Specification string |
| 32 |
character(len=:), allocatable :: version |
| 33 |
|
| 34 |
contains |
| 35 |
|
| 36 |
procedure :: serializable_is_same => meta_request_same |
| 37 |
procedure :: dump_to_toml => meta_request_dump |
| 38 |
procedure :: load_from_toml => meta_request_load |
| 39 |
|
| 40 |
end type metapackage_request_t |
| 41 |
|
| 42 |
|
| 43 |
!> Configuration data for metapackages |
| 44 |
type, extends(serializable_t) :: metapackage_config_t |
| 45 |
|
| 46 |
!> Request MPI support |
| 47 |
type(metapackage_request_t) :: mpi |
| 48 |
|
| 49 |
!> Request OpenMP support |
| 50 |
type(metapackage_request_t) :: openmp |
| 51 |
|
| 52 |
!> Request stdlib support |
| 53 |
type(metapackage_request_t) :: stdlib |
| 54 |
|
| 55 |
!> fortran-lang minpack |
| 56 |
type(metapackage_request_t) :: minpack |
| 57 |
|
| 58 |
!> HDF5 |
| 59 |
type(metapackage_request_t) :: hdf5 |
| 60 |
|
| 61 |
!> NetCDF |
| 62 |
type(metapackage_request_t) :: netcdf |
| 63 |
|
| 64 |
!> BLAS |
| 65 |
type(metapackage_request_t) :: blas |
| 66 |
|
| 67 |
contains |
| 68 |
|
| 69 |
procedure :: get_requests |
| 70 |
|
| 71 |
!> Merge another config into this one (for propagating dependency metapackages) |
| 72 |
procedure :: merge => meta_config_merge |
| 73 |
|
| 74 |
! Cleanup configuration; assert package names |
| 75 |
final :: meta_config_final |
| 76 |
procedure :: reset => meta_config_reset |
| 77 |
|
| 78 |
procedure :: serializable_is_same => meta_config_same |
| 79 |
procedure :: dump_to_toml => meta_config_dump |
| 80 |
procedure :: load_from_toml => meta_config_load |
| 81 |
|
| 82 |
end type metapackage_config_t |
| 83 |
|
| 84 |
|
| 85 |
contains |
| 86 |
|
| 87 |
!> Destroy a metapackage request |
| 88 |
elemental subroutine request_destroy(self) |
| 89 |
class(metapackage_request_t), intent(inout) :: self |
| 90 |
self%on = .false. |
| 91 |
if (allocated(self%version)) deallocate(self%version) |
| 92 |
if (allocated(self%name)) deallocate(self%name) |
| 93 |
end subroutine request_destroy |
| 94 |
|
| 95 |
!> Parse version string of a metapackage request |
| 96 |
subroutine request_parse(self, version_request, error) |
| 97 |
|
| 98 |
! Instance of this metapackage |
| 99 |
type(metapackage_request_t), intent(inout) :: self |
| 100 |
|
| 101 |
! Parse version request |
| 102 |
character(len=*), intent(in) :: version_request |
| 103 |
|
| 104 |
! Error message |
| 105 |
type(error_t), allocatable, intent(out) :: error |
| 106 |
|
| 107 |
! wildcard = use any versions |
| 108 |
if (version_request=="*") then |
| 109 |
|
| 110 |
! Any version is OK |
| 111 |
self%on = .true. |
| 112 |
self%version = version_request |
| 113 |
|
| 114 |
else |
| 115 |
|
| 116 |
call fatal_error(error,'Value <'//version_request//'> for metapackage '//self%name//& |
| 117 |
'is not currently supported. Try "*" instead. ') |
| 118 |
return |
| 119 |
|
| 120 |
end if |
| 121 |
|
| 122 |
end subroutine request_parse |
| 123 |
|
| 124 |
!> Construct a new metapackage request from the dependencies table |
| 125 |
subroutine new_meta_request(self, key, table, meta_allowed, error) |
| 126 |
type(metapackage_request_t), intent(out) :: self |
| 127 |
|
| 128 |
!> The package name |
| 129 |
character(len=*), intent(in) :: key |
| 130 |
|
| 131 |
!> Instance of the TOML data structure |
| 132 |
type(toml_table), intent(inout) :: table |
| 133 |
|
| 134 |
!> List of keys allowed to be metapackages |
| 135 |
logical, intent(in), optional :: meta_allowed(:) |
| 136 |
|
| 137 |
!> Error handling |
| 138 |
type(error_t), allocatable, intent(out) :: error |
| 139 |
|
| 140 |
integer :: i |
| 141 |
character(len=:), allocatable :: value |
| 142 |
logical, allocatable :: allow_meta(:) |
| 143 |
type(toml_key), allocatable :: keys(:) |
| 144 |
|
| 145 |
call request_destroy(self) |
| 146 |
|
| 147 |
!> Set name |
| 148 |
self%name = key |
| 149 |
if (.not.is_meta_package(key)) then |
| 150 |
call fatal_error(error,"Error reading fpm.toml: <"//key//"> is not a valid metapackage name") |
| 151 |
return |
| 152 |
end if |
| 153 |
|
| 154 |
call table%get_keys(keys) |
| 155 |
|
| 156 |
if (present(meta_allowed)) then |
| 157 |
if (size(meta_allowed)/=size(keys)) then |
| 158 |
call fatal_error(error,"Internal error: list of metapackage-enable entries does not match table size") |
| 159 |
return |
| 160 |
end if |
| 161 |
allow_meta = meta_allowed |
| 162 |
else |
| 163 |
allocate(allow_meta(size(keys)),source=.true.) |
| 164 |
endif |
| 165 |
|
| 166 |
do i=1,size(keys) |
| 167 |
if (.not.allow_meta(i)) cycle |
| 168 |
if (keys(i)%key==key) then |
| 169 |
call get_value(table, key, value) |
| 170 |
if (.not. allocated(value)) then |
| 171 |
call syntax_error(error, "Could not retrieve version string for metapackage key <"//key//">. Check syntax") |
| 172 |
return |
| 173 |
else |
| 174 |
call request_parse(self, value, error) |
| 175 |
return |
| 176 |
endif |
| 177 |
end if |
| 178 |
end do |
| 179 |
! If we reach here, key not present => request remains off |
| 180 |
end subroutine new_meta_request |
| 181 |
|
| 182 |
!> Construct a new build configuration from a TOML data structure |
| 183 |
subroutine new_meta_config(self, table, meta_allowed, error) |
| 184 |
|
| 185 |
!> Instance of the build configuration |
| 186 |
type(metapackage_config_t), intent(out) :: self |
| 187 |
|
| 188 |
!> Instance of the TOML data structure |
| 189 |
type(toml_table), intent(inout) :: table |
| 190 |
|
| 191 |
!> List of keys allowed to be metapackages |
| 192 |
logical, intent(in) :: meta_allowed(:) |
| 193 |
|
| 194 |
!> Error handling |
| 195 |
type(error_t), allocatable, intent(out) :: error |
| 196 |
|
| 197 |
integer :: stat |
| 198 |
|
| 199 |
!> The toml table is not checked here because it already passed |
| 200 |
!> the "new_dependencies" check |
| 201 |
call new_meta_request(self%openmp, "openmp", table, meta_allowed, error) |
| 202 |
if (allocated(error)) return |
| 203 |
|
| 204 |
call new_meta_request(self%stdlib, "stdlib", table, meta_allowed, error) |
| 205 |
if (allocated(error)) return |
| 206 |
|
| 207 |
call new_meta_request(self%minpack, "minpack", table, meta_allowed, error) |
| 208 |
if (allocated(error)) return |
| 209 |
|
| 210 |
call new_meta_request(self%mpi, "mpi", table, meta_allowed, error) |
| 211 |
if (allocated(error)) return |
| 212 |
|
| 213 |
call new_meta_request(self%hdf5, "hdf5", table, meta_allowed, error) |
| 214 |
if (allocated(error)) return |
| 215 |
|
| 216 |
call new_meta_request(self%netcdf, "netcdf", table, meta_allowed, error) |
| 217 |
if (allocated(error)) return |
| 218 |
|
| 219 |
call new_meta_request(self%blas, "blas", table, meta_allowed, error) |
| 220 |
if (allocated(error)) return |
| 221 |
|
| 222 |
end subroutine new_meta_config |
| 223 |
|
| 224 |
!> Check local schema for allowed entries |
| 225 |
logical function is_meta_package(key) |
| 226 |
character(*), intent(in) :: key |
| 227 |
select case (key) |
| 228 |
case ("openmp","stdlib","mpi","minpack","hdf5","netcdf","blas") |
| 229 |
is_meta_package = .true. |
| 230 |
case default |
| 231 |
is_meta_package = .false. |
| 232 |
end select |
| 233 |
end function is_meta_package |
| 234 |
|
| 235 |
!> Return a list of metapackages requested for the current build |
| 236 |
function get_requests(meta) result(requests) |
| 237 |
class(metapackage_config_t), intent(in) :: meta |
| 238 |
type(metapackage_request_t), allocatable :: requests(:) |
| 239 |
integer :: nreq |
| 240 |
|
| 241 |
nreq = count([ meta%mpi%on, & |
| 242 |
meta%openmp%on, & |
| 243 |
meta%stdlib%on, & |
| 244 |
meta%minpack%on, & |
| 245 |
meta%hdf5%on, & |
| 246 |
meta%netcdf%on, & |
| 247 |
meta%blas%on ]) |
| 248 |
|
| 249 |
allocate(requests(nreq)); if (nreq <= 0) return |
| 250 |
|
| 251 |
nreq = 0 |
| 252 |
call add_if_active(meta%mpi ,requests,nreq) |
| 253 |
call add_if_active(meta%openmp ,requests,nreq) |
| 254 |
call add_if_active(meta%stdlib ,requests,nreq) |
| 255 |
call add_if_active(meta%minpack,requests,nreq) |
| 256 |
call add_if_active(meta%hdf5 ,requests,nreq) |
| 257 |
call add_if_active(meta%netcdf ,requests,nreq) |
| 258 |
call add_if_active(meta%blas ,requests,nreq) |
| 259 |
|
| 260 |
contains |
| 261 |
|
| 262 |
subroutine add_if_active(req,list,count) |
| 263 |
type(metapackage_request_t), intent(in) :: req |
| 264 |
type(metapackage_request_t), intent(inout) :: list(:) |
| 265 |
integer, intent(inout) :: count |
| 266 |
if (.not.req%on) return |
| 267 |
count = count+1 |
| 268 |
list(count) = req |
| 269 |
end subroutine add_if_active |
| 270 |
|
| 271 |
end function get_requests |
| 272 |
|
| 273 |
!> Merge another metapackage configuration into this one |
| 274 |
!> This is used to propagate metapackage requests from dependencies to the main package |
| 275 |
subroutine meta_config_merge(self, other) |
| 276 |
class(metapackage_config_t), intent(inout) :: self |
| 277 |
type(metapackage_config_t), intent(in) :: other |
| 278 |
|
| 279 |
! Merge each metapackage request: if 'other' has it on, enable it in self |
| 280 |
call merge_request(self%openmp, other%openmp) |
| 281 |
call merge_request(self%stdlib, other%stdlib) |
| 282 |
call merge_request(self%minpack, other%minpack) |
| 283 |
call merge_request(self%mpi, other%mpi) |
| 284 |
call merge_request(self%hdf5, other%hdf5) |
| 285 |
call merge_request(self%netcdf, other%netcdf) |
| 286 |
call merge_request(self%blas, other%blas) |
| 287 |
|
| 288 |
contains |
| 289 |
|
| 290 |
subroutine merge_request(self_req, other_req) |
| 291 |
type(metapackage_request_t), intent(inout) :: self_req |
| 292 |
type(metapackage_request_t), intent(in) :: other_req |
| 293 |
|
| 294 |
! If other request is on and self is off, copy the request |
| 295 |
if (other_req%on .and. .not. self_req%on) then |
| 296 |
self_req%on = .true. |
| 297 |
if (allocated(other_req%version)) self_req%version = other_req%version |
| 298 |
end if |
| 299 |
end subroutine merge_request |
| 300 |
|
| 301 |
end subroutine meta_config_merge |
| 302 |
|
| 303 |
logical function meta_request_same(this, that) |
| 304 |
class(metapackage_request_t), intent(in) :: this |
| 305 |
class(serializable_t), intent(in) :: that |
| 306 |
|
| 307 |
meta_request_same = .false. |
| 308 |
select type (other => that) |
| 309 |
type is (metapackage_request_t) |
| 310 |
if (this%on .neqv. other%on) return |
| 311 |
if (allocated(this%name) .neqv. allocated(other%name)) return |
| 312 |
if (allocated(this%version).neqv. allocated(other%version))return |
| 313 |
if (allocated(this%name)) then; if (this%name /= other%name) return; end if |
| 314 |
if (allocated(this%version)) then; if (this%version/= other%version)return; end if |
| 315 |
class default |
| 316 |
return |
| 317 |
end select |
| 318 |
meta_request_same = .true. |
| 319 |
end function meta_request_same |
| 320 |
|
| 321 |
subroutine meta_request_dump(self, table, error) |
| 322 |
class(metapackage_request_t), intent(inout) :: self |
| 323 |
type(toml_table), intent(inout) :: table |
| 324 |
type(error_t), allocatable, intent(out) :: error |
| 325 |
|
| 326 |
call set_value (table, "on", self%on, error, 'metapackage_request_t') |
| 327 |
if (allocated(error)) return |
| 328 |
|
| 329 |
call set_string(table, "name", self%name, error) |
| 330 |
if (allocated(error)) return |
| 331 |
|
| 332 |
call set_string(table, "version", self%version,error) |
| 333 |
if (allocated(error)) return |
| 334 |
end subroutine meta_request_dump |
| 335 |
|
| 336 |
subroutine meta_request_load(self, table, error) |
| 337 |
class(metapackage_request_t), intent(inout) :: self |
| 338 |
type(toml_table), intent(inout) :: table |
| 339 |
type(error_t), allocatable, intent(out) :: error |
| 340 |
|
| 341 |
call get_value(table, "on", self%on) |
| 342 |
call get_value(table, "name", self%name) |
| 343 |
call get_value(table, "version", self%version) |
| 344 |
|
| 345 |
end subroutine meta_request_load |
| 346 |
|
| 347 |
logical function meta_config_same(this, that) |
| 348 |
class(metapackage_config_t), intent(in) :: this |
| 349 |
class(serializable_t), intent(in) :: that |
| 350 |
|
| 351 |
meta_config_same = .false. |
| 352 |
select type (other => that) |
| 353 |
type is (metapackage_config_t) |
| 354 |
|
| 355 |
if (.not. this%mpi == other%mpi) return |
| 356 |
if (.not. this%openmp == other%openmp) return |
| 357 |
if (.not. this%stdlib == other%stdlib) return |
| 358 |
if (.not. this%minpack == other%minpack)return |
| 359 |
if (.not. this%hdf5 == other%hdf5) return |
| 360 |
if (.not. this%netcdf == other%netcdf) return |
| 361 |
if (.not. this%blas == other%blas) return |
| 362 |
|
| 363 |
meta_config_same = .true. |
| 364 |
|
| 365 |
class default |
| 366 |
return |
| 367 |
end select |
| 368 |
|
| 369 |
end function meta_config_same |
| 370 |
|
| 371 |
subroutine meta_config_dump(self, table, error) |
| 372 |
class(metapackage_config_t), intent(inout) :: self |
| 373 |
type(toml_table), intent(inout) :: table |
| 374 |
type(error_t), allocatable, intent(out) :: error |
| 375 |
|
| 376 |
type(toml_table), pointer :: ptr |
| 377 |
|
| 378 |
! openmp |
| 379 |
call add_table(table, "openmp", ptr); if (.not.associated(ptr)) then |
| 380 |
call fatal_error(error, "metapackage_config_t: cannot create 'openmp' table"); return |
| 381 |
end if |
| 382 |
call self%openmp%dump_to_toml(ptr, error); if (allocated(error)) return |
| 383 |
|
| 384 |
! stdlib |
| 385 |
call add_table(table, "stdlib", ptr); if (.not.associated(ptr)) then |
| 386 |
call fatal_error(error, "metapackage_config_t: cannot create 'stdlib' table"); return |
| 387 |
end if |
| 388 |
call self%stdlib%dump_to_toml(ptr, error); if (allocated(error)) return |
| 389 |
|
| 390 |
! minpack |
| 391 |
call add_table(table, "minpack", ptr); if (.not.associated(ptr)) then |
| 392 |
call fatal_error(error, "metapackage_config_t: cannot create 'minpack' table"); return |
| 393 |
end if |
| 394 |
call self%minpack%dump_to_toml(ptr, error); if (allocated(error)) return |
| 395 |
|
| 396 |
! mpi |
| 397 |
call add_table(table, "mpi", ptr); if (.not.associated(ptr)) then |
| 398 |
call fatal_error(error, "metapackage_config_t: cannot create 'mpi' table"); return |
| 399 |
end if |
| 400 |
call self%mpi%dump_to_toml(ptr, error); if (allocated(error)) return |
| 401 |
|
| 402 |
! hdf5 |
| 403 |
call add_table(table, "hdf5", ptr); if (.not.associated(ptr)) then |
| 404 |
call fatal_error(error, "metapackage_config_t: cannot create 'hdf5' table"); return |
| 405 |
end if |
| 406 |
call self%hdf5%dump_to_toml(ptr, error); if (allocated(error)) return |
| 407 |
|
| 408 |
! netcdf |
| 409 |
call add_table(table, "netcdf", ptr); if (.not.associated(ptr)) then |
| 410 |
call fatal_error(error, "metapackage_config_t: cannot create 'netcdf' table"); return |
| 411 |
end if |
| 412 |
call self%netcdf%dump_to_toml(ptr, error); if (allocated(error)) return |
| 413 |
|
| 414 |
! blas |
| 415 |
call add_table(table, "blas", ptr); if (.not.associated(ptr)) then |
| 416 |
call fatal_error(error, "metapackage_config_t: cannot create 'blas' table"); return |
| 417 |
end if |
| 418 |
call self%blas%dump_to_toml(ptr, error); if (allocated(error)) return |
| 419 |
end subroutine meta_config_dump |
| 420 |
|
| 421 |
! Ensure the names of all packages are always defined |
| 422 |
subroutine meta_config_final(self) |
| 423 |
type(metapackage_config_t), intent(inout) :: self |
| 424 |
call meta_config_reset(self) |
| 425 |
end subroutine meta_config_final |
| 426 |
|
| 427 |
! Ensure the names of all packages are always defined |
| 428 |
subroutine meta_config_reset(self) |
| 429 |
class(metapackage_config_t), intent(inout) :: self |
| 430 |
|
| 431 |
call request_destroy(self%openmp); self%openmp%name = "openmp" |
| 432 |
call request_destroy(self%stdlib); self%stdlib%name = "stdlib" |
| 433 |
call request_destroy(self%minpack);self%minpack%name= "minpack" |
| 434 |
call request_destroy(self%mpi); self%mpi%name = "mpi" |
| 435 |
call request_destroy(self%hdf5); self%hdf5%name = "hdf5" |
| 436 |
call request_destroy(self%netcdf); self%netcdf%name = "netcdf" |
| 437 |
call request_destroy(self%blas); self%blas%name = "blas" |
| 438 |
|
| 439 |
end subroutine meta_config_reset |
| 440 |
|
| 441 |
subroutine meta_config_load(self, table, error) |
| 442 |
class(metapackage_config_t), intent(inout) :: self |
| 443 |
type(toml_table), intent(inout) :: table |
| 444 |
type(error_t), allocatable, intent(out) :: error |
| 445 |
|
| 446 |
type(toml_table), pointer :: ptr |
| 447 |
|
| 448 |
! openmp |
| 449 |
call get_value(table, "openmp", ptr) |
| 450 |
if (associated(ptr)) call self%openmp%load_from_toml(ptr, error); if (allocated(error)) return |
| 451 |
|
| 452 |
! stdlib |
| 453 |
call get_value(table, "stdlib", ptr) |
| 454 |
if (associated(ptr)) call self%stdlib%load_from_toml(ptr, error); if (allocated(error)) return |
| 455 |
|
| 456 |
! minpack |
| 457 |
call get_value(table, "minpack", ptr) |
| 458 |
if (associated(ptr)) call self%minpack%load_from_toml(ptr, error); if (allocated(error)) return |
| 459 |
|
| 460 |
! mpi |
| 461 |
call get_value(table, "mpi", ptr) |
| 462 |
if (associated(ptr)) call self%mpi%load_from_toml(ptr, error); if (allocated(error)) return |
| 463 |
|
| 464 |
! hdf5 |
| 465 |
call get_value(table, "hdf5", ptr) |
| 466 |
if (associated(ptr)) call self%hdf5%load_from_toml(ptr, error); if (allocated(error)) return |
| 467 |
|
| 468 |
! netcdf |
| 469 |
call get_value(table, "netcdf", ptr) |
| 470 |
if (associated(ptr)) call self%netcdf%load_from_toml(ptr, error); if (allocated(error)) return |
| 471 |
|
| 472 |
! blas |
| 473 |
call get_value(table, "blas", ptr) |
| 474 |
if (associated(ptr)) call self%blas%load_from_toml(ptr, error); if (allocated(error)) return |
| 475 |
end subroutine meta_config_load |
| 476 |
|
| 477 |
end module fpm_manifest_metapackages |