47 Commits

Author SHA1 Message Date
Dylan Baker
379165e0c6 compilers: refactor sanity checking code, again
The goal is to reduce code duplication, and allow each language to
implement as little as possible to get good checking. The main
motivation is that half of the checks are fragile, as they add the work
directory to the paths of the generated files they want to use. This
works when run inside mesonmain because we always have an absolute build
directory, but when put into run_project_tests.py it doesn't work
because that gives a relative build directory.

Additionally, this fixes the implementation of sanity checking for
transpiled languages like Vala and Cython, which previously didn't test
the output of their compilers at all, but re-ran the C compiler test for
itself.
2026-02-03 13:34:06 -08:00
Dylan Baker
8938f5efad compilers: Remove Environment parameter from Compiler.sanity_check 2025-11-19 10:48:48 -08:00
Dylan Baker
fc97e4f395 compilers: Remove Environment parameter from Compiler.run_sanity_check 2025-11-19 10:48:48 -08:00
Dylan Baker
a6c4a4d7e8 compilers: Pass Environment instead of MachineInfo
We end up needing it everywhere, so just store it. This patch is huge
already, so it's just the conversion to passing Environment, more
cleanups to come.
2025-11-19 10:48:48 -08:00
Dylan Baker
a6af0ad503 Revert "compilers: refactor sanity checking code"
This reverts commit 806289a5d2.
2025-10-06 10:22:41 -07:00
Dylan Baker
806289a5d2 compilers: refactor sanity checking code
The goal is to reduce code duplication, and allow each language to
implement as little as possible to get good checking. The main
motivation is that half of the checks are fragile, as they add the work
directory to the paths of the generated files they want to use. This
works when run inside mesonmain because we always have an absolute build
directory, but when put into run_project_tests.py it doesn't work
because that gives a relative build directory.
2025-10-06 09:03:07 -07:00
Paolo Bonzini
8e564f16ae compilers: introduce common helper for sanity checks
Avoid reinventing the wheel and instead use a single helper, taking care
of logging and cross compilation.

Fixes: #14373
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-30 00:14:44 +03:00
Charles Brunet
4761e4cad9 Remove get_buildtype_args function
This is a first step to make `buildtype` a true alias of `debug` and
`optimization` options.

See #10808.

Relates to:
- #11645
- #12096
- #5920
- #5814
- #8220
- #8493
- #9540
- #10487
- #12265
- #8308
- #8214
- #7194
- #11732
2023-12-23 13:32:49 +02:00
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
Eli Schwartz
39ecfc2d54 compilers: drop dead code
no_warn_args is unused. Its only purpose was to implement automatic
hiding of UB in transpiled code, and it was not used at all in languages
other than C/C++ -- specifically when the C/C++ source files were
created by transpiling from vala or cython.
2023-12-05 19:52:23 -05:00
Alan Brooks
c1ac252f4f fix bug where all java builds & tests fail to run SanityCheck on JDK11
Needed a classpath set in the current working directory.
This was on a Zulu build of OpenJDK 11.0.17 on a macOS ARM machine.

The errors folks might encounter:
Error: Could not find or load main class SanityCheck
Caused by: java.lang.ClassNotFoundException: SanityCheck
2023-09-25 18:27:24 +03:00
HiPhish
439a61affa Change "can not" to "cannot" throughout project
The word "cannot" expresses inability to do something whereas "can not"
expresses the ability to refrain from doing something.
2023-04-11 17:10:01 +03:00
Dylan Baker
2d349eae8c pylint: enable the set_membership plugin
Which adds the `use-set-for-membership` check. It's generally faster in
python to use a set with the `in` keyword, because it's a hash check
instead of a linear walk, this is especially true with strings, where
it's actually O(n^2), one loop over the container, and an inner loop of
the strings (as string comparison works by checking that `a[n] == b[n]`,
in a loop).

