get_fpm_digest Function

public function get_fpm_digest(source_dir) result(digest_key)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: source_dir

Return Value character(len=32)


Source Code

    function get_fpm_digest(source_dir) result(digest_key)
        character(len=*), intent(in) :: source_dir
        character(len=32) :: digest_key
        type(srcfile_t), allocatable :: sources(:)
        type(error_t), allocatable :: error
        integer :: i
        character(len=16) :: hex_digest

        ! Use FPM API to discover sources and get their digests
        call add_sources_from_dir(sources, source_dir, FPM_SCOPE_APP, error=error)

        if (allocated(error)) then
            ! Fallback to simple naming if FPM fails
            digest_key = 'fallback_'//adjustl(extract_filename(source_dir))
            return
        end if

        if (.not. allocated(sources) .or. size(sources) == 0) then
            digest_key = 'empty_'//adjustl(extract_filename(source_dir))
            return
        end if

        ! Combine all source file digests into a single cache key
        ! Use the first source file's digest as the primary key
        write (hex_digest, '(z0)') sources(1)%digest
        digest_key = 'fpm_'//trim(hex_digest)

        ! For multiple sources, XOR their digests together
        do i = 2, size(sources)
            write (hex_digest, '(z0)') ieor(sources(1)%digest, sources(i)%digest)
            digest_key = 'fpm_'//trim(hex_digest)
        end do

    end function get_fpm_digest