fortran-lang / fpm

Fortran Package Manager (fpm)
https://fpm.fortran-lang.org
MIT License
892 stars 100 forks source link

Allow file permissions for fpm-install #314

Open awvwgk opened 3 years ago

awvwgk commented 3 years ago

Currently the install command can only copy files from the build directory to a prefix. As pointed out in #257 it would be helpful to define permissions for the installed executables as well.

For this purpose we could search for the install program and leverage the built-in permission handling or do the permissions ourselves using chmod. This will probably be limited to POSIX platforms (Unix and Cygwin).

urbanjost commented 3 years ago

There is a WHICH(3f) function in my collection I added to M_io.f90 that might be useful. I wrote it for POSIX and Windows but have not used MSWindows much but if it does not work there I think it would be easy to change.M_io.

It gets the environment variable PATH and then parses it and then joins it with the command name and then uses INQUIRE to see if the file exists. If install is not there it could look for chmod or whatever other systems have that might be equivalent. I just pulled it into M_io and did not test it much but the idea has worked successfully in several situations -- looking on a system to see which Adobe PDF viewer can be found, what browers are available, what GIF display command is available, ... . I need to add a unit test for it and do some testing but that should not prevent you from taking a quick look to see if the idea appeals to you. .

urbanjost commented 3 years ago

It calls a few other procedures, but copies or equivalents are already in fpm --- split, join_path (or joinpath?), instead of the separator function there is an OS detection routine that would give you the same feature and would cut down on duplication. If you want me to make an "fpm" version let me know.

I guess now all I have to say instead is

 cd /tmp
 git clone https://github.com/urbanjost/M_io
 cd M_io
 fpm run --example demo_which

before install existed in fpm I was using a shell script called "fpm-install" that might be relevant

#!/bin/bash
#@(#) install executables in directory (assuming install(1) exists)
DIR=${FPM_INSTALL_DIR:-"$HOME/.local/bin"}
mkdir -p $DIR
ffpm run  --release --compiler gfortran --runner "install -vbp -m 0711 -t $DIR" $*
awvwgk commented 3 years ago

I have a similar path-reader in one of my projects (here), which I use to search for config or parameter files. This one could be repurposed as which clone as well.

This sounds like a feature for stdlib_os in my opinion. I wonder if we could port this one easily from CMake to fpm?

urbanjost commented 3 years ago

Amazing project. Lost myself for a while in it. Tried moving it to fpm and get hung up with Fortran fpm not having an fpm.mk option and there being no way without making a custom version or using backdoors like ifort configuration files to customize the compiles and links with fpm yet. That stopped me with some much simpler projects that just required X11 Windows or an external package. Have tried a few approaches (including response files which I added to a newer version of M_CLI2, and "external packages" that really were not a package, looked at some other package managers ..) and really did not find anything that did not seem like a kludge or required so much customizing it was easier to just do it with Make/CMake ...) . Maybe there is no elegantly simple way to handle cuda/MPI/OpenMPI/OpenACC/coarrays... until coarrays develops further). So I am thinking the main point is it does not have to be simple to set up, but able to be packaged in such a way it is simple for a user of the package to use as much as possible. Allowing multiple compilers complicates that too. My own system builds everything into a production layout directly, where two variables (one for OS, one for a compiler) to build the directory. The two variables are set automatically but can be set by the user. So instead of "Linux" and "ifort" you can make up other names like "ifort_coarray" and add an entry in a file that defines the switches, but that does not quite fit the fpm model. The solution has to bundle with the package to be easily useable by an end-user of the package.