Skip to content

Commit d9d1524

Browse files
committed
Refactoring of manifest types
- move defaults from fpm to fpm_manifest - rename all manifest types from *_t to *_config_t - instance names correspond to table names in manifest
1 parent c68cf2f commit d9d1524

File tree

10 files changed

+174
-162
lines changed

10 files changed

+174
-162
lines changed

fpm/src/fpm.f90

Lines changed: 19 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ module fpm
1212

1313
use fpm_sources, only: add_executable_sources, add_sources_from_dir
1414
use fpm_targets, only: targets_from_sources, resolve_module_dependencies
15-
use fpm_manifest, only : get_package_data, default_executable, &
16-
default_library, package_t, default_test
15+
use fpm_manifest, only : get_package_data, package_config_t
1716
use fpm_error, only : error_t, fatal_error
18-
use fpm_manifest_test, only : test_t
17+
use fpm_manifest_test, only : test_config_t
1918
use,intrinsic :: iso_fortran_env, only : stdin=>input_unit, &
2019
& stdout=>output_unit, &
2120
& stderr=>error_unit
22-
use fpm_manifest_dependency, only: dependency_t
21+
use fpm_manifest_dependency, only: dependency_config_t
2322
implicit none
2423
private
2524
public :: cmd_build, cmd_install, cmd_run
@@ -34,7 +33,7 @@ recursive subroutine add_libsources_from_package(sources,link_libraries,package_
3433
type(srcfile_t), allocatable, intent(inout), target :: sources(:)
3534
type(string_t), allocatable, intent(inout) :: link_libraries(:)
3635
type(string_t), allocatable, intent(inout) :: package_list(:)
37-
type(package_t), intent(in) :: package
36+
type(package_config_t), intent(in) :: package
3837
character(*), intent(in) :: package_root
3938
logical, intent(in) :: dev_depends
4039
type(error_t), allocatable, intent(out) :: error
@@ -76,11 +75,11 @@ recursive subroutine add_libsources_from_package(sources,link_libraries,package_
7675
contains
7776

7877
subroutine add_dependencies(dependency_list)
79-
type(dependency_t), intent(in) :: dependency_list(:)
78+
type(dependency_config_t), intent(in) :: dependency_list(:)
8079

8180
integer :: i
8281
type(string_t) :: dep_name
83-
type(package_t) :: dependency
82+
type(package_config_t) :: dependency
8483

8584
character(:), allocatable :: dependency_path
8685

@@ -135,8 +134,8 @@ subroutine add_dependencies(dependency_list)
135134

136135
dep_name%s = dependency_list(i)%name
137136
package_list = [package_list, dep_name]
138-
if (allocated(dependency%build_config%link)) then
139-
link_libraries = [link_libraries, dependency%build_config%link]
137+
if (allocated(dependency%build%link)) then
138+
link_libraries = [link_libraries, dependency%build%link]
140139
end if
141140

142141
end do
@@ -151,15 +150,15 @@ subroutine build_model(model, settings, package, error)
151150
!
152151
type(fpm_model_t), intent(out) :: model
153152
type(fpm_build_settings), intent(in) :: settings
154-
type(package_t), intent(in) :: package
153+
type(package_config_t), intent(in) :: package
155154
type(error_t), allocatable, intent(out) :: error
156155

157156
integer :: i
158157
type(string_t), allocatable :: package_list(:)
159158

160159
model%package_name = package%name
161-
if (allocated(package%build_config%link)) then
162-
model%link_libraries = package%build_config%link
160+
if (allocated(package%build%link)) then
161+
model%link_libraries = package%build%link
163162
else
164163
allocate(model%link_libraries(0))
165164
end if
@@ -189,7 +188,7 @@ subroutine build_model(model, settings, package, error)
189188
model%link_flags = ''
190189

191190
! Add sources from executable directories
192-
if (is_dir('app') .and. package%build_config%auto_executables) then
191+
if (is_dir('app') .and. package%build%auto_executables) then
193192
call add_sources_from_dir(model%sources,'app', FPM_SCOPE_APP, &
194193
with_executables=.true., error=error)
195194

@@ -198,7 +197,7 @@ subroutine build_model(model, settings, package, error)
198197
end if
199198

200199
end if
201-
if (is_dir('test') .and. package%build_config%auto_tests) then
200+
if (is_dir('test') .and. package%build%auto_tests) then
202201
call add_sources_from_dir(model%sources,'test', FPM_SCOPE_TEST, &
203202
with_executables=.true., error=error)
204203

@@ -209,7 +208,7 @@ subroutine build_model(model, settings, package, error)
209208
end if
210209
if (allocated(package%executable)) then
211210
call add_executable_sources(model%sources, package%executable, FPM_SCOPE_APP, &
212-
auto_discover=package%build_config%auto_executables, &
211+
auto_discover=package%build%auto_executables, &
213212
error=error)
214213

215214
if (allocated(error)) then
@@ -219,7 +218,7 @@ subroutine build_model(model, settings, package, error)
219218
end if
220219
if (allocated(package%test)) then
221220
call add_executable_sources(model%sources, package%test, FPM_SCOPE_TEST, &
222-
auto_discover=package%build_config%auto_tests, &
221+
auto_discover=package%build%auto_tests, &
223222
error=error)
224223

225224
if (allocated(error)) then
@@ -245,53 +244,21 @@ subroutine build_model(model, settings, package, error)
245244

246245
end subroutine build_model
247246

248-
!> Apply package defaults
249-
subroutine package_defaults(package)
250-
type(package_t), intent(inout) :: package
251-
252-
! Populate library in case we find the default src directory
253-
if (.not.allocated(package%library) .and. exists("src")) then
254-
allocate(package%library)
255-
call default_library(package%library)
256-
end if
257-
258-
! Populate executable in case we find the default app
259-
if (.not.allocated(package%executable) .and. &
260-
exists(join_path('app',"main.f90"))) then
261-
allocate(package%executable(1))
262-
call default_executable(package%executable(1), package%name)
263-
end if
264-
265-
! Populate test in case we find the default test directory
266-
if (.not.allocated(package%test) .and. &
267-
exists(join_path("test","main.f90"))) then
268-
allocate(package%test(1))
269-
call default_test(package%test(1), package%name)
270-
endif
271-
272-
if (.not.(allocated(package%library) .or. allocated(package%executable))) then
273-
print '(a)', "Neither library nor executable found, there is nothing to do"
274-
error stop 1
275-
end if
276-
277-
end subroutine
278247

279248
subroutine cmd_build(settings)
280249
type(fpm_build_settings), intent(in) :: settings
281-
type(package_t) :: package
250+
type(package_config_t) :: package
282251
type(fpm_model_t) :: model
283252
type(error_t), allocatable :: error
284253

285254
integer :: i
286255

287-
call get_package_data(package, "fpm.toml", error)
256+
call get_package_data(package, "fpm.toml", error, apply_defaults=.true.)
288257
if (allocated(error)) then
289258
print '(a)', error%message
290259
error stop 1
291260
end if
292261

293-
call package_defaults(package)
294-
295262
call build_model(model, settings, package, error)
296263
if (allocated(error)) then
297264
print '(a)', error%message
@@ -322,22 +289,19 @@ subroutine cmd_run(settings,test)
322289
integer :: i, j, col_width, nCol
323290
logical :: found(size(settings%name))
324291
type(error_t), allocatable :: error
325-
type(package_t) :: package
292+
type(package_config_t) :: package
326293
type(fpm_model_t) :: model
327294
type(string_t) :: exe_cmd
328295
type(string_t), allocatable :: executables(:)
329296
type(build_target_t), pointer :: exe_target
330297
type(srcfile_t), pointer :: exe_source
331298

332-
call get_package_data(package, "fpm.toml", error)
299+
call get_package_data(package, "fpm.toml", error, apply_defaults=.true.)
333300
if (allocated(error)) then
334301
print '(a)', error%message
335302
error stop 1
336303
end if
337304

338-
339-
call package_defaults(package)
340-
341305
call build_model(model, settings%fpm_build_settings, package, error)
342306
if (allocated(error)) then
343307
print '(a)', error%message

fpm/src/fpm/manifest.f90

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
!> Additionally, the required data types for users of this module are reexported
88
!> to hide the actual implementation details.
99
module fpm_manifest
10-
use fpm_manifest_build_config, only: build_config_t
11-
use fpm_manifest_executable, only : executable_t
12-
use fpm_manifest_library, only : library_t
13-
use fpm_manifest_package, only : package_t, new_package
10+
use fpm_manifest_build, only: build_config_t
11+
use fpm_manifest_executable, only : executable_config_t
12+
use fpm_manifest_library, only : library_config_t
13+
use fpm_manifest_package, only : package_config_t, new_package
1414
use fpm_error, only : error_t, fatal_error, file_not_found_error
1515
use fpm_toml, only : toml_table, read_package_file
16-
use fpm_manifest_test, only : test_t
16+
use fpm_manifest_test, only : test_config_t
17+
use fpm_filesystem, only: join_path, exists
1718
implicit none
1819
private
1920

2021
public :: get_package_data, default_executable, default_library, default_test
21-
public :: package_t
22+
public :: package_config_t
2223

2324

2425
contains
@@ -28,7 +29,7 @@ module fpm_manifest
2829
subroutine default_library(self)
2930

3031
!> Instance of the library meta data
31-
type(library_t), intent(out) :: self
32+
type(library_config_t), intent(out) :: self
3233

3334
self%source_dir = "src"
3435

@@ -39,7 +40,7 @@ end subroutine default_library
3940
subroutine default_executable(self, name)
4041

4142
!> Instance of the executable meta data
42-
type(executable_t), intent(out) :: self
43+
type(executable_config_t), intent(out) :: self
4344

4445
!> Name of the package
4546
character(len=*), intent(in) :: name
@@ -54,7 +55,7 @@ end subroutine default_executable
5455
subroutine default_test(self, name)
5556

5657
!> Instance of the executable meta data
57-
type(test_t), intent(out) :: self
58+
type(test_config_t), intent(out) :: self
5859

5960
!> Name of the package
6061
character(len=*), intent(in) :: name
@@ -67,17 +68,20 @@ end subroutine default_test
6768

6869

6970
!> Obtain package meta data from a configuation file
70-
subroutine get_package_data(package, file, error)
71+
subroutine get_package_data(package, file, error, apply_defaults)
7172

7273
!> Parsed package meta data
73-
type(package_t), intent(out) :: package
74+
type(package_config_t), intent(out) :: package
7475

7576
!> Name of the package configuration file
7677
character(len=*), intent(in) :: file
7778

7879
!> Error status of the operation
7980
type(error_t), allocatable, intent(out) :: error
8081

82+
!> Apply package defaults (uses file system operations)
83+
logical, intent(in), optional :: apply_defaults
84+
8185
type(toml_table), allocatable :: table
8286

8387
call read_package_file(table, file, error)
@@ -90,7 +94,51 @@ subroutine get_package_data(package, file, error)
9094

9195
call new_package(package, table, error)
9296

97+
if (present(apply_defaults)) then
98+
if (apply_defaults) then
99+
call package_defaults(package, error)
100+
if (allocated(error)) return
101+
end if
102+
end if
103+
93104
end subroutine get_package_data
94105

95106

107+
!> Apply package defaults
108+
subroutine package_defaults(package, error)
109+
110+
!> Parsed package meta data
111+
type(package_config_t), intent(inout) :: package
112+
113+
!> Error status of the operation
114+
type(error_t), allocatable, intent(out) :: error
115+
116+
! Populate library in case we find the default src directory
117+
if (.not.allocated(package%library) .and. exists("src")) then
118+
allocate(package%library)
119+
call default_library(package%library)
120+
end if
121+
122+
! Populate executable in case we find the default app
123+
if (.not.allocated(package%executable) .and. &
124+
exists(join_path('app',"main.f90"))) then
125+
allocate(package%executable(1))
126+
call default_executable(package%executable(1), package%name)
127+
end if
128+
129+
! Populate test in case we find the default test directory
130+
if (.not.allocated(package%test) .and. &
131+
exists(join_path("test","main.f90"))) then
132+
allocate(package%test(1))
133+
call default_test(package%test(1), package%name)
134+
endif
135+
136+
if (.not.(allocated(package%library) .or. allocated(package%executable))) then
137+
call fatal_error(error, "Neither library nor executable found, there is nothing to do")
138+
return
139+
end if
140+
141+
end subroutine package_defaults
142+
143+
96144
end module fpm_manifest

fpm/src/fpm/manifest/build_config.f90 renamed to fpm/src/fpm/manifest/build.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
!>auto-tests = bool
99
!>link = ["lib"]
1010
!>```
11-
module fpm_manifest_build_config
11+
module fpm_manifest_build
1212
use fpm_error, only : error_t, syntax_error, fatal_error
1313
use fpm_strings, only : string_t
1414
use fpm_toml, only : toml_table, toml_key, toml_stat, get_value
@@ -146,4 +146,4 @@ subroutine info(self, unit, verbosity)
146146

147147
end subroutine info
148148

149-
end module fpm_manifest_build_config
149+
end module fpm_manifest_build

fpm/src/fpm/manifest/dependency.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ module fpm_manifest_dependency
3030
implicit none
3131
private
3232

33-
public :: dependency_t, new_dependency, new_dependencies
33+
public :: dependency_config_t, new_dependency, new_dependencies
3434

3535

3636
!> Configuration meta data for a dependency
37-
type :: dependency_t
37+
type :: dependency_config_t
3838

3939
!> Name of the dependency
4040
character(len=:), allocatable :: name
@@ -50,7 +50,7 @@ module fpm_manifest_dependency
5050
!> Print information on this instance
5151
procedure :: info
5252

53-
end type dependency_t
53+
end type dependency_config_t
5454

5555

5656
contains
@@ -60,7 +60,7 @@ module fpm_manifest_dependency
6060
subroutine new_dependency(self, table, error)
6161

6262
!> Instance of the dependency configuration
63-
type(dependency_t), intent(out) :: self
63+
type(dependency_config_t), intent(out) :: self
6464

6565
!> Instance of the TOML data structure
6666
type(toml_table), intent(inout) :: table
@@ -176,7 +176,7 @@ end subroutine check
176176
subroutine new_dependencies(deps, table, error)
177177

178178
!> Instance of the dependency configuration
179-
type(dependency_t), allocatable, intent(out) :: deps(:)
179+
type(dependency_config_t), allocatable, intent(out) :: deps(:)
180180

181181
!> Instance of the TOML data structure
182182
type(toml_table), intent(inout) :: table
@@ -210,7 +210,7 @@ end subroutine new_dependencies
210210
subroutine info(self, unit, verbosity)
211211

212212
!> Instance of the dependency configuration
213-
class(dependency_t), intent(in) :: self
213+
class(dependency_config_t), intent(in) :: self
214214

215215
!> Unit for IO
216216
integer, intent(in) :: unit

0 commit comments

Comments
 (0)