Commit Graph

125 Commits

Author SHA1 Message Date
Daan De Meyer 028abfe87c minstall: Don't treat symlinks to directories as directories in do_copydir()
As documented in https://docs.python.org/3/library/os.html#os.walk:

> dirnames is a list of the names of the subdirectories in dirpath
> (including symlinks to directories, and excluding '.' and '..')

So currently, we treat any symlink to a directory as a directory instead
of as a symlink. In practice, this means symlinks to directories are
installed as empty directories instead of as symlinks.

Let's make sure the symlinks are kept intact by checking for symlinks
when we iterate over the directory names and treating any symlinks we
find as files instead of as symlinks.
2025-04-14 21:04:15 +03:00
Dylan Baker 4fa5292545 coredata: replace get_option with optstore.get_value_for
This is an old method, that is now just a wrapper around the OptionStore
method, that doesn't add any value. It's also an option related method
attached to the CoreData instead of the OptionStore, so useless and a
layering violation.
2025-03-10 14:14:25 -04:00
Dylan Baker 0e6e68786c minstall: help mypy out with our chown overriding
This is an annoying issue to look at, because shutil.chown has (for our
purposes) three signatures:
```python
chown(path: int | AnyPathLike, uid: int | str, group: None = None) -> None: ...
chown(path: int | AnyPathLike, uid: None, group: int | str) -> None: ...
chown(path: int | AnyPathLike, uid: int | str, group: int | str) -> None: ...
```

This is a really difficult thing to guarantee from our code. We more or
less depend on being able to pass two parameters of `None | int | str`,
and it working. In our only caller we do ensure that at least one of the
variables is not None, but convincing mypy of this is more work than
it's worth.

This will show up in our CI only for python >= 3.13. An updated typshed
will make this show up for earlier versions, however. Pyright (which is
used by the VSCode Python extension) will spot this for earlier
versions. I have changed the code in such a way to make our CI turn
green.
2025-02-03 21:49:53 -08:00
rusty-snake c66a89fdca Add run0 as a way to raise privileges 2025-01-07 21:40:14 +02:00
Andreas Karlsson b8cdd06af5 Consistently list short options first for install
Other commands already list the short options first plus -h is always
listed before --help.
2024-11-02 19:55:09 -04:00
Andreas Karlsson 2d40813d42 Add -q as alternative to --quiet for meson install
Since "meson test" already has both -q and --quiet it makes a lot of
sense to add the short option to "meson install" too for reasons of
symmetry.
2024-11-02 19:55:09 -04:00
Dylan Baker efa85c5b64 minstall: fix bug link 2024-10-01 09:58:16 -07:00
Eli Schwartz 02e4138e10
Revert "minstall: update symlink install message presentation"
This reverts commit 3587786a3c.

No unicode, thanks.

Fixes #13519
2024-08-06 01:55:22 -04:00
James Knight 3587786a3c minstall: update symlink install message presentation
Updating the log message generated when installing a symbolic link. The
new message format may be a bit more clear on the link being created.

Signed-off-by: James Knight <james.d.knight@live.com>
2024-08-04 16:15:34 +03:00
Jussi Pakkanen 0d7bb776e2 Move OptionKey in the option source file. 2024-07-11 11:53:39 +03:00
Eli Schwartz 8fe8b1d829
minstall: fix symlink handling on python 3.13
We passed a wrapper hack for shutil.chown because some functionality
wasn't available in the stdlib. It was added in python 3.13 beta1, so
the tests fail when we actually test symlink handling.

