Commit Graph

98 Commits

Author SHA1 Message Date
Daniele Nicolodi 97320e7186 minstall: Replace non-breakable space with plain space in comment 2023-02-27 07:03:30 -05:00
Eli Schwartz 616bf1f79d
minstall: add a timeout when waiting for user input for elevation
Do not allow hanging forever.

It's fine to use selectors here, which are unix-only, because we require
Unix + a system that has e.g. sudo installed, anyway.
2023-02-20 22:33:46 -05:00
Eli Schwartz 55abcbb8f6
minstall: check 5 times for an answer to the elevation prompt
The user might press enter by accident and miss the message.
2023-02-20 22:33:46 -05:00
Eli Schwartz ecb32bf457
minstall: drop privileges before running rebuild_all
If the user runs `sudo meson install` this may run ninja to build
everything that gets installed. This naturally happens as root also, by
default, which is bad. Instead, detect root elevation tools and drop the
uid/gid of the child ninja process back to the original invoking user
before doing anything.
2023-02-20 22:33:46 -05:00
Eli Schwartz a878c38476
minstall: rework root elevation prompt for extensibility and behavior
There's a couple issues with the current approach:
- pkexec is an unusual elevation method, the standard is sudo
- it tries to elevate even in automated workflows
- the user may not want to automatically rerun as root, that might be
  badly behaved

Do some upfront checks instead, first to make sure it even makes sense
to try becoming root, and then to ask the user "do you really want
this". Also check for a couple common approaches to root elevation,
including doas.

Fixes #7345
Fixes #7809
2023-02-20 20:29:31 -05:00
Eli Schwartz 7884149bf5
minstall: when elevating to root, don't allow ninja to rerun
We just finished running rebuild_all, and then actually running
the install routine failed because of permission errors, so we magically
reran as root. But we should *know* that all prerequisite targets are up
to date already, we don't need to run it *again*.

Nevertheless, when running meson install directly we could end up
without --no-rebuild in the original argv. This meant that it wouldn't
be in the re-executed argv either. Add it on just in case -- repeating
it twice doesn't hurt anyway.
2023-02-20 19:54:38 -05:00
Charles Brunet 04f233a80d allow install script to run in dry-run mode 2023-02-14 10:50:10 -05:00
L. E. Segovia 7e5b0760ce minstall: make do_strip run with -Sx for macOS targets
This commit also adds some extra symbol noise to lib.c, in order to aid
detection of the debug information with nm.

Fixes #10943
2022-11-01 17:56:18 +02:00
Rosen Penev 26acf2152d minstall: handle extra error for selinuxenabled
Microsoft's WSL2 uses a Plan 9 filesystem, which returns IOError when file is missing.
2022-09-07 08:46:50 -04:00
Eli Schwartz f93886192e
minstall: do not trample install_mode by rpath fixer
install_mode can include the setuid bit, which has the special property
(mentioned in the set_mode logic for minstall itself) of needing to come
last, because it "will get wiped by chmod" (or at least chown).

In fact, it's not just chown that wipes setuid, but other changes as
well, such as the file contents. This is not an issue for install_data /
custom_target, but for compiled outputs, we run depfixer to handle
rpaths. This may or may not cause edits to the binary, depending on
whether we have a build rpath to wipe, or an install rpath to add. (We
also may run `strip`, but that external program already has its own mode
restoration logic.)

Fix this by switching the order of operations around, so that setting
the permissions happens last.

Fixes https://github.com/void-linux/void-packages/issues/38682
2022-08-18 07:57:51 -04:00
Xavier Claessens 2e3ac3eec0 minstall: Add more safety checks when unpickling installdata
When need to catch exceptions just like we do in coredata.load() to
print proper error message instead of backtrace when user mix meson
versions.

This happens frequently when user has a newer version of meson installed
in their HOME and then "sudo meson install" uses the system version of
meson.
2022-06-16 17:06:25 -04:00
Eli Schwartz a49cd00d64 treewide: various cleanups to move imports for mypy into typechecking blocks
Along the way, add __future__ annotations where lacking.
2022-06-10 09:15:48 -04:00
Marco Trevisan (Treviño) b0d300e788 install_symlink: Handle $DESTDIR case for links with absolute path
In case a link is pointing_to an absolute path and we are using $DESTDIR
we fail in case the target is missing.

This is incorrect because we may need to use an absolute path to an
already installed file that is in $DESTDIR.

So if an absolute target is not existing, check if we have such file in
$DESTDIR before failing for real.
2022-03-24 15:26:12 -04:00
Xavier Claessens eafb8a8e10 install: Add --strip option 2022-03-09 10:38:28 -05:00
Xavier Claessens 01e92dc543 Fix default install tag for shared lib symlinks
Versioned shared libraries should have .so file in devel, .so.1 and
.so.1.2.3 in runtime.

