Commit Graph

61 Commits

Author SHA1 Message Date
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
Charles Brunet a843a99743
mypy: replace fchmod by chmod
The former is unix-only, which complains when running on the Windows
platform -- even though this code is in a unix-specific branch.

But per the docs:

> As of Python 3.3, this is equivalent to os.chmod(fd, mode).

So we can just use the identical function that is available in more
places.
2023-09-26 18:13:31 -04:00
Eli Schwartz 90ce084144
treewide: automatic rewriting of all comment-style type annotations
Performed using https://github.com/ilevkivskyi/com2ann

This has no actual effect on the codebase as type checkers (still)
support both and negligible effect on runtime performance since
__future__ annotations ameliorates that. Technically, the bytecode would
be bigger for non function-local annotations, of which we have many
either way.

So if it doesn't really matter, why do a large-scale refactor? Simple:
because people keep wanting to, but it's getting nickle-and-dimed. If
we're going to do this we might as well do it consistently in one shot,
using tooling that guarantees repeatability and correctness.

Repeat with:

```
com2ann mesonbuild/
```
2023-08-11 13:41:03 -04: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
Eli Schwartz 680b5ff819
treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Benjamin Gilbert 35e230e48c depfixer: silence fix_jar() and make it do something
fix_jar() tries to remove an existing Class-Path entry from the jar
manifest by postprocessing the manifest and passing it to `jar -um`.
However, `jar -um` can only add/replace manifest entries, not remove
them, and it also complains loudly when replacing an entry:

    Dec 13, 2022 7:11:19 PM java.util.jar.Attributes read
    WARNING: Duplicate name in Manifest: Manifest-Version.
    Ensure that the manifest does not have duplicate entries, and
    that blank lines separate individual sections in both your
    manifest and in the META-INF/MANIFEST.MF entry in the jar file.

Thus fix_jar() produces one such warning for each entry in the manifest
and accomplishes nothing else.

Use jar -uM instead.  This completely removes the manifest from the jar
and allows adding it back as a normal zip member, fixing fix_jar() and
avoiding the warnings.

Fixes: https://github.com/mesonbuild/meson/issues/10491
Fixes: c70a051e93 ("java: remove manifest classpath from installed jar")
2022-12-14 15:37:59 -05:00
Benjamin Gilbert 51c889ddbc depfixer: don't extract MANIFEST.MF verbosely
Avoids non-actionable output when installing a jar:

    inflated: META-INF/MANIFEST.MF

Fixes: c70a051e93 ("java: remove manifest classpath from installed jar")
2022-12-13 21:41:50 -05:00
Dylan Baker 67da2ad0fb
pylint: enable simplifiable-if-statement 2022-11-30 07:01:22 -05:00
Eli Schwartz 97ec20e901
depfixer: handle darwin dependencies with non-ASCII paths
I assume there's no real reason this cannot happen, perhaps if the meson
source directory has one. So we should use Popen_safe for safety
reasons.
2022-11-03 17:51:35 -04:00
Dylan Baker f5283dd63f pylint: enable global-statement
This does force a number of uses of `# pylint: disable` comments, but it
also finds a couple of useless global uses and one place (in the
previous commit) that an easy refactor removes the use of global. Global
is a code smell, so forcing adding a comment to disable helps force
developers to really consider if what they're doing is a good idea.
2022-09-22 18:17:43 -04:00
Dylan Baker 188c552dcf pylint: enable use-maxsplit-arg
This finds a bunch of places where we can do more efficient string
splitting.
2022-09-19 20:57:52 -04:00
Zbigniew Jędrzejewski-Szmek 7a5eb6f9aa depfixer: always print the file name in messages
The messages are not useful unless we know what file they are about.
2021-11-09 10:50:59 +01:00
Zbigniew Jędrzejewski-Szmek c2f1d91b8a depfixer: convert unused printing code to debugging functions
When installing with 'meson install --quiet' I'd get the following output:
This file does not have an rpath.
This file does not have a runpath.

(It turns out that of the couple hundred of binaries that are installed,
this message was generated for /usr/lib/systemd/boot/efi/linuxx64.elf.stub.)

There doesn't seem to be any good reason for this output by default. But those
functions can still be used for debugging. Under a debugger, returning the
string is just as useful as printing it, but more flexible. So let's suppress
printing of anything by default, but keep the extractor functions.

