mesonic icon indicating copy to clipboard operation
mesonic copied to clipboard

Installing from vim

Open albfan opened this issue 6 years ago • 4 comments

I know this is not exactly a mesonic issue, just gathering info about install a meson project

how one can use :make as normal user and :make install involving sudo?

As it normally will install on /usr/local how you can force prefix as usr?

albfan avatar Jan 12 '19 10:01 albfan

After reading your question I decided to add MesonConfigure command that sets meson options. It was sitting in my .vimrc for a while and I never had the time to add it to the plugin. Now you can change prefix and any other meson options as follows:

:MesonConfigure -Dprefix=/usr

Please, see README file for more examples.

If I understand you correctly, you need a command that gets different permissions depending on the first argument. As it is unusual for build systems to get different access permissions depending on their arguments, the best way to achieve that is to write a wrapper script and use it instead of plain ninja command to build the project.

I'll give you an example. First, write a script build.sh:

#!/bin/sh
action="$1"
if test "$action" = "install"
then
    sudo ninja "$@"
else
    ninja "$@"
fi

Then set this variable in your .vimrc.

let meson_ninja_command = 'path/to/build.sh'

After that :make install will run sudo ninja. Changing prefix can be achieved by adding meson configure command in the script. Changing prefix every time you build your project is not recommended as it may trigger recompilation of many source files.

igankevich avatar Jan 12 '19 15:01 igankevich

That's great, I'm gitg maintainer and member of GNOME foundation (we all use meson in deep) Will spread the word about this fantastic plugin!

albfan avatar Jan 12 '19 16:01 albfan

I'm glad you liked it :-)

igankevich avatar Jan 12 '19 21:01 igankevich

I think I didn't explain correctly.

this plugin set makprg as "meson compile" so

:make

does:

meson compile -C build 

while:

:make install

does:

meson compile -C build install
INFO: autodetecting backend as ninja

ERROR: Can't invoke target `install`: target not found

here there's a difference between goals and targets. make install is a phony goal, like make test

I see you define MesonTest to run meson test so I think we need a MesonInstall, but there might be other options.

As an example meson install detects if you need elevated privileges

        except PermissionError:
            if is_windows() or destdir != '' or not os.isatty(sys.stdout.fileno()) or not os.isatty(sys.stderr.fileno()):

only if you are not on windows.

so sudo problem can be resolved with:

:terminal meson install -C build

and meson resolves that for you

still as a wrapper that turns meson into a make thing, maybe make install, make test makes sense (if you are not building a test or install app) and we can detect some phony targets.

:MesonPhony install
:MesonPhony test

Maybe it is overcomplicated, but let me know your thoughs. MesonInstall is probably enough

albfan avatar Nov 03 '25 13:11 albfan