get_content_hash Function

public function get_content_hash(source_files) result(hash_key)

Arguments

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

Generate content-based hash using FPM's fnv_1a algorithm

Return Value character(len=32)


Source Code

    function get_content_hash(source_files) result(hash_key)
        !> Generate content-based hash using FPM's fnv_1a algorithm
        character(len=*), intent(in) :: source_files(:)
        character(len=32) :: hash_key
        type(string_t), allocatable :: file_contents(:)
        character(len=16) :: hex_digest
        integer(kind=8) :: combined_digest
        integer :: i

        ! Read all source files and combine their content using FPM's read_lines
        combined_digest = 0_int64

        do i = 1, size(source_files)
            if (len_trim(source_files(i)) == 0) cycle

            ! Use FPM's read_lines function like fpm_source_parsing.f90 does
            file_contents = read_lines(trim(source_files(i)))

            ! Use FPM's fnv_1a hash function like fmp_source_parsing.f90 does
            if (size(file_contents) > 0) then
                combined_digest = ieor(combined_digest, fnv_1a(file_contents))
            end if
        end do

        ! Convert to hex string
        if (combined_digest /= 0) then
            write (hex_digest, '(z0)') combined_digest
            hash_key = 'fpm_'//trim(hex_digest)
        else
            hash_key = 'fallback_unknown'
        end if

    end function get_content_hash