Fixes: #9811
2022-03-07 09:27:02 -05:00
Xavier Claessens 6fafeb13b3 devenv: Source bash completion scripts 2022-02-28 09:03:27 -05:00
Eli Schwartz 0b431a6b4a
fix missing f-string preventing variable formatting
Detected by flake8 which reported that `e` was an unused variable.
2022-02-16 18:19:13 -05:00
Eli Schwartz ab441e78b5
minstall: raise explicit errors, by using MesonException
RuntimeError is way too generic when we have an explicit class for
"Meson reports to the user, something went wrong".

Moreover we now tell people that generic exceptions are "Meson bugs and
should be reported", so our failure to do the technically correct thing
and report the right kind of exception means we get haunted by demons of
confusion. Specifically, people complain to us that Meson told them
"there is a bug in Meson" when their install fails due to meson.build or
build environment issues.
2022-02-09 16:33:34 -05:00
Eli Schwartz a45446b6e5
minstall: stop running ldconfig for the user
This was a nice idea in theory, but in practice it had various problems:

- On the only platform where ldconfig is expected to be run, it is
  really slow, even when the user uses a non-default prefix and ldconfig
  doesn't even have permission to run, nor can do anything useful due to
  ld.so.conf state
- On FreeBSD, it bricked the system: #9592
- On cross builds, it should not be used and broke installing, because
  ldconfig may not be runnable without binfmt + qemu: #9707
- it prints weird and confusing errors in the common "custom prefix"
  layout: #9241

Some of these problems can be or have been fixed. But it's a constant
source of footguns and complaints and for something that was originally
supposed to be just "it's the right thing to do anyway, so just do it
automatically" it is entirely too risky.

Ultimately I do not think there is justification for keeping this
feature in since it doesn't actually make everyone happy. Better for
users to decide whether they need this themselves.

This is anyways the case for cmake and autotools and generally any other
build system, so it should not be too intimidating...

Fixes #9721
2022-02-01 16:52:26 -05:00
Nirbheek Chauhan 1cda222a1a install: Setup VS env if we did that during setup
Otherwise we might not find a ninja that was picked up from the Visual
Studio installation.

```
$ meson setup _build
...
Activating VS 15.9.40
...
Found ninja-1.8.2 at "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.EXE"
$ meson compile -C _build
Activating VS 15.9.40
...
$ meson install -C _build
Can't find ninja, can't rebuild test.
```

Fixes https://github.com/mesonbuild/meson/issues/9774
2022-01-16 23:42:19 +05:30
Dylan Baker 05d61b4c66 install: Don't run ldconfig on cross builds
Even if we install without a DESTDIR set, we should never update
ldconfig when cross compiling.

