subroutine gather_files_with_mask(targets, visited, target_mask, files, file_mask, build_dir, dep_dirs)
type(build_target_ptr), intent(in) :: targets(:)
logical, intent(in) :: visited(:)
integer(int64), allocatable, intent(in), optional :: target_mask(:)
type(string_t), allocatable, intent(out) :: files(:)
integer(int64), allocatable, intent(out) :: file_mask(:)
character(len=*), intent(in) :: build_dir
type(string_t), allocatable, intent(in), optional :: dep_dirs(:)
type(string_t), allocatable :: buf(:)
integer(int64), allocatable :: mbuf(:)
integer :: n, cap
integer :: i, j
integer(int64) :: m
n = 0
cap = 256
allocate(buf(cap), mbuf(cap))
do i = 1, size(targets)
if (.not. visited(i)) cycle
if (.not. allocated(targets(i)%ptr%source)) cycle
m = 0_int64
if (present(target_mask)) then
if (allocated(target_mask)) m = target_mask(i)
end if
if (present(dep_dirs)) then
call vec_push_unique(buf, mbuf, n, cap, targets(i)%ptr%source%file_name, build_dir, m, dep_dirs)
else
call vec_push_unique(buf, mbuf, n, cap, targets(i)%ptr%source%file_name, build_dir, m)
end if
if (allocated(targets(i)%ptr%source%include_dependencies)) then
do j = 1, size(targets(i)%ptr%source%include_dependencies)
if (present(dep_dirs)) then
call vec_push_unique(buf, mbuf, n, cap, targets(i)%ptr%source%include_dependencies(j)%s, build_dir, m, dep_dirs)
else
call vec_push_unique(buf, mbuf, n, cap, targets(i)%ptr%source%include_dependencies(j)%s, build_dir, m)
end if
end do
end if
end do
call finalize_vec(buf, mbuf, n, files, file_mask)
contains
subroutine finalize_vec(buf, mbuf, n, files, file_mask)
type(string_t), allocatable, intent(inout) :: buf(:)
integer(int64), allocatable, intent(inout) :: mbuf(:)
integer, intent(in) :: n
type(string_t), allocatable, intent(out) :: files(:)
integer(int64), allocatable, intent(out) :: file_mask(:)
integer :: k
if (n <= 0) then
allocate(files(0), file_mask(0))
deallocate(buf, mbuf)
return
end if
allocate(files(n), file_mask(n))
do k = 1, n
call move_alloc(buf(k)%s, files(k)%s)
file_mask(k) = mbuf(k)
end do
deallocate(buf, mbuf)
end subroutine finalize_vec
end subroutine gather_files_with_mask