@@ -38,6 +38,7 @@ module fpm_manifest_package
3838 use fpm_manifest_library, only : library_config_t, new_library
3939 use fpm_manifest_install, only: install_config_t, new_install_config
4040 use fpm_manifest_test, only : test_config_t, new_test
41+ use fpm_filesystem, only : exists, getline, join_path
4142 use fpm_error, only : error_t, fatal_error, syntax_error
4243 use fpm_toml, only : toml_table, toml_array, toml_key, toml_stat, get_value, &
4344 & len
@@ -99,14 +100,17 @@ module fpm_manifest_package
99100
100101
101102 ! > Construct a new package configuration from a TOML data structure
102- subroutine new_package (self , table , error )
103+ subroutine new_package (self , table , root , error )
103104
104105 ! > Instance of the package configuration
105106 type (package_config_t), intent (out ) :: self
106107
107108 ! > Instance of the TOML data structure
108109 type (toml_table), intent (inout ) :: table
109110
111+ ! > Root directory of the manifest
112+ character (len=* ), intent (in ), optional :: root
113+
110114 ! > Error handling
111115 type (error_t), allocatable , intent (out ) :: error
112116
@@ -116,8 +120,8 @@ subroutine new_package(self, table, error)
116120 achar (8 ) // achar (9 ) // achar (10 ) // achar (12 ) // achar (13 )
117121 type (toml_table), pointer :: child, node
118122 type (toml_array), pointer :: children
119- character (len= :), allocatable :: version
120- integer :: ii, nn, stat
123+ character (len= :), allocatable :: version, version_file
124+ integer :: ii, nn, stat, io
121125
122126 call check(table, error)
123127 if (allocated (error)) return
@@ -157,6 +161,25 @@ subroutine new_package(self, table, error)
157161
158162 call get_value(table, " version" , version, " 0" )
159163 call new_version(self% version, version, error)
164+ if (allocated (error) .and. present (root)) then
165+ version_file = join_path(root, version)
166+ if (exists(version_file)) then
167+ deallocate (error)
168+ open (file= version_file, newunit= io, iostat= stat)
169+ if (stat == 0 ) then
170+ call getline(io, version, iostat= stat)
171+ end if
172+ if (stat == 0 ) then
173+ close (io, iostat= stat)
174+ end if
175+ if (stat == 0 ) then
176+ call new_version(self% version, version, error)
177+ else
178+ call fatal_error(error, " Reading version number from file '" &
179+ & // version_file// " ' failed" )
180+ end if
181+ end if
182+ end if
160183 if (allocated (error)) return
161184
162185 call get_value(table, " dependencies" , child, requested= .false. )
0 commit comments