Skip to content

Commit d504a40

Browse files
committed
ensure no targets skipped mocking compile_commands.json
1 parent bdf9568 commit d504a40

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/fpm_backend.F90

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ subroutine build_package(targets,model,verbose,dry_run)
9191
! Perform depth-first topological sort of targets
9292
do i=1,size(targets)
9393

94-
call sort_target(targets(i)%ptr)
94+
call sort_target(targets(i)%ptr, dry_run)
9595

9696
end do
9797

@@ -180,15 +180,19 @@ end subroutine build_package
180180
!> If `target` is marked as sorted, `target%schedule` should be an
181181
!> integer greater than zero indicating the region for scheduling
182182
!>
183-
recursive subroutine sort_target(target)
183+
recursive subroutine sort_target(target, mock)
184184
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
185187

186188
integer :: i, fh, stat
189+
logical :: dry_run
190+
191+
dry_run = .false.
192+
if (present(mock)) dry_run = mock
187193

188194
! 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
192196

193197
! Check for a circular dependency
194198
! (If target has been touched but not processed)
@@ -201,20 +205,24 @@ recursive subroutine sort_target(target)
201205
! Load cached source file digest if present
202206
if (.not.allocated(target%digest_cached) .and. &
203207
exists(target%output_file) .and. &
204-
exists(target%output_file//'.digest')) then
208+
exists(target%output_file//'.digest') .and. &
209+
(.not.dry_run)) then
205210

206211
allocate(target%digest_cached)
207212
open(newunit=fh,file=target%output_file//'.digest',status='old')
208213
read(fh,*,iostat=stat) target%digest_cached
209214
close(fh)
210215

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)
214218

215219
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
218226

219227
! Skip if target is source-based and source file is unmodified
220228
if (allocated(target%digest_cached)) then
@@ -233,7 +241,7 @@ recursive subroutine sort_target(target)
233241
do i=1,size(target%dependencies)
234242

235243
! Sort dependency
236-
call sort_target(target%dependencies(i)%ptr)
244+
call sort_target(target%dependencies(i)%ptr, dry_run)
237245

238246
if (.not.target%dependencies(i)%ptr%skip) then
239247

@@ -329,23 +337,23 @@ subroutine build_target(model,target,verbose,dry_run,table,stat)
329337

330338
case (FPM_TARGET_OBJECT)
331339
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)
333341

334342
case (FPM_TARGET_C_OBJECT)
335343
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)
337345

338346
case (FPM_TARGET_CPP_OBJECT)
339347
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)
341349

342350
case (FPM_TARGET_EXECUTABLE)
343351
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)
345353

346354
case (FPM_TARGET_ARCHIVE)
347355
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)
349357

350358
end select
351359

0 commit comments

Comments
 (0)