@@ -91,7 +91,7 @@ subroutine build_package(targets,model,verbose,dry_run)
91
91
! Perform depth-first topological sort of targets
92
92
do i= 1 ,size (targets)
93
93
94
- call sort_target(targets(i)% ptr)
94
+ call sort_target(targets(i)% ptr, dry_run )
95
95
96
96
end do
97
97
@@ -180,15 +180,19 @@ end subroutine build_package
180
180
! > If `target` is marked as sorted, `target%schedule` should be an
181
181
! > integer greater than zero indicating the region for scheduling
182
182
! >
183
- recursive subroutine sort_target (target )
183
+ recursive subroutine sort_target (target , mock )
184
184
type (build_target_t), intent (inout ), target :: target
185
+ ! > Optionally sort ALL targets if this is a dry run
186
+ logical , optional , intent (in ) :: mock
185
187
186
188
integer :: i, fh, stat
189
+ logical :: dry_run
190
+
191
+ dry_run = .false.
192
+ if (present (mock)) dry_run = mock
187
193
188
194
! Check if target has already been processed (as a dependency)
189
- if (target % sorted .or. target % skip) then
190
- return
191
- end if
195
+ if (target % sorted .or. target % skip) return
192
196
193
197
! Check for a circular dependency
194
198
! (If target has been touched but not processed)
@@ -201,20 +205,24 @@ recursive subroutine sort_target(target)
201
205
! Load cached source file digest if present
202
206
if (.not. allocated (target % digest_cached) .and. &
203
207
exists(target % output_file) .and. &
204
- exists(target % output_file// ' .digest' )) then
208
+ exists(target % output_file// ' .digest' ) .and. &
209
+ (.not. dry_run)) then
205
210
206
211
allocate (target % digest_cached)
207
212
open (newunit= fh,file= target % output_file// ' .digest' ,status= ' old' )
208
213
read (fh,* ,iostat= stat) target % digest_cached
209
214
close (fh)
210
215
211
- if (stat /= 0 ) then ! Cached digest is not recognized
212
- deallocate (target % digest_cached)
213
- end if
216
+ ! Cached digest is not recognized
217
+ if (stat /= 0 ) deallocate (target % digest_cached)
214
218
215
219
end if
216
-
217
- if (allocated (target % source)) then
220
+
221
+ if (dry_run) then
222
+
223
+ target % skip = .false.
224
+
225
+ elseif (allocated (target % source)) then
218
226
219
227
! Skip if target is source-based and source file is unmodified
220
228
if (allocated (target % digest_cached)) then
@@ -233,7 +241,7 @@ recursive subroutine sort_target(target)
233
241
do i= 1 ,size (target % dependencies)
234
242
235
243
! Sort dependency
236
- call sort_target(target % dependencies(i)% ptr)
244
+ call sort_target(target % dependencies(i)% ptr, dry_run )
237
245
238
246
if (.not. target % dependencies(i)% ptr% skip) then
239
247
@@ -329,23 +337,23 @@ subroutine build_target(model,target,verbose,dry_run,table,stat)
329
337
330
338
case (FPM_TARGET_OBJECT)
331
339
call model% compiler% compile_fortran(target % source% file_name, target % output_file, &
332
- & target % compile_flags, target % output_log_file, stat, table)
340
+ & target % compile_flags, target % output_log_file, stat, table, dry_run )
333
341
334
342
case (FPM_TARGET_C_OBJECT)
335
343
call model% compiler% compile_c(target % source% file_name, target % output_file, &
336
- & target % compile_flags, target % output_log_file, stat, table)
344
+ & target % compile_flags, target % output_log_file, stat, table, dry_run )
337
345
338
346
case (FPM_TARGET_CPP_OBJECT)
339
347
call model% compiler% compile_cpp(target % source% file_name, target % output_file, &
340
- & target % compile_flags, target % output_log_file, stat, table)
348
+ & target % compile_flags, target % output_log_file, stat, table, dry_run )
341
349
342
350
case (FPM_TARGET_EXECUTABLE)
343
351
call model% compiler% link(target % output_file, &
344
- & target % compile_flags// " " // target % link_flags, target % output_log_file, stat)
352
+ & target % compile_flags// " " // target % link_flags, target % output_log_file, stat, dry_run )
345
353
346
354
case (FPM_TARGET_ARCHIVE)
347
355
call model% archiver% make_archive(target % output_file, target % link_objects, &
348
- & target % output_log_file, stat)
356
+ & target % output_log_file, stat, dry_run )
349
357
350
358
end select
351
359
0 commit comments