From f63a416f69388239306cd37a3616649216e6273d Mon Sep 17 00:00:00 2001 From: LKedward Date: Thu, 3 Dec 2020 14:56:17 +0000 Subject: Fix: enumeration of executable link objects Adds missing recursive discovery of non-library dependency objects for executable link object lists --- fpm/src/fpm_targets.f90 | 93 ++++++++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 36 deletions(-) diff --git a/fpm/src/fpm_targets.f90 b/fpm/src/fpm_targets.f90 index 03996f7..f9bbcda 100644 --- a/fpm/src/fpm_targets.f90 +++ b/fpm/src/fpm_targets.f90 @@ -259,12 +259,14 @@ function find_module_dependency(targets,module_name,include_dir) result(target_p end function find_module_dependency -!> For link targets, enumerate any dependency objects required for linking +!> For libraries and executables, build a list of objects required for linking +!> +!> stored in `target%link_objects` +!> subroutine resolve_target_linking(targets) type(build_target_ptr), intent(inout), target :: targets(:) - integer :: i,j,k - type(string_t) :: link_object + integer :: i do i=1,size(targets) @@ -272,47 +274,66 @@ subroutine resolve_target_linking(targets) allocate(target%link_objects(0)) - do j=1,size(target%dependencies) - - if (target%target_type == FPM_TARGET_ARCHIVE ) then - - ! Construct object list for archive - link_object%s = target%dependencies(j)%ptr%output_file - target%link_objects = [target%link_objects, link_object] - - else if (target%target_type == FPM_TARGET_EXECUTABLE .and. & - target%dependencies(j)%ptr%target_type == FPM_TARGET_OBJECT) then - - associate(exe_obj => target%dependencies(j)%ptr) - - ! Construct object list for executable - link_object%s = exe_obj%output_file - target%link_objects = [target%link_objects, link_object] - - ! Include non-library object dependencies - do k=1,size(exe_obj%dependencies) - - if (allocated(exe_obj%dependencies(k)%ptr%source)) then - if (exe_obj%dependencies(k)%ptr%source%unit_scope == & - exe_obj%source%unit_scope) then + if (target%target_type == FPM_TARGET_ARCHIVE) then - link_object%s = exe_obj%dependencies(k)%ptr%output_file - target%link_objects = [target%link_objects, link_object] + call get_link_objects(target%link_objects,target,is_exe=.false.) - end if - end if - - end do + else if (target%target_type == FPM_TARGET_EXECUTABLE) then - end associate - - end if + call get_link_objects(target%link_objects,target,is_exe=.true.) + + end if - end do end associate end do +contains + + !> Wrapper to build link object list + !> + !> For libraries: just list dependency objects of lib target + !> + !> For executables: need to recursively discover non-library + !> dependency objects. (i.e. modules in same dir as program) + !> + recursive subroutine get_link_objects(link_objects,target,is_exe) + type(string_t), intent(inout), allocatable :: link_objects(:) + type(build_target_t), intent(in) :: target + logical, intent(in) :: is_exe + + integer :: i + type(string_t) :: temp_str + + if (.not.allocated(target%dependencies)) return + + do i=1,size(target%dependencies) + + associate(dep => target%dependencies(i)%ptr) + + if (.not.allocated(dep%source)) cycle + + ! Skip library dependencies for executable targets + ! since the library archive will always be linked + if (is_exe.and.(dep%source%unit_scope == FPM_SCOPE_LIB)) cycle + + ! Skip if dependency object already listed + if (dep%output_file .in. link_objects) cycle + + ! Add dependency object file to link object list + temp_str%s = dep%output_file + link_objects = [link_objects, temp_str] + + ! For executable objects, also need to include non-library + ! dependencies from dependencies (recurse) + if (is_exe) call get_link_objects(link_objects,dep,is_exe=.true.) + + end associate + + end do + + end subroutine get_link_objects + end subroutine resolve_target_linking -- cgit v1.2.3 From 0d6a0c50c237617d6ea37436ca65301d77725ad8 Mon Sep 17 00:00:00 2001 From: LKedward Date: Thu, 3 Dec 2020 14:57:54 +0000 Subject: Update: dependency tests for updated resolve_target_linking Add checks on the link object lists built for archives and executables in 'resolve_target_linking' --- fpm/test/fpm_test/test_module_dependencies.f90 | 84 ++++++++++++++++++++------ 1 file changed, 66 insertions(+), 18 deletions(-) diff --git a/fpm/test/fpm_test/test_module_dependencies.f90 b/fpm/test/fpm_test/test_module_dependencies.f90 index 18929ac..a7fc269 100644 --- a/fpm/test/fpm_test/test_module_dependencies.f90 +++ b/fpm/test/fpm_test/test_module_dependencies.f90 @@ -1,14 +1,15 @@ !> Define tests for the `fpm_sources` module (module dependency checking) module test_module_dependencies use testsuite, only : new_unittest, unittest_t, error_t, test_failed - use fpm_targets, only: targets_from_sources, resolve_module_dependencies + use fpm_targets, only: targets_from_sources, resolve_module_dependencies, & + resolve_target_linking use fpm_model, only: fpm_model_t, srcfile_t, build_target_t, build_target_ptr, & FPM_UNIT_UNKNOWN, FPM_UNIT_PROGRAM, FPM_UNIT_MODULE, & FPM_UNIT_SUBMODULE, FPM_UNIT_SUBPROGRAM, FPM_UNIT_CSOURCE, & FPM_UNIT_CHEADER, FPM_SCOPE_UNKNOWN, FPM_SCOPE_LIB, & FPM_SCOPE_DEP, FPM_SCOPE_APP, FPM_SCOPE_TEST, & FPM_TARGET_EXECUTABLE, FPM_TARGET_OBJECT, FPM_TARGET_ARCHIVE - use fpm_strings, only: string_t + use fpm_strings, only: string_t, operator(.in.) implicit none private @@ -71,14 +72,17 @@ contains if (allocated(error)) then return end if - + if (size(model%targets) /= 3) then call test_failed(error,'Incorrect number of model%targets - expecting three') return end if + call resolve_target_linking(model%targets) + call check_target(model%targets(1)%ptr,type=FPM_TARGET_ARCHIVE,n_depends=2, & - deps = [model%targets(2),model%targets(3)],error=error) + deps = [model%targets(2),model%targets(3)], & + links = model%targets(2:3), error=error) if (allocated(error)) return @@ -146,8 +150,10 @@ contains return end if + call resolve_target_linking(model%targets) + call check_target(model%targets(1)%ptr,type=FPM_TARGET_ARCHIVE,n_depends=1, & - deps=[model%targets(2)],error=error) + deps=[model%targets(2)],links=[model%targets(2)],error=error) if (allocated(error)) return @@ -162,7 +168,8 @@ contains if (allocated(error)) return call check_target(model%targets(4)%ptr,type=FPM_TARGET_EXECUTABLE,n_depends=2, & - deps=[model%targets(1),model%targets(3)],error=error) + deps=[model%targets(1),model%targets(3)], & + links=[model%targets(3)], error=error) if (allocated(error)) return @@ -202,20 +209,22 @@ contains return end if + call resolve_target_linking(model%targets) + call check_target(model%targets(1)%ptr,type=FPM_TARGET_OBJECT,n_depends=0, & source=sources(1),error=error) if (allocated(error)) return call check_target(model%targets(2)%ptr,type=FPM_TARGET_EXECUTABLE,n_depends=1, & - deps=[model%targets(1)],error=error) + deps=[model%targets(1)],links=[model%targets(1)],error=error) if (allocated(error)) return end subroutine test_program_with_module - !> Check program using a module in same directory + !> Check program using modules in same directory subroutine test_program_own_module_use(error) !> Error handling @@ -233,7 +242,7 @@ contains integer, intent(in) :: exe_scope type(error_t), allocatable, intent(out) :: error - type(srcfile_t) :: sources(2) + type(srcfile_t) :: sources(3) type(fpm_model_t) :: model character(:), allocatable :: scope_str @@ -241,13 +250,17 @@ contains scope_str = merge('FPM_SCOPE_APP ','FPM_SCOPE_TEST',exe_scope==FPM_SCOPE_APP)//' - ' - sources(1) = new_test_source(FPM_UNIT_MODULE,file_name="app/app_mod.f90", & + sources(1) = new_test_source(FPM_UNIT_MODULE,file_name="app/app_mod1.f90", & scope = exe_scope, & - provides=[string_t('app_mod')]) + provides=[string_t('app_mod1')]) - sources(2) = new_test_source(FPM_UNIT_PROGRAM,file_name="app/my_program.f90", & + sources(2) = new_test_source(FPM_UNIT_MODULE,file_name="app/app_mod2.f90", & + scope = exe_scope, & + provides=[string_t('app_mod2')],uses=[string_t('app_mod1')]) + + sources(3) = new_test_source(FPM_UNIT_PROGRAM,file_name="app/my_program.f90", & scope=exe_scope, & - uses=[string_t('app_mod')]) + uses=[string_t('app_mod2')]) call targets_from_sources(model,sources) call resolve_module_dependencies(model%targets,error) @@ -256,11 +269,12 @@ contains return end if - if (size(model%targets) /= 3) then + if (size(model%targets) /= 4) then call test_failed(error,scope_str//'Incorrect number of model%targets - expecting three') return end if + call resolve_target_linking(model%targets) call check_target(model%targets(1)%ptr,type=FPM_TARGET_OBJECT,n_depends=0, & source=sources(1),error=error) @@ -272,11 +286,16 @@ contains if (allocated(error)) return - call check_target(model%targets(3)%ptr,type=FPM_TARGET_EXECUTABLE,n_depends=1, & - deps=[model%targets(2)],error=error) + call check_target(model%targets(3)%ptr,type=FPM_TARGET_OBJECT,n_depends=1, & + source=sources(3),deps=[model%targets(2)],error=error) + + if (allocated(error)) return + + call check_target(model%targets(4)%ptr,type=FPM_TARGET_EXECUTABLE,n_depends=1, & + deps=[model%targets(3)],links=model%targets(1:3), error=error) if (allocated(error)) return - + end subroutine test_scope end subroutine test_program_own_module_use @@ -414,12 +433,13 @@ contains !> Helper to check an expected output target - subroutine check_target(target,type,n_depends,deps,source,error) + subroutine check_target(target,type,n_depends,deps,links,source,error) type(build_target_t), intent(in) :: target integer, intent(in) :: type integer, intent(in) :: n_depends type(srcfile_t), intent(in), optional :: source type(build_target_ptr), intent(in), optional :: deps(:) + type(build_target_ptr), intent(in), optional :: links(:) type(error_t), intent(out), allocatable :: error integer :: i @@ -448,6 +468,34 @@ contains end if + if (present(links)) then + + do i=1,size(links) + + if (.not.(links(i)%ptr%output_file .in. target%link_objects)) then + call test_failed(error,'Missing object ('//links(i)%ptr%output_file//& + ') for executable "'//target%output_file//'"') + return + end if + + end do + + if (size(links) > size(target%link_objects)) then + + call test_failed(error,'There are missing link objects for target "'& + //target%output_file//'"') + return + + elseif (size(links) < size(target%link_objects)) then + + call test_failed(error,'There are more link objects than expected for target "'& + //target%output_file//'"') + return + + end if + + end if + if (present(source)) then if (allocated(target%source)) then -- cgit v1.2.3 From 418454ceee23ddd835b4b1a8cd85050ed50d2925 Mon Sep 17 00:00:00 2001 From: LKedward Date: Thu, 3 Dec 2020 15:22:58 +0000 Subject: Update example package for indirect module use Update hello_complex_2 example package to add a non-library module that is indirectly used by an app in the same directory. --- example_packages/hello_complex_2/app/say_hello/app_extra_mod.f90 | 6 ++++++ example_packages/hello_complex_2/app/say_hello/app_hello_mod.f90 | 1 + example_packages/hello_complex_2/app/say_hello/say_Hello.f90 | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 example_packages/hello_complex_2/app/say_hello/app_extra_mod.f90 diff --git a/example_packages/hello_complex_2/app/say_hello/app_extra_mod.f90 b/example_packages/hello_complex_2/app/say_hello/app_extra_mod.f90 new file mode 100644 index 0000000..5059e22 --- /dev/null +++ b/example_packages/hello_complex_2/app/say_hello/app_extra_mod.f90 @@ -0,0 +1,6 @@ +module app_extra_mod +implicit none + +character(len=5) :: greet_object = "World" + +end module app_extra_mod diff --git a/example_packages/hello_complex_2/app/say_hello/app_hello_mod.f90 b/example_packages/hello_complex_2/app/say_hello/app_hello_mod.f90 index c5795cb..e44edd7 100644 --- a/example_packages/hello_complex_2/app/say_hello/app_hello_mod.f90 +++ b/example_packages/hello_complex_2/app/say_hello/app_hello_mod.f90 @@ -1,4 +1,5 @@ module app_hello_mod +use app_extra_mod, only: greet_object implicit none integer :: hello_int = 42 diff --git a/example_packages/hello_complex_2/app/say_hello/say_Hello.f90 b/example_packages/hello_complex_2/app/say_hello/say_Hello.f90 index 3b69ba7..3ebaebb 100644 --- a/example_packages/hello_complex_2/app/say_hello/say_Hello.f90 +++ b/example_packages/hello_complex_2/app/say_hello/say_Hello.f90 @@ -1,8 +1,8 @@ program say_Hello use greet_m, only: make_greeting - use app_hello_mod + use app_hello_mod, only: greet_object implicit none - print *, make_greeting("World") + print *, make_greeting(greet_object) end program say_Hello -- cgit v1.2.3 From 75f8eda5115f3f5160d8aeda63f72d7c852684f7 Mon Sep 17 00:00:00 2001 From: LKedward Date: Sat, 5 Dec 2020 16:53:46 +0000 Subject: Update tests: to include run and test commands --- ci/run_tests.bat | 6 ++++++ ci/run_tests.sh | 2 ++ 2 files changed, 8 insertions(+) diff --git a/ci/run_tests.bat b/ci/run_tests.bat index 533590d..22be2db 100755 --- a/ci/run_tests.bat +++ b/ci/run_tests.bat @@ -36,6 +36,9 @@ if errorlevel 1 exit 1 .\build\gfortran_debug\app\hello_world if errorlevel 1 exit 1 +%fpm_path% run +if errorlevel 1 exit 1 + cd ..\hello_fpm if errorlevel 1 exit 1 @@ -71,6 +74,9 @@ del /q /f build %fpm_path% build if errorlevel 1 exit 1 +%fpm_path% test +if errorlevel 1 exit 1 + .\build\gfortran_debug\app\say_Hello if errorlevel 1 exit 1 diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 3588012..85484e5 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -23,6 +23,7 @@ rm -rf ./*/build cd hello_world "${f_fpm_path}" build ./build/gfortran_debug/app/hello_world +"${f_fpm_path}" run cd ../hello_fpm "${f_fpm_path}" build @@ -36,6 +37,7 @@ cd ../circular_example cd ../hello_complex "${f_fpm_path}" build +"${f_fpm_path}" test ./build/gfortran_debug/app/say_Hello ./build/gfortran_debug/app/say_goodbye ./build/gfortran_debug/test/greet_test -- cgit v1.2.3 From 8f2d19af16e06cfb5f54d9df548237b2cb7ab2f5 Mon Sep 17 00:00:00 2001 From: LKedward Date: Sat, 5 Dec 2020 17:06:40 +0000 Subject: Fix: output path for Windows Remove hard-coded forward slash. --- fpm/src/fpm.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fpm/src/fpm.f90 b/fpm/src/fpm.f90 index b94d25f..e041924 100644 --- a/fpm/src/fpm.f90 +++ b/fpm/src/fpm.f90 @@ -171,7 +171,7 @@ subroutine build_model(model, settings, package, error) model%fortran_compiler = 'gfortran' if(settings%release)then - model%output_directory = 'build/gfortran_release' + model%output_directory = join_path('build','gfortran_release') model%fortran_compile_flags=' & & -O3 & & -Wimplicit-interface & @@ -181,7 +181,7 @@ subroutine build_model(model, settings, package, error) & -funroll-loops ' // & & '-J'//join_path(model%output_directory,model%package_name) else - model%output_directory = 'build/gfortran_debug' + model%output_directory = join_path('build','gfortran_debug') model%fortran_compile_flags = ' -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g '// & '-fbounds-check -fcheck-array-temporaries -fbacktrace '// & '-J'//join_path(model%output_directory,model%package_name) -- cgit v1.2.3 From 7f1611d55d3fd431401008121a3cdf93e7d3968d Mon Sep 17 00:00:00 2001 From: LKedward Date: Sat, 5 Dec 2020 17:15:20 +0000 Subject: Bump patch number --- fpm/fpm.toml | 2 +- fpm/src/fpm_command_line.f90 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fpm/fpm.toml b/fpm/fpm.toml index c30c9b4..dd92230 100644 --- a/fpm/fpm.toml +++ b/fpm/fpm.toml @@ -1,5 +1,5 @@ name = "fpm" -version = "0.1.1" +version = "0.1.2" license = "MIT" author = "fpm maintainers" maintainer = "" diff --git a/fpm/src/fpm_command_line.f90 b/fpm/src/fpm_command_line.f90 index 03daf6f..29991e5 100644 --- a/fpm/src/fpm_command_line.f90 +++ b/fpm/src/fpm_command_line.f90 @@ -83,7 +83,7 @@ contains case default ; os_type = "OS Type: UNKNOWN" end select version_text = [character(len=80) :: & - & 'Version: 0.1.1, alpha', & + & 'Version: 0.1.2, alpha', & & 'Program: fpm(1)', & & 'Description: A Fortran package manager and build system', & & 'Home Page: https://github.com/fortran-lang/fpm', & -- cgit v1.2.3 From db93172961aca4f4ba990264d2accfa2dd44a1d1 Mon Sep 17 00:00:00 2001 From: Laurence Kedward Date: Mon, 7 Dec 2020 10:59:53 +0000 Subject: Remove spurious whitespace change --- fpm/test/fpm_test/test_module_dependencies.f90 | 1 - 1 file changed, 1 deletion(-) diff --git a/fpm/test/fpm_test/test_module_dependencies.f90 b/fpm/test/fpm_test/test_module_dependencies.f90 index a7fc269..5d78e0c 100644 --- a/fpm/test/fpm_test/test_module_dependencies.f90 +++ b/fpm/test/fpm_test/test_module_dependencies.f90 @@ -72,7 +72,6 @@ contains if (allocated(error)) then return end if - if (size(model%targets) /= 3) then call test_failed(error,'Incorrect number of model%targets - expecting three') return -- cgit v1.2.3