New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow fpm to change the working directory #483
Conversation
bind(C, name="chdir") | ||
#else | ||
bind(C, name="_chdir") | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine for this PR, but down the road we should move all these platform specific ifdefs into a platform.f90
or compatibility.f90
file, and then just use
such a file here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was tempted to do:
#ifndef _WIN32
character(len=*), parameter :: chdir_symbol = "chdir"
#else
character(len=*), parameter :: chdir_symbol = "_chdir"
#endif
! ...
function chdir(...) bind(C, name=chdir_symbol)
But GFortran didn't like those, unfortunately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to try exactly that to see if it works! Then we could have the chdir_symbol
in platform.f90
. As it is now, we'll have to move the whole chdir
definition into platform.f90
, which is fine too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used string concatenation in the past with bind(C, name=namespace//"...")
so in principle this seems to work. But here I'm hitting:
./src/fpm_os.F90:18:29:
18 | bind(C, name=chdir_symbol)
| 1
Error: Parameter ‘chdir_symbol’ at (1) has not been declared or is a variable, which does not reduce to a constant expression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is not possible because the interface is a separate scoping unit not automatically inheriting the module scope. Using import
will also not work here because it would make the parameter available after it has been used. That's a tricky one, maybe worth a thread on discourse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Posted here: https://fortran-lang.discourse.group/t/constant-expressions-for-bind-c-name/1319
Let's see if somebody more knowledgeable in the Fortran standard can help us out here.
Okay, than let's try this:
Give it a try:
|
Autodiscovery seems to works nicely but would it not be better to change back to the original directory after the model has been built? This would allow me to do It seems that we still need two separate options:
What do you think? |
I think we will need both, knowledge about the working directory and the project root at every point in fpm. With this patch right now a command like
will copy the executable into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me now. Thanks!
This looks good to go so with two approvals I'll now merge. Thanks @awvwgk |
This allow to use
fpm -C <PATH>
to change the working directory and enables the automatic discovery of a package manifest in the parent directories.Explicitly changing of directories
-C, --directory PATH
: Change working directory toPATH
before running any command.After checking out this pull request locally, you should be able to build the example package by:
Automatic discovery of manifest files
With a directory changing mechanism we can also easily implement a mechanism to ”find” the package manifest in a parent directory. For this purpose fpm will retrieve the current working directory and check if a package manifest exists in any of the parent directories. By changing to this directory, all other commands can be used directly without modification.
You should be able to check this behavior with
If you copy / install the fpm executable you can also check the automatic discovery without the
-C
/--directory
option. It should work just the same.Please try to break this feature.
Caveats
This introduces preprocessor usage into fpm, not sure if we are actually able to avoid it without using compiler extensions at this point.
Related #481, #172