fpm
fpm copied to clipboard
Exclude build, app, example and test folders when source-dir is project root
Description
Following on from this discussion: https://fortran-lang.discourse.group/t/fpm-builds-where-the-build-dir-is-in-the-source-dir/5882/5
If the user sets the source-dir
folder as the project root, i.e.
[library]
source-dir = "./"
then currently, the fpm-generated build
folder is included in the build. This is along with any other user-generated app, example and test folders, which I guess might not be named as such.
The problem with the build
folder being included is that it might include dependencies from e.g. GitHub that are already being built separately to the main build. This means fpm tries to build them twice and you get an error <ERROR>*build_model*:Error: One or more duplicate module names found.
The two suggested options are to:
- Raise an error in case the
source-dir
is set to./
(forbid the source directory from being the project root) - Exclude the build, test, example, and app, directories, and consider everything else to be source.
Personally my preference would be the latter. Though it's not best practice, I suspect there is a lot of legacy code that has the source files in the project root and we don't want to arbitrarily exclude these (or force them to update their project structure) for fear of putting people off using fpm for being too prescriptive.
Expected Behaviour
When the user sets source-dir
as the project root, either the build, app, test and example directories are excluded from the build, or the user is warned against / forbidden from doing so.
Version of fpm
0.8.2
Platform and Architecture
All
Additional Information
No response
Let me link to a relevant discussion at #847: current consensus is that all source files should be under src/
, app/
, test/
I totally get that for new projects, but that rather limits fpm's usefulness for:
- Legacy projects where you don't want to mess with the project folder structure (e.g. because you might end up breaking other still-supported build processes)
- Single-file projects, as nicely described here: https://fortran-lang.discourse.group/t/fpm-builds-where-the-build-dir-is-in-the-source-dir/5882/6?u=samharrison7
I would also support your PR for multiple source directories - that would actually fix the reason for which I initially set source-dir
to the project root.