The code was somewhat inconsistent wrt. to when .decode() was done. But it
seems that we'll get can expect a decodable text string in all cases, so
just call .decode() everywhere, because it's nicer to print decoded strings.
2021-11-09 10:50:59 +01:00
Zbigniew Jędrzejewski-Szmek da522efc93 depfixer: f-strings 2021-11-09 10:47:21 +01:00
Christian Clauss a5020857f3 Fix typos discovered by codespell 2021-10-10 16:12:25 -04:00
Dylan Baker 4d7031437c pylint: turn on superflous-parens
We have a lot of these. Some of them are harmless, if unidiomatic, such
as `if (condition)`, others are potentially dangerous `assert(...)`, as
`assert(condtion)` works as expected, but `assert(condition, message)`
will result in an assertion that never triggers, as what you're actually
asserting is `bool(tuple[2])`, which will always be true.
2021-08-31 16:28:54 -04:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Hemmo Nieminen 01c6b50a77 depfixer: temporarily modify file permissions
If the installed files don't have suitable file permissions depfixer
will fail to process it. Temporarily lax file permissions to work around
this.
2021-03-24 17:51:57 +02:00
Dylan Baker a4e1be4e5b scripts/depfixer: make rpaths_dirs_to_remove a set
It's only used for doing an `if x in container` check, which will be
faster with a set, and the only caller already has a set, so avoid
we can avoid a type conversion as well.
2021-01-13 13:30:06 -08:00
Alan Coopersmith d6ef5b2024 depfixer: split new rpath into multiple entries for dedup comparisons
Fixes: #8115

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-12-22 20:21:31 +00:00
Daniel Mensinger e681235e5f
typing: fix code review 2020-09-08 20:15:58 +02:00
Daniel Mensinger 23818fc5a3
typing: more fixes 2020-09-08 20:15:58 +02:00
Daniel Mensinger a4f4379c44
typing: fully annotate scripts 2020-09-08 20:15:56 +02:00
Jussi Pakkanen 7d0393342a Dedup final install rpath. 2020-08-30 18:58:11 +03:00
Jussi Pakkanen 91c5b37970 Better log message on rpath error. 2020-08-07 21:13:46 -04:00
Dan Kegel d7235c5905 Let .pc files specify rpath.
Fixes #4027
2020-05-16 20:25:58 +00:00
Nirbheek Chauhan 2860bd0385 depfixer: Ignore more extensions that can't need RPATH fixes
Generated headers, PDB files, import libraries, etc.

Speed-up in gst-build on Windows:

```
meson install
before: 5.4 seconds
after:  5.1 seconds

meson install --only-changed
before: 2.7 seconds
after:  1.6 seconds
```
2020-02-17 23:58:20 +05:30
Nirbheek Chauhan 561a284c51 depfixer: Cache searching of install_name_tool
This gives a significant speedup in large projects such as gst-build
since now we only search for the tool once. Speed-up on Windows:

```
meson install:
before: 15.3 seconds
after:   5.4 seconds

meson install --only-changed:
before: 11.6 seconds
after:   2.7 seconds
```
2020-02-17 23:58:20 +05:30
Binh Nguyen f6758f2434 Prevent install_name_tool to run on EXE when cross compile on OSX 2019-11-12 20:39:23 +02:00
Michael Hirsch, Ph.D 7aecfb1540 remove unreachable code 2019-08-02 14:31:22 +03:00
Daniel Mensinger 3581839f4c
Fix unused variables warnings 2019-04-29 12:22:50 +02:00
Daniel Mensinger bf98ffca9e
Fix blind exceptions 2019-04-29 12:16:06 +02:00
Marvin Scholz fc3e2f5ad0 depfixer: Do not try to fix rpaths of dlls 2018-10-25 19:30:02 +03:00
David Seifert 3a8911a07f Do not try to remove duplicate RPATH entries on macOS 2018-10-14 23:50:52 +03:00
Niclas Moeslund Overby c70a051e93 java: remove manifest classpath from installed jar 2018-07-03 22:12:17 +02:00
Nirbheek Chauhan 96b7fdb723 macos: Rewrite install_name for dependent built libraries on install
On macOS, we set the install_name for built libraries to
@rpath/libfoo.dylib, and when linking to the library, we set the RPATH
to its path in the build directory. This allows all built binaries to
be run as-is from the build directory (uninstalled).

