Skip to content

Commit 56b846f

Browse files
committed
Resolve conflicts
2 parents 13db2fe + 033146f commit 56b846f

File tree

12 files changed

+366
-27
lines changed

12 files changed

+366
-27
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
os: [ubuntu-latest, macos-11, windows-latest]
25-
gcc_v: [9] # Version of GFortran we want to use.
25+
gcc_v: [10] # Version of GFortran we want to use.
2626
include:
2727
- os: ubuntu-latest
2828
os-arch: linux-x86_64

ci/run_tests.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,41 @@ pushd cpp_files
158158
"$fpm" test
159159
popd
160160

161+
# Test app exit codes
162+
pushd fpm_test_exit_code
163+
"$fpm" build
164+
165+
# odd number -> success!
166+
EXIT_CODE=0
167+
"$fpm" run -- 1 || EXIT_CODE=$?
168+
test $EXIT_CODE -eq 0
169+
170+
# even number -> error 3
171+
EXIT_CODE=0
172+
"$fpm" run -- 512 || EXIT_CODE=$?
173+
test $EXIT_CODE -eq 3
174+
175+
# even number -> error 3
176+
EXIT_CODE=0
177+
"$fpm" run -- 0 || EXIT_CODE=$?
178+
test $EXIT_CODE -eq 3
179+
180+
# not an integer -> error 2
181+
EXIT_CODE=0
182+
"$fpm" run -- 3.1415 || EXIT_CODE=$?
183+
test $EXIT_CODE -eq 2
184+
185+
# not a number -> error 2
186+
EXIT_CODE=0
187+
"$fpm" run -- notanumber || EXIT_CODE=$?
188+
test $EXIT_CODE -eq 2
189+
190+
# no arguments -> error 1
191+
EXIT_CODE=0
192+
"$fpm" run || EXIT_CODE=$?
193+
test $EXIT_CODE -eq 1
194+
popd
195+
196+
161197
# Cleanup
162198
rm -rf ./*/build
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# fpm_test_exit_code
2+
Test program for application exit codes
3+
see https://github.com/fortran-lang/fpm/issues/848
4+
5+
This app expects to receive an integer command line argument, to check whether it is odd or even.
6+
It returns 0 on success (odd input), or among a few error codes otherwise.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
! Test program for application exit codes
2+
! see https://github.com/fortran-lang/fpm/issues/848
3+
4+
! This app expects to receive an integer command line argument, to check whether it is odd or even.
5+
! It returns 0 on success (odd input), or among a few error codes otherwise.
6+
7+
program check_odd_number
8+
implicit none
9+
10+
integer, parameter :: SUCCESS = 0
11+
integer, parameter :: INVALID_ARGUMENT = 1
12+
integer, parameter :: NOT_AN_INTEGER = 2
13+
integer, parameter :: NOT_ODD = 3
14+
15+
character(len=1024) :: buffer
16+
integer :: ierr,ln,the_number
17+
18+
! If the argument is missing or not an integer, return an error flag
19+
if (command_argument_count()/=1) stop INVALID_ARGUMENT
20+
21+
! Get command argument
22+
call get_command_argument(1,value=buffer,length=ln,status=ierr)
23+
24+
! On invalid string
25+
if (ln<1 .or. ierr/=0) stop INVALID_ARGUMENT
26+
27+
! Read to int
28+
read(buffer(:ln),*,iostat=ierr) the_number
29+
30+
! On invalid integer
31+
if (ierr/=0) stop NOT_AN_INTEGER
32+
33+
! Check if it is odd or even
34+
if (mod(the_number,2)==0) then
35+
! Is even
36+
stop NOT_ODD
37+
else
38+
! Is odd
39+
stop SUCCESS
40+
end if
41+
42+
end program check_odd_number
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name = "fpm_test_exit_code"
2+
version = "0.1.0"
3+
license = "license"
4+
author = "Federico Perini"
5+
maintainer = "[email protected]"
6+
copyright = "Copyright 2023, Jane Doe"
7+
[build]
8+
auto-executables = true
9+
[install]
10+
library = false

src/fpm.f90

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ subroutine build_model(model, settings, package, error)
5656
call model%deps%add(package, error)
5757
if (allocated(error)) return
5858

59+
! Update dependencies where needed
60+
call model%deps%update(error)
61+
if (allocated(error)) return
62+
5963
! build/ directory should now exist
6064
if (.not.exists("build/.gitignore")) then
6165
call filewrite(join_path("build", ".gitignore"),["*"])
@@ -435,7 +439,7 @@ subroutine cmd_run(settings,test)
435439
type(string_t), allocatable :: executables(:)
436440
type(build_target_t), pointer :: exe_target
437441
type(srcfile_t), pointer :: exe_source
438-
integer :: run_scope
442+
integer :: run_scope,firsterror
439443
integer, allocatable :: stat(:)
440444
character(len=:),allocatable :: line
441445
logical :: toomany
@@ -580,10 +584,12 @@ subroutine cmd_run(settings,test)
580584
if (any(stat /= 0)) then
581585
do i=1,size(stat)
582586
if (stat(i) /= 0) then
583-
write(stderr,'(*(g0:,1x))') '<ERROR> Execution failed for object "',basename(executables(i)%s),'"'
587+
write(stderr,'(*(g0:,1x))') '<ERROR> Execution for object "',basename(executables(i)%s),&
588+
'" returned exit code ',stat(i)
584589
end if
585590
end do
586-
call fpm_stop(1,'*cmd_run*: Stopping due to failed executions')
591+
firsterror = findloc(stat/=0,value=.true.,dim=1)
592+
call fpm_stop(stat(firsterror),'*cmd_run*:stopping due to failed executions')
587593
end if
588594

589595
endif

src/fpm/cmd/update.f90

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ subroutine cmd_update(settings)
4343
if (settings%fetch_only) return
4444

4545
if (size(settings%name) == 0) then
46-
do ii = 1, deps%ndep
47-
call deps%update(deps%dep(ii)%name, error)
48-
call handle_error(error)
49-
end do
46+
call deps%update(error)
47+
call handle_error(error)
5048
else
5149
do ii = 1, size(settings%name)
5250
call deps%update(trim(settings%name(ii)), error)

0 commit comments

Comments
 (0)