fpm icon indicating copy to clipboard operation
fpm copied to clipboard

Add --directory flag for run and test

Open LKedward opened this issue 4 years ago • 2 comments

A useful addition would be a --directory flag to specify a directory to change to before running an executable.

LKedward avatar Mar 24 '21 12:03 LKedward

This will be important for applications that expect input files to be present, as well as output files, in the current directory.

milancurcic avatar Mar 24 '21 16:03 milancurcic

Since we now support -C/--directory to change the working directory of fpm. In principle we can change the working directory for the fpm run command. Still, fpm requires the package manifest to be placed in the current working directory, this must be made more flexible for this option to actually to become useful.

On the other hand, we have the automatic discovery of the package manifest in place, fpm is able to locate the manifest file in the parent directory. Our mechanism to make fpm work correctly in this scenario is to change to the project root directory... which takes away any potential advantages of using the -C/--directory option at the moment.

Instead we should retain both the working directory and the automatic detected project root and use those to correctly setup all file paths relative to our initial/final working directory (depending whether we actually change the working directory in the run). The main difficulty is to identify all relative file paths which must be aware of the difference between working directory and project root directory.

One solution is to have a file system context, which can be used to access all file paths and is able to automatically convert paths relative to the project root to paths relative to the current working directory.

awvwgk avatar Sep 26 '21 08:09 awvwgk