Skip to content

Commit

Permalink
Merge pull request #1010 from henilp105/main
Browse files Browse the repository at this point in the history
fix: add fpm_model.json to the package tarball before uploading to the registry
  • Loading branch information
gnikit committed Mar 26, 2024
2 parents f65d65b + a9e4e38 commit 07fce84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/fpm/cmd/publish.f90
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ subroutine cmd_publish(settings)
end do

tmp_file = get_temp_filename()
call git_archive('.', tmp_file, 'HEAD', settings%verbose, error)
call git_archive('.', tmp_file, 'HEAD', additional_files=['fpm_model.json'], verbose=settings%verbose, error=error)
if (allocated(error)) call fpm_stop(1, '*cmd_publish* Archive error: '//error%message)
call model%dump('fpm_model.json', error, json=.true.)
if (allocated(error)) call fpm_stop(1, '*cmd_publish* Model dump error: '//error%message)
Expand Down
22 changes: 18 additions & 4 deletions src/fpm/git.f90
Original file line number Diff line number Diff line change
Expand Up @@ -407,20 +407,22 @@ pure function descriptor_name(descriptor) result(name)
end function descriptor_name

!> Archive a folder using `git archive`.
subroutine git_archive(source, destination, ref, verbose, error)
subroutine git_archive(source, destination, ref, additional_files, verbose, error)
!> Directory to archive.
character(*), intent(in) :: source
!> Destination of the archive.
character(*), intent(in) :: destination
!> (Symbolic) Reference to be archived.
character(*), intent(in) :: ref
!> (Optional) list of additional untracked files to be added to the archive.
character(*), optional, intent(in) :: additional_files(:)
!> Print additional information if true.
logical, intent(in) :: verbose
!> Error handling.
type(error_t), allocatable, intent(out) :: error

integer :: stat
character(len=:), allocatable :: cmd_output, archive_format
integer :: stat,i
character(len=:), allocatable :: cmd_output, archive_format, add_files

call execute_and_read_output('git archive -l', cmd_output, error, verbose)
if (allocated(error)) return
Expand All @@ -431,7 +433,19 @@ subroutine git_archive(source, destination, ref, verbose, error)
call fatal_error(error, "Cannot find a suitable archive format for 'git archive'."); return
end if

call run('git archive '//ref//' --format='//archive_format//' -o '//destination, echo=verbose, exitstat=stat)
allocate(character(len=0) :: add_files)
if (present(additional_files)) then
do i=1,size(additional_files)
add_files = trim(add_files)//' --add-file='//adjustl(additional_files(i))
end do
endif

call run('git archive '//ref//' &
--format='//archive_format// &
add_files//' \
-o '//destination, \
echo=verbose, \
exitstat=stat)
if (stat /= 0) then
call fatal_error(error, "Error packing '"//source//"'."); return
end if
Expand Down

0 comments on commit 07fce84

Please sign in to comment.