Fixes failure to run test_install_subdir_symlinks_with_default_umask_and_mode
on python 3.13.
2024-06-23 16:15:52 -04:00
Akihiko Odaki ed1a1d567a Print a proper sentence when reporting script failure 2024-02-11 18:28:53 +05:30
Dylan Baker e991c4d454 Use SPDX-License-Identifier consistently
This replaces all of the Apache blurbs at the start of each file with an
`# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing
uses to be consistent in capitalization, and to be placed above any
copyright notices.

This removes nearly 3000 lines of boilerplate from the project (only
python files), which no developer cares to look at.

SPDX is in common use, particularly in the Linux kernel, and is the
recommended format for Meson's own `project(license: )` field
2023-12-13 15:19:21 -05:00
Aditya Vidyadhar Kamath f4d19db25e
Use target.aix_so_archive to decide to archive shared library in AIX
Previously, AIX support was updated to archive shared libraries per AIX
platform conventions, which expect .a files that contain .so files. This
is usually correct, but an edge case occurs for loadable plugins, e.g.
what meson creates for `shared_module()`. A notable example is python
extensions (SciPy, for example).

These should *not* be archived, because the .so file itself needs to be
loaded as a plugin. For example, SciPy fails to import in the python
interpreter.

Handle this by differentiating between plugins and regular libraries,
and only archiving when safe to do so.

Fixes #12219
2023-10-31 19:18:17 -04:00
Luke Elliott ce691f8c98 Add comments suggesting to keep shell completion scripts up-to-date near cmd line argument code 2023-11-01 00:06:19 +02:00
Arsen Arsenović 0af126fec7 install_{data,headers,subdir}: implement follow_symlinks
This permits users who rely on following symlinks to stay on the old
default of following them.
2023-09-13 21:44:40 -04:00
Peter Hutterer 1bb29b1b32 minstall: move the "Installing foo to bar" message up
Move this message up before we attempt to change anything in the file
system (in this case creating the directory structure).
If an error occurs it will thus occur immediately after the message,
allowing us to debug what failed to install.
2023-08-24 21:29:10 -04:00
Eli Schwartz 7afc69254d
fix implicit_reexport issues and enforce them going forward
This detects cases where module A imports a function from B, and C
imports that same function from A instead of B. It's not part of the API
contract of A, and causes innocent refactoring to break things.
2023-07-19 18:31:37 -04:00
Aditya Kamath 8946bc05f7
Archive shared library in AIX (#11850)
* Archive shared library in AIX

This code change to ensure we archive shared libraries in AIX.

The things we do are:
Archive shared library
Install archived shared library
Build all must build the archived shared library
blibpath must have the archived shared library dependency.

* Archive shared library in AIX.

Made changes as per the review comments given in the first
PR request.

They are:-
Use self.environment.machines[t.for_machine].is_aix()
Remove trial spaces
Use of val instead of internal
Changed comments wherever requested

* Space after octothorpe

* Fixed failed test case causing build break during install section

* Moved AIX specific code to AIXDynamicLinker from backend

* Fix indentation, trailing spaces, add type annotations and Linux/macOS build break

* Remove some more trailing space issues

* Fixed the wrong return type in linkers
2023-06-27 22:02:32 +03:00
Eli Schwartz 6823cabb83
extend install scripts to allow specific directory variable exports
This is useful for internal scripts that want to know about something
other than MESON_INSTALL_PREFIX and MESON_INSTALL_DESTDIR_PREFIX, which
is very specific to the prefix.
2023-05-02 19:28:35 -04:00
Eli Schwartz 3bc2236c59
minstall: work around broken environments with missing UIDs
Running some container-like mechanisms such as chroot(1) from sudo, can
result in a new isolated environment where the environment variables
exist but no users exist. From there, a build is performed as root but
installation fails when we try to look up the passwd database entry for
the user outside of the chroot.

Proper container mechanisms such as systemd-nspawn, and even improper
ones like docker, sanitize this and ensure those stale environment
variables don't exist anymore. But chroot is very low-level.

Avoid crashing when this happens.

Fixes #11662
2023-04-14 15:13:12 -04:00
Eli Schwartz 9a77c45e41
minstall: do not drop privileges if msetup also ran under sudo
A user might run `sudo somewrapper` to build and install something with
meson, and it is not actually possible to drop privileges and build,
since the build directory is also owned by root.

A common case of this is `sudo pip install` for projects using
meson-python or other python build-backends that wrap around meson.

Fixes #11665
2023-04-14 15:12:37 -04:00
Daniele Nicolodi 1bc3d91112 minstall: Fix install_subdir() excludes with path separators on Win
The paths in meson.build use / as path separator, however, the paths
constructed during the directory structure walk use native path
separators, thus the path never compare equal to the excluded ones.
Normalize the exclusion paths before the comparison.
2023-04-14 21:37:52 +03:00
Josh Soref cf9fd56bc9 fix various spelling issues
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-11 19:21:05 -04:00
Xavier Claessens b30cd5d2d5 Make --vsenv a readonly builtin option
We need to remember its value when reconfiguring, but the Build object
is not reused, only coredata is.

This also makes CLI more consistent by allowing `-Dvsenv=true` syntax.

Fixes: #11309
2023-03-29 09:33:41 -04:00
Eli Schwartz a024d75e15
backends: add a new "none" backend
It can only be used for projects that don't have any rules at all, i.e.
they are purely using Meson to:

- configure files
- run (script?) tests
- install files that exist by the end of the setup stage

This can be useful e.g. for Meson itself, a pure python project.
2023-03-20 17:22:50 -04:00
Dylan Baker 7c2ac4f8fe utils: fix annotation of pickle_load
It's actually Generic, and we should use Generic annotations to get the
correct result. This means that we don't have to assert or cast the
return type, because mypy just knowns
2023-03-09 19:03:44 -05:00
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