Fixes #9707
2021-12-11 21:31:59 +02:00
Pablo Correa Gómez 4f882ff8ec add install_symlink function
Allows installing symlinks directly from meson, which can
become useful in multiple scenarios. Current main use is to
help moving forward #9557
2021-12-01 13:59:54 -05:00
Eli Schwartz 99d809b59d
fix BSD ldconfig handling (#9631)
For libraries installed to libdir, it's not expected to have rpath
hooked up. But for non-default libdirs, the path might not get searched
by default. `ldconfig -m <libdir>` is convenient here, as it will
programmatically add a new directory to search for shared libraries, so
the resulting installed programs work out of the box.

Include the dragonfly BSD platform name, which doesn't match the 'bsd'
catch-all pattern.
2021-11-28 18:32:10 +02:00
Eli Schwartz 858b114d5c minstall: do not run ldconfig on the *BSDs
They don't utilize a soname cache, so running ldconfig without arguments
is basically pointless -- and at least some of them are buggy: running
ldconfig with the verbose flag switches on "delete all directories from
the hints file, and recreate it using 0 command-line positional
arguments", which would soft-brick the system.

Fixes #9592
2021-11-25 23:19:57 +05:30
Eli Schwartz 8947352889 fix various flake8 whitespace errors 2021-10-27 09:51:52 -04:00
Christian Clauss a5020857f3 Fix typos discovered by codespell 2021-10-10 16:12:25 -04:00
Xavier Claessens 6b7d43ebe0 minstall: Ignore ldconfig errors when we did not install libraries
Fixes: #9241
2021-10-10 14:42:13 +03:00
Eli Schwartz 108bd996ee
add install_emptydir function
This replaces the absolute hack of using

```
install_subdir('nonexisting', install_dir: 'share')
```

which requires you to make sure you don't accidentally or deliberately
have a completely different directory with the same name in your source
tree that is full of files you don't want installed. It also avoids
splitting the name in two and listing them in the wrong order.

You can also set the install mode of each directory component by listing
them one at a time in order, and in fact create nested structures at
all.

Fixes #1604
Properly fixes #2904
2021-10-08 14:35:00 -04:00
Eli Schwartz 800c3462f0
condense lines 2021-10-04 17:01:03 -04:00
Eli Schwartz d06cc042eb
f-strings 2021-10-04 16:29:32 -04:00
Xavier Claessens 8c5aa031b5 Add install tags
Fixes: #7007.
2021-08-17 15:19:18 -04:00
Stéphane Cerveau 51cbb15335 minstall: restore_selinux_contexts: fix env test
To avoid extra env test, test destdir presence
upper in restore_selinux_contexts
2021-08-06 15:03:29 -04:00
Stéphane Cerveau 2c3a68bc30 install: apply ldconfig at the end of the install
On linux system ldconfig needs to be called to update
the ld.so.cache to be able to load libraries from
/usr/local/lib/x86_64-linux-gnu on debian based
distributions for example.
2021-08-06 15:03:29 -04:00
Stéphane Cerveau 7e8d5207a7 install: update restore_selinux to use popen_safe
Use Popen_safe to simplify the code.
2021-08-06 15:03:29 -04:00
Xavier Claessens 9da99e7a59 destdir: Allow relative to build directory
Meson already works like that, except in do_copydir() that requires
absolute destdir. Better explicitly support that instead of leaving it
undefined and unconsistent.
2021-08-04 09:43:41 -04:00
Paolo Bonzini b44a51d0fd resolve symlinks passed to -C
"meson setup" is resolving symlinks for the build directory in
validate_core_dirs.  For consistency with it, do the same when
the build directory is passed via -C to devenv, dist, init, install
and test.

This ensures for example that the path to test dependencies is
computed correctly in "meson test".

Fixes: #8765
2021-07-07 18:00:37 +02:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Dylan Baker 132420a059 minstall: make intentions clearer
The existing code works, but it probably doesn't do what the author
thought it would do. `(x or y or z) is not None` works by checking that
each of those things are *truthy* in turn, and returning the first
truthy value, which is compared against None. Using `all()` makes it
very clear that what you want to do is make sure that each value is not
None.
2021-06-22 09:13:41 -07:00
Dylan Baker 86da131129 mesonlib: Fix FileMode type annotations 2021-06-22 09:12:54 -07:00
Dylan Baker 5d3a60ae65 minstall: fix type annotation for add_arguments
This takes an `argparse.ArgumentParser` instance, not a namespace
2021-06-22 09:12:54 -07:00
Eli Schwartz 0ad870f3dc
minstall: always track meson-created directories
If a custom_target output is a directory, we install it as a directory,
not as a file. And, we try to track subdirectories which are created so
uninstalling works. But one directory creation did not go through
DirMaker, in the case where the output directory does not have any
further subdirectories.

Consolidate on makedirs, since I don't see much point in using os.mkdir
right here.
2021-03-18 20:30:13 -04:00
Peter Kjellerstedt 6226ac26ef minstall: Correctly set uid/gid of installed files
In commit caab4d3d, the uid and gid arguments passed to os.chown() by
set_chown() were accidentally swapped, causing files to end up with
incorrect owner/group if the owner and group are not the same.

Also update the documentation to better indicate which argument to
install_mode is which.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
2021-03-06 13:29:29 +02:00
Eli Schwartz 6a0fabc647
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04 17:16:11 -05:00
Xavier Claessens 2fabd4c7dc minstall: Add --skip-subprojects option
By default all subprojects are installed. If --skip-subprojects is given
with no value only the main project is installed. If --skip-subprojects
is given with a value, it should be a coma separated list of subprojects
to skip and all others will be installed.

Fixes: #2550.
2021-02-22 23:03:55 +02:00
Xℹ Ruoyao 3ed30cea6e Fix destdir detection for installation via polkit
In 0.57.0 installation via polkit won't work anymore. `destdir` is
defaulted to an empty string ('') instead of None.  But polkit
installation code incorrectly tests `destdir is None`.
2021-02-16 08:39:29 -05:00
Xavier Claessens 95c0790711 minstall: Add --dry-run option
Closes: #1281
2021-02-04 16:24:38 +00:00
Xavier Claessens 6c6b5d77d6 add_install_script: add skip_if_destdir kwarg
It is common, at least in GNOME projects, to have scripts that must be
run only in the final destination, to update system icon cache, etc.
Skipping them from Meson ensures we can properly log that they have not
been run instead of relying on such scripts to to it (they don't
always).
2021-01-30 21:28:21 +00:00
Xavier Claessens c491d48b9d minstall: Add --destdir command line option 2021-01-30 21:28:21 +00:00
Xavier Claessens 0626465ea8 Fix executable as script on Windows
On Windows this would fail because of missing DLL:
```
mylib = library(...)
exe = executable(..., link_with: mylib)
meson.add_install_script(exe)
```

The reason is on Windows we cannot rely on rpath to find libraries from
build directory, they are searched in $PATH. We already have all that
mechanism in place for custom_target() using ExecutableSerialisation
class, so reuse it for install/dist/postconf scripts too.

This has bonus side effect to also use exe_wrapper for those scripts.

Fixes: #8187
2021-01-30 09:51:06 +00:00
Dylan Baker caab4d3d92 minstall: Fix signature of monkeypatched os.chown
this also clears up the last of the mypy problems in minstall, yay!
2021-01-13 13:32:48 -08:00