Also, I'm tired of complaining about this in reviews, let the tools do
it for me :)
2022-11-30 16:23:29 -05:00
Xavier Claessens
2961adb8c8 Compilers: Keep ccache and exelist separated
Only combine them in the Compiler base class, this will make easier to
run compiler without ccache.
2022-10-25 17:24:56 -04:00
Tristan Partin
5a7427cebb Fix mismatched param names between Compiler and BasicLinkerIsCompilerMixin 2022-10-24 21:43:25 +03:00
Tristan Partin
e05a88835a Use f-strings in JavaCompiler 2022-10-24 21:43:25 +03:00
Tristan Partin
e87259f4a7 Add missing compiler functions to JavaCompiler
Fixes #2571
2022-10-24 21:43:25 +03:00
Eli Schwartz
0703ee0aef move various unused typing-only imports into type-checking blocks 2022-07-03 14:11:31 -04:00
Dylan Baker
1209b8820b compilers: push the compiler id to a class variable
It really is a per class value, and shouldn't be set per instance. It
also allows us to get rid of useless constructors, including those
breaking mypy
2022-01-10 15:53:26 -05:00
Dylan Baker
f48d75dcae compilers/java: Add no_warn_args and debug_args methods 2021-11-08 23:33:14 +02:00
Tristan Partin
be92e37837 Add Java module
The Java module will serve as a source for easing Java development
within Meson. Currently it only supports generating native header files.
2021-08-22 07:57:29 -07:00
Daniel Mensinger
3e396b3782 fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Dylan Baker
135f5d5838 compilers: make get_optimization_args abstract 2020-10-01 15:06:10 -07:00
Dylan Baker
3fc37fc13e compilers/java: Add type annotations 2020-10-01 15:05:01 -07:00
Dylan Baker
d3a059b55f compilers/cuda: make type safe 2020-10-01 15:05:00 -07:00
Dylan Baker
e7f0890cb9 compilers: move get_dependency_gen_args to base Compiler
So that every subclass doesn't have to reimplement it. Especially since
the Gnu implementation moved out of the CCompiler and into the
GnuLikeCompiler mixin
2020-10-01 15:05:00 -07:00
Dylan Baker
1513aa437d compilers: move split_shlib_to_parts to the base compiler
Only the GnuLikeCompiler overrides this, and it's implemented multiple
places
2020-10-01 15:05:00 -07:00
Dylan Baker
2c0fbe161d compilers: make is_cross part of the base Compiler class
Every class needs to set this, so it should be part of the base. For
classes that require is_cross, the positional argument remains in their
signature. For those that don't, they just allow the base class to set
their value to it's default of False.
2020-09-24 12:14:13 -07:00
Dylan Baker
98416e7f75 compilers: put name_string method in base compiler
Every language had the exact same implementation
2020-09-24 12:14:13 -07:00
Daniel Mensinger
09b53c534f types: import typing as T (fixes #6333) 2020-01-08 15:28:17 +01:00
Dylan Baker
ee6e249f65 compilers: move language attribute to the class level
We know that if a compiler class inherits CCompiler it's language will
be C, so doing this at the class level makes more sense.
2019-12-12 09:35:30 -08:00
Dylan Baker
0c22798b1a compilers: replace CompilerType with MachineInfo
Now that the linkers are split out of the compilers this enum is
only used to know what platform we're compiling for. Which is
what the MachineInfo class is for
2019-10-07 12:08:20 -07:00
Dylan Baker
06dcbd50ee compilers: Dispatch to dynamic linker class
Most of the cuda code is from Olexa Bilaniuk.
Most of the PGI code is from Michael Hirsc
2019-08-14 13:13:23 -07:00
John Ericson
07777e15d4 Purge is_cross and friends without changing user interfaces
In most cases instead pass `for_machine`, the name of the relevant
machines (what compilers target, what targets run on, etc). This allows
us to use the cross code path in the native case, deduplicating the
code.

As one can see, environment got bigger as more information is kept
structured there, while ninjabackend got a smaller. Overall a few amount
of lines were added, but the hope is what's added is a lot simpler than
what's removed.
2019-06-09 13:13:25 -04:00
John Ericson
6dbe33d949 C# and Java compilers should have is_cross = False
All compilers should define this attribute. Probably should change base
class to require this.
2019-02-01 13:22:01 -05:00
Daniel Mensinger
ca808a0702 More os.pathsep 2019-01-06 12:19:33 +01:00
Daniel Mensinger
477b69b505 Use os.pathsep 2019-01-06 12:19:33 +01:00
Daniel Mensinger
681532452c Handle java correct 2019-01-06 12:19:33 +01:00
Daniel Mensinger
9eca2e46a0 Added more compiler option support 2019-01-06 12:19:33 +01:00
Daniel Mensinger
9742927903 Absolute path generation refactoring 2019-01-06 12:19:32 +01:00
Daniel Mensinger
c4eb5c79fe Added unit test 2019-01-06 12:19:28 +01:00
Daniel Mensinger
71d17b44e4 Fixed list_target_files and list_targets 2019-01-06 12:19:28 +01: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
ed701b5cb0 Revert "Add macOS linker versioning information"
This reverts commit fa6ca16054.

Closes https://github.com/mesonbuild/meson/issues/3550
2018-05-09 23:11:15 +02:00
Tom Schoonjans
fa6ca16054 Add macOS linker versioning information
This patch exploits the information residing in ltversion to set the
-compatibility_version and -current_version flags that are passed to the
linker on macOS.
2018-04-16 22:26:16 +03:00
Jussi Pakkanen
2269b7f60b Add build_rpath as new property allowing people to specify rpath entries that are used in the build tree but will be removed on install. 2017-07-21 19:40:54 +03:00
Alistair Thomas
117f4ab8b5 Split out languages from compilers.py 2017-06-23 00:42:41 +01:00