Construct a new package configuration from a TOML data structure
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(package_config_t), | intent(out) | :: | self |
Instance of the package configuration |
||
type(toml_table), | intent(inout) | :: | table |
Instance of the TOML data structure |
||
character(len=*), | intent(in), | optional | :: | root |
Root directory of the manifest |
|
type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
subroutine new_package(self, table, root, error) !> Instance of the package configuration type(package_config_t), intent(out) :: self !> Instance of the TOML data structure type(toml_table), intent(inout) :: table !> Root directory of the manifest character(len=*), intent(in), optional :: root !> Error handling type(error_t), allocatable, intent(out) :: error ! Backspace (8), tabulator (9), newline (10), formfeed (12) and carriage ! return (13) are invalid in package names character(len=*), parameter :: invalid_chars = & achar(8) // achar(9) // achar(10) // achar(12) // achar(13) type(toml_table), pointer :: child, node type(toml_array), pointer :: children character(len=:), allocatable :: version, version_file integer :: ii, nn, stat, io call check(table, error) if (allocated(error)) return ! Get package name and perform validation call get_value(table, "name", self%name) if (.not.allocated(self%name)) then call syntax_error(error, "Could not retrieve package name") return end if if (bad_name_error(error,'package',self%name)) return if (len(self%name) <= 0) then call syntax_error(error, "Package name must be a non-empty string") return end if ii = scan(self%name, invalid_chars) if (ii > 0) then call syntax_error(error, "Package name contains invalid characters") return end if ! Get package-specific metadata call get_value(table, "license", self%license) call get_value(table, "author", self%author) call get_value(table, "maintainer", self%maintainer) call get_value(table, "copyright", self%copyright) ! Initialize shared feature components call init_feature_components(self%feature_config_t, table, root=root, error=error) if (allocated(error)) return call get_value(table, "version", version, "0") call new_version(self%version, version, error) if (allocated(error) .and. present(root)) then version_file = join_path(root, version) if (exists(version_file)) then deallocate(error) open(file=version_file, newunit=io, iostat=stat) if (stat == 0) then call getline(io, version, iostat=stat) end if if (stat == 0) then close(io, iostat=stat) end if if (stat == 0) then call new_version(self%version, version, error) else call fatal_error(error, "Reading version number from file '" & & //version_file//"' failed") end if end if end if if (allocated(error)) return call get_value(table, "profiles", child, requested=.false.) if (associated(child)) then call new_profiles(self%profiles, child, error) if (allocated(error)) return else ! Leave profiles unallocated for now allocate(self%profiles(0)) end if call get_value(table, "features", child, requested=.false.) if (associated(child)) then ! Parse features from manifest using new_collections call new_collections(self%features, child, error) if (allocated(error)) return else ! Initialize with default feature collections (debug and release) call get_default_features(self%features, error) if (allocated(error)) return end if end subroutine new_package