Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions ci/run_tests.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ if errorlevel 1 exit 1
fpm run
if errorlevel 1 exit 1

fpm test
if errorlevel 1 exit 1

build\gfortran_debug\app\fpm
if errorlevel 1 exit 1

Expand Down
1 change: 1 addition & 0 deletions ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -ex
cd fpm
fpm build
fpm run
fpm test
build/gfortran_debug/app/fpm
cd ../test/example_packages/hello_world
../../../fpm/build/gfortran_debug/app/fpm build
Expand Down
8 changes: 8 additions & 0 deletions fpm/fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ license = "MIT"
author = "fpm maintainers"
maintainer = ""
copyright = "2020 fpm contributors"

[dependencies]
toml-f = { git = "https://github.com/toml-f/toml-f" }

[[test]]
name = "fpm-test"
source-dir = "test"
main = "main.f90"
70 changes: 47 additions & 23 deletions fpm/src/fpm.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module fpm
use environment, only: get_os_type, OS_LINUX, OS_MACOS, OS_WINDOWS
use fpm_config, only : get_package_data, default_executable, default_library, &
& package_t
use fpm_error, only : error_t
implicit none
private
public :: cmd_build, cmd_install, cmd_new, cmd_run, cmd_test
Expand Down Expand Up @@ -85,34 +88,55 @@ logical function str_ends_with(s, e) result(r)
end if
end function

subroutine package_name(name)
character(:), allocatable, intent(out) :: name
! Currrently a heuristic. We should update this to read the name from fpm.toml
if (exists("src/fpm.f90")) then
name = "fpm"
else
name = "hello_world"
end if
end subroutine

subroutine cmd_build()
type(package_t) :: package
type(error_t), allocatable :: error
type(string_t), allocatable :: files(:)
character(:), allocatable :: basename, pkg_name, linking
character(:), allocatable :: basename, linking
integer :: i, n
print *, "# Building project"
call list_files("src", files)
call get_package_data(package, "fpm.toml", error)
if (allocated(error)) then
print '(a)', error%message
error stop 1
end if

! Populate library in case we find the default src directory
if (.not.allocated(package%library) .and. exists("src")) then
call default_library(package%library)
end if

! Populate executable in case we find the default app directory
if (.not.allocated(package%executable) .and. exists("app")) then
allocate(package%executable(1))
call default_executable(package%executable(1), package%name)
end if

if (.not.(allocated(package%library) .or. allocated(package%executable))) then
print '(a)', "Neither library nor executable found, there is nothing to do"
error stop 1
end if

linking = ""
do i = 1, size(files)
if (str_ends_with(files(i)%s, ".f90")) then
n = len(files(i)%s)
basename = files(i)%s(1:n-4)
call run("gfortran -c src/" // basename // ".f90 -o " // basename // ".o")
linking = linking // " " // basename // ".o"
end if
if (allocated(package%library)) then
call list_files(package%library%source_dir, files)
do i = 1, size(files)
if (str_ends_with(files(i)%s, ".f90")) then
n = len(files(i)%s)
basename = files(i)%s
call run("gfortran -c " // package%library%source_dir // "/" // &
& basename // " -o " // basename // ".o")
linking = linking // " " // basename // ".o"
end if
end do
end if

do i = 1, size(package%executable)
basename = package%executable(i)%main
call run("gfortran -c " // package%executable(i)%source_dir // "/" // &
& basename // " -o " // basename // ".o")
call run("gfortran " // basename // ".o " // linking // " -o " // &
& package%executable(i)%name)
end do
call run("gfortran -c app/main.f90 -o main.o")
call package_name(pkg_name)
call run("gfortran main.o " // linking // " -o " // pkg_name)
end subroutine

subroutine cmd_install()
Expand Down
79 changes: 79 additions & 0 deletions fpm/src/fpm/config.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
!> Package configuration data.
!
! This module provides the necessary procedure to translate a TOML document
! to the corresponding Fortran type, while verifying it with respect to
! its schema.
!
! Additionally, the required data types for users of this module are reexported
! to hide the actual implementation details.
module fpm_config
use fpm_config_executable, only : executable_t
use fpm_config_library, only : library_t
use fpm_config_package, only : package_t, new_package
use fpm_error, only : error_t, fatal_error, file_not_found_error
use fpm_toml, only : toml_table, read_package_file
implicit none
private

public :: get_package_data, default_executable, default_library
public :: package_t


contains


!> Populate library in case we find the default src directory
subroutine default_library(self)

!> Instance of the library meta data
type(library_t), intent(out) :: self

self%source_dir = "src"

end subroutine default_library


!> Populate executable in case we find the default app directory
subroutine default_executable(self, name)

!> Instance of the executable meta data
type(executable_t), intent(out) :: self

!> Name of the package
character(len=*), intent(in) :: name

self%name = name
self%source_dir = "app"
self%main = "main.f90"

end subroutine default_executable


!> Obtain package meta data from a configuation file
subroutine get_package_data(package, file, error)

!> Parsed package meta data
type(package_t), intent(out) :: package

!> Name of the package configuration file
character(len=*), intent(in) :: file

!> Error status of the operation
type(error_t), allocatable, intent(out) :: error

type(toml_table), allocatable :: table

call read_package_file(table, file, error)
if (allocated(error)) return

if (.not.allocated(table)) then
call fatal_error(error, "Unclassified error while reading: '"//file//"'")
return
end if

call new_package(package, table, error)

end subroutine get_package_data


end module fpm_config
Loading