However, on install, we have to strip all the RPATHs because they
point to the build directory, and we change the install_name of all
built libraries to the absolute path to the library. This causes the
install name in binaries to be out of date.

We now change that install name to point to the absolute path to each
built library after installation.

Fixes https://github.com/mesonbuild/meson/issues/3038
Fixes https://github.com/mesonbuild/meson/issues/3077

With this, the default workflow on macOS matches what everyone seems
to do, including Autotools and CMake. The next step is providing a way
for build files to override the install_name that is used after
installation for use with, f.ex., private libraries when combined with
the install_rpath: kwarg on targets.
2018-06-18 06:33:23 +00:00
Nirbheek Chauhan 69f817b0e3 depfixer: Rewrite install_name for dylibs on install
The install name is used by consumers of the library to find the
library at runtime. If it's @rpath/libfoo.dylib, all consumers must
manually add the library path to RPATH, which is not what people
expect.

Almost everyone sets the library install name as the full path to the
library, and this is done at install time with install_name_tool.
2018-06-18 06:33:23 +00:00
Nirbheek Chauhan 9f616e98bf depfixer: Run install_name_tool only once while deleting rpaths 2018-05-24 14:38:28 +00:00
Nirbheek Chauhan a6c9f98c57 depfixer: We no longer run this as a script 2018-05-24 14:38:28 +00:00
Jussi Pakkanen d3ff7d44ab Made depfixer more robust on OSX. Closes #3493. 2018-05-01 12:10:25 +00:00
Jussi Pakkanen 7c37ca15f3 🤦🤦🤦 2018-04-14 22:41:24 +03:00
Jussi Pakkanen aed11affd3 Update depfixer to fix rpaths also on OSX. 2018-04-08 19:48:31 +03:00
Jussi Pakkanen db34a3a701 Close files reliably. 2017-07-18 00:33:08 +02:00
Jussi Pakkanen 1617634214 Use sys.exit rather than plain exit. 2017-07-16 12:05:09 +03:00
Alistair Thomas a195b78c8d Whitespace tweaks to reduce Flake8 warnings 2017-05-29 19:32:47 +03:00
Peter Hutterer ca924451ac Use American English: behaviour -> behavior 2017-05-04 22:09:27 +03:00
Dylan Baker a8173630ea Don't use len() to test emptiness vs not emptiness
Meson has a common pattern of using 'if len(foo) == 0:' or
'if len(foo) != 0:', however, this is a common anti-pattern in python.
Instead tests for emptiness/non-emptiness should be done with a simple
'if foo:' or 'if not foo:'

Consider the following:
>>> import timeit
>>> timeit.timeit('if len([]) == 0: pass')
0.10730923599840025
>>> timeit.timeit('if not []: pass')
0.030033907998586074
>>> timeit.timeit('if len(['a', 'b', 'c', 'd']) == 0: pass')
0.1154778649979562
>>> timeit.timeit("if not ['a', 'b', 'c', 'd']: pass")
0.08259823200205574
>>> timeit.timeit('if len("") == 0: pass')
0.089759664999292
>>> timeit.timeit('if not "": pass')
0.02340641999762738
>>> timeit.timeit('if len("foo") == 0: pass')
0.08848102600313723
>>> timeit.timeit('if not "foo": pass')
0.04032287199879647

And for the one additional case of 'if len(foo.strip()) == 0', which can
be replaced with 'if not foo.isspace()'
>>> timeit.timeit('if len("   ".strip()) == 0: pass')
0.15294511600222904
>>> timeit.timeit('if "   ".isspace(): pass')
0.09413968399894657
>>> timeit.timeit('if len("   abc".strip()) == 0: pass')
0.2023209120015963
>>> timeit.timeit('if "   abc".isspace(): pass')
0.09571301700270851

In other words, it's always a win to not use len(), when you don't
actually want to check the length.
2017-05-02 21:57:26 +03:00
Jussi Pakkanen 0e47e74a77 Do not obliterate old rpath because it might be used due to read only data sharing. Closes #1619. 2017-04-17 12:48:54 +03:00
Mike Sinkovsky 969be1f679 cleanup: Remove redundant parentheses 2017-01-18 21:22:47 +02:00
Mike Sinkovsky 079e43f70b fix 'unreachable code' warnings 2017-01-03 13:34:39 -05:00