Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ test ! -x ./build/gfortran_*/app/unused
test ! -x ./build/gfortran_*/test/unused_test
popd

pushd version_file
"$fpm" build
"$fpm" run
popd

pushd with_c
"$fpm" build
"$fpm" run --target with_c
Expand Down
1 change: 1 addition & 0 deletions example_packages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ the features demonstrated in each package and which versions of fpm are supporte
| submodules | Lib-only; submodules (3 levels) | N | Y |
| link_external | Link external library | N | Y |
| link_executable | Link external library to a single executable | N | Y |
| version_file | Read version number from a file in the project root | N | Y |
| with_c | Compile with `c` source files | N | Y |
| with_makefile | External build command (makefile) | Y | N |
1 change: 1 addition & 0 deletions example_packages/version_file/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.42.1
13 changes: 13 additions & 0 deletions example_packages/version_file/app/main.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program stub
implicit none
logical :: exists
integer :: unit
character(len=100) :: line
inquire(file="VERSION", exist=exists)
if (.not.exists) error stop "File VERSION does not exist."
open(file="VERSION", newunit=unit)
read(unit, '(a)') line
close(unit)

print '(*(a))', "File VERSION contains '", trim(line), "'"
end program stub
2 changes: 2 additions & 0 deletions example_packages/version_file/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "version_file"
version = "VERSION"
8 changes: 8 additions & 0 deletions manifest-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ A standardized way to manage and specify versions is the [Semantic Versioning] s
version = "1.0.0"
```

The version entry can also contain a filename relative to the project root, which contains the version number of the project

*Example:*

```toml
version = "VERSION"
```

[Semantic Versioning]: https://semver.org


Expand Down
2 changes: 1 addition & 1 deletion src/fpm/cmd/new.f90
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ subroutine create_verified_basic_manifest(filename)
call set_value(table, "copyright", 'Copyright '//date(1:4)//', Jane Doe')
! continue building of manifest
! ...
call new_package(package, table, error)
call new_package(package, table, error=error)
if (allocated(error)) stop 3
if(settings%verbose)then
call table%accept(ser)
Expand Down
2 changes: 1 addition & 1 deletion src/fpm/manifest.f90
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ subroutine get_package_data(package, file, error, apply_defaults)
return
end if

call new_package(package, table, error)
call new_package(package, table, dirname(file), error)
if (allocated(error)) return

if (present(apply_defaults)) then
Expand Down
29 changes: 26 additions & 3 deletions src/fpm/manifest/package.f90
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module fpm_manifest_package
use fpm_manifest_library, only : library_config_t, new_library
use fpm_manifest_install, only: install_config_t, new_install_config
use fpm_manifest_test, only : test_config_t, new_test
use fpm_filesystem, only : exists, getline, join_path
use fpm_error, only : error_t, fatal_error, syntax_error
use fpm_toml, only : toml_table, toml_array, toml_key, toml_stat, get_value, &
& len
Expand Down Expand Up @@ -99,14 +100,17 @@ module fpm_manifest_package


!> Construct a new package configuration from a TOML data structure
subroutine new_package(self, table, error)
subroutine new_package(self, table, root, error)

!> Instance of the package configuration
type(package_config_t), intent(out) :: self

!> Instance of the TOML data structure
type(toml_table), intent(inout) :: table

!> Root directory of the manifest
character(len=*), intent(in), optional :: root

!> Error handling
type(error_t), allocatable, intent(out) :: error

Expand All @@ -116,8 +120,8 @@ subroutine new_package(self, table, error)
achar(8) // achar(9) // achar(10) // achar(12) // achar(13)
type(toml_table), pointer :: child, node
type(toml_array), pointer :: children
character(len=:), allocatable :: version
integer :: ii, nn, stat
character(len=:), allocatable :: version, version_file
integer :: ii, nn, stat, io

call check(table, error)
if (allocated(error)) return
Expand Down Expand Up @@ -157,6 +161,25 @@ subroutine new_package(self, table, error)

call get_value(table, "version", version, "0")
call new_version(self%version, version, error)
if (allocated(error) .and. present(root)) then
version_file = join_path(root, version)
if (exists(version_file)) then
deallocate(error)
open(file=version_file, newunit=io, iostat=stat)
if (stat == 0) then
call getline(io, version, iostat=stat)
end if
if (stat == 0) then
close(io, iostat=stat)
end if
if (stat == 0) then
call new_version(self%version, version, error)
else
call fatal_error(error, "Reading version number from file '" &
& //version_file//"' failed")
end if
end if
end if
if (allocated(error)) return

call get_value(table, "dependencies", child, requested=.false.)
Expand Down
1 change: 1 addition & 0 deletions src/fpm_filesystem.f90
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ function dirname(path) result (dir)
character(:), allocatable :: dir

dir = path(1:scan(path,'/\',back=.true.))
if (len_trim(dir) == 0) dir = "."

end function dirname

Expand Down
14 changes: 7 additions & 7 deletions test/fpm_test/test_manifest.f90
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ subroutine test_package_simple(error)
call add_table(children, child, stat)
call set_value(child, 'name', '"tester"', stat)

call new_package(package, table, error)
call new_package(package, table, error=error)

end subroutine test_package_simple

Expand All @@ -676,7 +676,7 @@ subroutine test_package_empty(error)

call new_table(table)

call new_package(package, table, error)
call new_package(package, table, error=error)

end subroutine test_package_empty

Expand All @@ -697,7 +697,7 @@ subroutine test_package_typeerror(error)
call new_table(table)
call add_array(table, "name", child, stat)

call new_package(package, table, error)
call new_package(package, table, error=error)

end subroutine test_package_typeerror

Expand All @@ -720,7 +720,7 @@ subroutine test_package_noname(error)
call add_table(table, "dev-dependencies", child, stat)
call add_table(table, "dependencies", child, stat)

call new_package(package, table, error)
call new_package(package, table, error=error)

end subroutine test_package_noname

Expand All @@ -743,7 +743,7 @@ subroutine test_package_wrongexe(error)
call add_array(table, 'executable', children, stat)
call add_array(children, children2, stat)

call new_package(package, table, error)
call new_package(package, table, error=error)

end subroutine test_package_wrongexe

Expand All @@ -766,7 +766,7 @@ subroutine test_package_wrongtest(error)
call add_array(table, 'test', children, stat)
call add_array(children, children2, stat)

call new_package(package, table, error)
call new_package(package, table, error=error)

end subroutine test_package_wrongtest

Expand All @@ -793,7 +793,7 @@ subroutine test_package_duplicate(error)
call add_table(children, child, stat)
call set_value(child, 'name', '"prog"', stat)

call new_package(package, table, error)
call new_package(package, table, error=error)

end subroutine test_package_duplicate

Expand Down