Skip to content

Fix for backtrace error when file not found in: src/fpm_source_parsing.f90#675

Merged
awvwgk merged 3 commits intofortran-lang:mainfrom
wiremoons:main
Mar 13, 2022
Merged

Fix for backtrace error when file not found in: src/fpm_source_parsing.f90#675
awvwgk merged 3 commits intofortran-lang:mainfrom
wiremoons:main

Conversation

@wiremoons
Copy link
Copy Markdown
Member

When using fpm run and a source file stated in a projects fpm.toml is missing a backtrace would be generated - example below:

% fpm run
 + mkdir -p build/dependencies
At line 86 of file ./src/fpm_source_parsing.f90
Fortran runtime error: Cannot open file 'app/aoc_day02_p2.f90': No such file or directory

Error termination. Backtrace:
#0  0x104ea9147
#1  0x104ea9dbf
#2  0x104eaa743
#3  0x104f6f553
#4  0x104f6f787
#5  0x104a85e0f
#6  0x104a87db7
#7  0x104a8b837
#8  0x104a6311b
#9  0x104a64af3
#10  0x104a612a3
#11  0x104adbf2f

This patch checks for the files existence, before any further parsing is attempted.

After applying this proposed fix, when a file is missing (as in the example above) then an error is shown instead of the backtrace:

% fpm run
<ERROR>*cmd_run*:model error:'app/aoc_day02_p2.f90' could not be found, check if the file exists
STOP 1

Uses the fpm subroutine file_not_found_error which I hope is the correct action to perform on the error.

@awvwgk
Copy link
Copy Markdown
Member

awvwgk commented Mar 13, 2022

We should already have a function called exists to check whether a file is present.

Fix indentation as corrected by @awvwgk

Co-authored-by: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com>
@wiremoons
Copy link
Copy Markdown
Member Author

We should already have a function called exists to check whether a file is present.

Yes - that would be useful so it is available for any other file handling in fpm.

Any suggestions on the best fpm project file to locate the function in - assuming its use would be project wide?

@awvwgk
Copy link
Copy Markdown
Member

awvwgk commented Mar 13, 2022

Yes - that would be useful so it is available for any other file handling in fpm.

I meant we already have such a function: https://fortran-lang.github.io/fpm/proc/exists.html

Copy link
Copy Markdown
Member

@awvwgk awvwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing. This is a useful improvement.

@awvwgk awvwgk merged commit e318ef2 into fortran-lang:main Mar 13, 2022
@wiremoons
Copy link
Copy Markdown
Member Author

I meant we already have such a function: https://fortran-lang.github.io/fpm/proc/exists.html

Thanks @awvwgk. There is a lot of useful functions in that fpm_filesystem module. A lot of them would be useful in stdlib too, perhaps in the stdlib_io module, so others could use them as well? Just a thought...

@awvwgk
Copy link
Copy Markdown
Member

awvwgk commented Mar 13, 2022

Fpm and stdlib have a somewhat ambivalent relation at the moment. While we would really like to use stdlib in fpm the size of the stdlib dependency would block us from bootstrapping fpm and on the other hand we have stdlib which currently can't be built with fpm directly but needs a separate deployment step.

Both issues could be fixed on the fpm side:

  • support tree shaking to only require the relevant components of stdlib
  • provide fypp support or CMake build file generation in fpm and build stdlib with fpm

Further, in fpm our development cycles so far were much faster than stdlib, when implementing features in fpm new filesystem functions are just a byproduct, while in stdlib it takes weeks to months to hammer out the API and get the required patches merged.

I think this are the reasons why we didn't really see much overlap and exchange yet between fpm and stdlib, but this shouldn't discourage anyone from porting features available in fpm to stdlib to make them available for the wider Fortran ecosystem and in the long-run also in fpm again or even better try to make stdlib usage in fpm more feasible by improving fpm for stdlib.

@ivan-pi
Copy link
Copy Markdown
Member

ivan-pi commented Mar 13, 2022

Great analysis. Can't the fpm modules also be used as a dependency in other fpm projects?

@awvwgk
Copy link
Copy Markdown
Member

awvwgk commented Mar 13, 2022

Indeed you can depend on fpm like on every other fpm project.

@awvwgk awvwgk added this to the v0.6.0 milestone Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants