Skip to content

Commit

Permalink
do not allow lists in library.source-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
perazz committed Sep 23, 2024
1 parent da6d1bf commit 54698d9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/fpm/manifest/library.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module fpm_manifest_library
use fpm_error, only : error_t, syntax_error
use fpm_strings, only: string_t, string_cat, operator(==)
use fpm_toml, only : toml_table, toml_key, toml_stat, get_value, get_list, serializable_t, set_value, &
set_list, set_string, get_value, get_list
set_list, set_string, get_value, has_list
implicit none
private

Expand Down Expand Up @@ -63,6 +63,11 @@ subroutine new_library(self, table, error)

call check(table, error)
if (allocated(error)) return

if (has_list(table, "source-dir")) then
call syntax_error(error, "Manifest key [library.source-dir] does not allow list input")
return
end if

call get_value(table, "source-dir", self%source_dir, "src")
call get_value(table, "build-script", self%build_script)
Expand Down
25 changes: 24 additions & 1 deletion src/fpm/toml.f90
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module fpm_toml
public :: read_package_file, toml_table, toml_array, toml_key, toml_stat, &
get_value, set_value, get_list, new_table, add_table, add_array, len, &
toml_error, toml_serialize, toml_load, check_keys, set_list, set_string, &
name_is_json
name_is_json, has_list

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

end subroutine read_package_file

!> Check if an instance of the TOML data structure contains a list
logical function has_list(table, key)

!> Instance of the TOML data structure
type(toml_table), intent(inout) :: table

!> Key to read from
character(len=*), intent(in) :: key

type(toml_array), pointer :: children

has_list = .false.

if (.not.table%has_key(key)) return

call get_value(table, key, children, requested=.false.)

! There is an allocated list
has_list = associated(children)

end function has_list


subroutine get_list(table, key, list, error)

Expand Down

0 comments on commit 54698d9

Please sign in to comment.