Skip to content

Commit 54698d9

Browse files
committed
do not allow lists in library.source-dir
1 parent da6d1bf commit 54698d9

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/fpm/manifest/library.f90

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module fpm_manifest_library
1212
use fpm_error, only : error_t, syntax_error
1313
use fpm_strings, only: string_t, string_cat, operator(==)
1414
use fpm_toml, only : toml_table, toml_key, toml_stat, get_value, get_list, serializable_t, set_value, &
15-
set_list, set_string, get_value, get_list
15+
set_list, set_string, get_value, has_list
1616
implicit none
1717
private
1818

@@ -63,6 +63,11 @@ subroutine new_library(self, table, error)
6363

6464
call check(table, error)
6565
if (allocated(error)) return
66+
67+
if (has_list(table, "source-dir")) then
68+
call syntax_error(error, "Manifest key [library.source-dir] does not allow list input")
69+
return
70+
end if
6671

6772
call get_value(table, "source-dir", self%source_dir, "src")
6873
call get_value(table, "build-script", self%build_script)

src/fpm/toml.f90

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module fpm_toml
2828
public :: read_package_file, toml_table, toml_array, toml_key, toml_stat, &
2929
get_value, set_value, get_list, new_table, add_table, add_array, len, &
3030
toml_error, toml_serialize, toml_load, check_keys, set_list, set_string, &
31-
name_is_json
31+
name_is_json, has_list
3232

3333
!> An abstract interface for any fpm class that should be fully serializable to/from TOML/JSON
3434
type, abstract, public :: serializable_t
@@ -337,6 +337,29 @@ subroutine read_package_file(table, manifest, error)
337337
end if
338338

339339
end subroutine read_package_file
340+
341+
!> Check if an instance of the TOML data structure contains a list
342+
logical function has_list(table, key)
343+
344+
!> Instance of the TOML data structure
345+
type(toml_table), intent(inout) :: table
346+
347+
!> Key to read from
348+
character(len=*), intent(in) :: key
349+
350+
type(toml_array), pointer :: children
351+
352+
has_list = .false.
353+
354+
if (.not.table%has_key(key)) return
355+
356+
call get_value(table, key, children, requested=.false.)
357+
358+
! There is an allocated list
359+
has_list = associated(children)
360+
361+
end function has_list
362+
340363

341364
subroutine get_list(table, key, list, error)
342365

0 commit comments

Comments
 (0)