Commit Graph

270 Commits

Author SHA1 Message Date
Daniel Mensinger ca40dda146 cmake: Add rule relaxations for CMake subprojects
fixes #10566
2022-08-10 22:24:02 -04:00
Dylan Baker 84d06a8f4b interpreter: Add return type to func_dependency 2022-07-17 12:58:17 -04:00
Eli Schwartz e7d87b6f58
implement the new preserve_path kwarg for install_data too
Primarily interesting to me because it is then available for the python
module's install_sources method.

Based on the new feature in install_headers.
2022-07-08 01:58:23 -04:00
Eli Schwartz b89451847a
fix incorrect type annotation
In my attempts at actually using this, I discovered that no, it actually
does take None.
2022-07-08 01:56:14 -04:00
Ralf Gommers 17936686d4 Improve error message for `include_directories(abs_path_intree)`
This error message was quite confusing when triggered by
use of an absolute path to the include dir of an external dependency
(numpy in my case). Changing that to a relative dir also isn't
a solution, because Meson will *not* do the "busywork to make paths
work" that the error message says it will.
2022-07-06 15:17:01 -04:00
Eli Schwartz 47426f3663
migrate declare_dependency to typed_kwargs 2022-06-17 14:33:02 -04:00
Eli Schwartz ca52dac38b
refactor logic for parsing dependency variables into type_checking module
We will momentarily use this to implement typed_kwargs, but not for all
usage sites.
2022-06-17 14:33:02 -04:00
Hemmo Nieminen b49b9f52b2 interpreter: fix a subproject check with symlinks
The check for whether or not a file is allowed to be accessed from a
subproject fails if the subproject is accessed via a symlink. Use the
absolute path of the subproject without resolving symlinks to fix the
check.

Extend unit test 106 to check for this in the future.
2022-06-17 14:18:05 -04:00
Xavier Claessens d85a9733e6 Fix crash when a reconfigure adds a new subproject
When a subproject is disabled on the initial configuration we should not
add it into self.coredata.initialized_subprojects because that will
prevent calling self.coredata.init_builtins() on a reconfigure if the
subproject gets enabled.

Fixes: #10225.
2022-06-14 16:01:20 -04:00
Eli Schwartz f380862284
add Feature checks for install_subdir creating an empty directory
Most importantly, tell people it's broken and to stop using it for
0.62.0
2022-06-10 17:56:02 -04:00
Dylan Baker 27bde338fb interpreter: add missing type annotation 2022-06-01 22:49:10 -04:00
Dylan Baker 2e5a2f6a48 interpreter: add location to a FeatureNew call 2022-06-01 22:49:10 -04:00
Dylan Baker 618b187f70 interpreter: use a shared KwargInfo for install_dir
CustomTarget allows multiple install dirs, while basically everything
else allows only one. So this provides a shared instance for that.
2022-06-01 22:49:10 -04:00
Vili Väinölä 18e2f8b2b3 Fix sandbox violation when using subproject as a symlink
Fix "Tried to grab file outside current (sub)project" error when subproject exists within
a source tree but it is used through a symlink. Using subprojects as symlinks is very useful
feature when migrating an existing codebase to meson that all sources do not need to be
immediately moved to subprojects folder.
2022-06-01 12:32:53 -07:00
Eli Schwartz 52d01dbf38
rename a badly named KwargInfo
CT_OUTPUT_KW is the same OUTPUT_KW we use in lots of places. The most
distinctive thing about it is not that it's part of custom_target
(basically any other function that uses such a kwarg follows the same
rules due to using CustomTarget under the hood), but the fact that it
takes multiple outputs.
2022-05-31 17:49:29 -04:00
Eli Schwartz e3d70d89b1
fix regression that broke type checking of CustomTarget outputs
We validate a few things here, such as the non-presence of '@INPUT' in
an output name. These got moved out of the CustomTarget constructor in
commit 11f9638035 and into KwargInfo, but
only for kwargs that took multiple values. This caused configure_file()
and unstable_rust.bindgen() to stop checking for this.

Add a shared single-output KW and use it in both places. This now
dispatches to _output_validator.

configure_file now validates subdirectories in output names the same way
we do elsewhere, directly in the typed_kwargs and by specifying the
erroring kwarg.
2022-05-31 17:49:29 -04:00
Eli Schwartz ae0b40945b
make sure no custom_target outputs are named "all" or "meson-internal__*"
Or any other reserved names. We check in add_target that the primary
name of any build target isn't on the forbidden list, but custom_target
allows names that are distinct from the output filenames, so we need to
check those too.

We would eventually still error out all the way at the end, with:

```
ERROR: Multiple producers for Ninja target "all". Please rename your targets.
```

But, if we can check that early and provide the underlying reason
(reserved name) alongside actually useful debugging info (a line
number), then why not?

Refactor the check into a small helper function in the process.
2022-05-31 17:49:29 -04:00
Eli Schwartz 38c00feb9d
relax target name restrictions to cater to internal use
We don't want to allow targets that conflict with:
- our aliased meson-* targets for phony commands
- any meson-*/ directories we create for internal purposes

We do want to allow targets such as:
- our own meson-*.X manpages

There are a couple routes we could take.

Using a better restriction, such as `meson-internal__*`, is trivially
done for our aliased targets, but changing directory names is...
awkward. We probably cannot do this, and doing the former but not the
latter is not very useful.

We could also carefully allow patterns we know we won't use, such as
file extensions, but which the manpages need, which works for our
directories and for many aliased targets, but run_target() is
user-specified and can be anything.

Use a hybrid approach to cover both use cases. We will now allow target
names that fulfill *all* the following criteria:
- it begins with "meson-"
- it doesn't continue with "internal__"
- it has a file extension
2022-05-31 17:49:29 -04:00
Florian "sp1rit"​ ad8f24f232 Implement `preserve_path` for install_headers
The `install_headers` function now has an optional argument
`preserve_path` that allows installing multi-directory
headerfile structures that live alongside sourcecode with a
single command.

For example, the headerfile structure

headers = [
  'one.h',
  'two.h',
  'alpha/one.h',
  'alpha/two.h',
  'alpha/three.h'
  'beta/one.h'
]

can now be passed to `install_headers(headers, subdir: 'mylib', preserve_path: true)`
and the resulting directory tree will look like

{prefix}
└── include
    └── mylib
        ├── alpha
        │   ├── one.h
        │   ├── two.h
        │   └── three.h
        ├── beta
        │   └── one.h
        ├── one.h
        └── two.h

Fixes #3371
2022-05-30 18:03:01 -04:00
Eli Schwartz 194c28297f fix incorrectly allowed kwarg for custom_target
override_options makes no sense for custom_target as we don't use it for
anything. Also, this was added in commit c3c30d4b06
despite not being allowed in permittedKwargsc3c30d4b0.

For inexplicable reasons, we had a known_kwargs for custom_target that
looped over kwargs and issued a warning, not an error, for unknown
kwargs. It was impossible to ever hit that check to begin with, though,
ever since commit e08d735105 which added
permittedKwargs and obsoleted those manual checks with real errors.

So at one point override_options was specially permitted to be used
without emitting a warning, and then for about half a decade it was an
error, and then based on some dead code it was allowed again for a bit.
But through all this it doesn't do anything and isn't documented.
2022-05-30 12:26:19 -04:00
Dylan Baker 8f68f5435d interpreter: add type restrictions to declare_dependency link_whole
Including that we don't accept SharedLibraries or CustomTarget[Index]s
that are a shared library
2022-05-25 22:41:03 -04:00
Dylan Baker 5926190cbb interpreter: add annotations to extract_variables 2022-05-25 22:41:03 -04:00
Daniel Mensinger 7ef73e8f6a ast: cmake: Generate line numbers while printing the AST for better debugging 2022-05-24 18:00:49 -04:00
Eli Schwartz 950fd06bc3 fix traceback when run_command has a find_program as the inline arg
We were poking directly at the node, so if it was a FunctionNode then
this broke. Instead, just do a reverse lookup in the overrides table to
get the original find_program name.
2022-05-24 20:16:16 +03:00
Dylan Baker d97d3721a3 interpreter: Add another overload to source_strings_to_files
Which doesn't have `StructuredSources`, as is actually quite common.
2022-05-23 23:32:47 -04:00
Eli Schwartz 9b17dd4f56
fix typing regression
In commit f2d21bf8a9 a type annotation was
added that does not exist. The referenced type is present but only as a
dotted name.
2022-05-23 16:44:07 -04:00
Eli Schwartz 6c0370f62f
dependencies: handle one more case of subproject installed files
Some projects treat meson.project_source_root() as the root of the
dependency files, because the project itself merely wraps a bunch of
datafiles. Our validation to make sure this doesn't point to another
subproject, made use of pathlib.Path's generator for all component
paths, which... did not include the path itself. So go ahead and
explicitly check that too. Add a test case to verify it while we are at
it.

Fixes https://github.com/mesonbuild/meson/pull/10103#issuecomment-1114901033
2022-05-03 18:43:07 -04:00
Paolo Bonzini 3a960023d3 interpreter: new function add_project_dependencies()
This function can be used to add fundamental dependencies such as glib
to all build products in one fell swoop.  This can be useful whenever,
due to a project's coding conventions, it is not really possible to
compile any source file without including the dependency.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2022-05-03 02:00:29 -04:00
Paolo Bonzini d413dedf2a interpreter: simplify checks in declare_dependency
Both dependencies.ExternalLibrary and dependencies.InternalDependency are
subclasses of dependencies.Dependency, no need to list them separately.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2022-05-03 02:00:29 -04:00
Eli Schwartz e6e8159980
use shared implementation to convert files() strings to File objects
This handles various edge cases:
- checks for sandbox violations just like all other functions
- warn for direntry issues
- check for generated files referred to via strings instead of the
  returned object

(All valid use cases for wanting to sneak around the checks, are made to
work via commit bba588d8b03a9125bf5c4faaad31b70d39242b68.)
2022-05-01 19:57:26 -04:00
Jussi Pakkanen bba588d8b0
Merge pull request #10039 from eli-schwartz/wayland-protocols-subproject-files
dependencies: allow get_variable to expose files from subprojects
2022-05-01 00:01:03 +03:00
Kirill Isakov 39dd1ff9e8 vcs_tag: handle non-str / non-file arguments
This makes vcs_tag behave like other commands so it accepts not only
string and file arguments, but also exe, custom_tgt, and
external_program.
2022-04-20 20:53:19 -04:00
Kirill Isakov 33aa803521 vcs_tag: document the already supported file arg 2022-04-20 20:53:19 -04:00
Eli Schwartz eb2551c90e
remove useless condition
not is_subproject() is the same check as self.subproject == ''
2022-04-14 18:37:04 -04:00
Eli Schwartz df3f064c81
dependencies: move DependencyVariableString handling to declare_dependency
This allows tracking which subproject it came from at the time of
definition, rather than the time of use. As a result, it is no longer
possible for one subproject which knows that another subproject installs
some data files, to expose those data files via its own
declare_dependency.
2022-04-13 17:28:01 -04:00
Eli Schwartz 0e3ed2f655
dependencies: allow get_variable to expose files from subprojects
There are somewhat common, reasonable and legitimate use cases for a
dependency to provide data files installed to /usr which are used as
command inputs. When getting a dependency from a subproject, however,
the attempt to directly construct an input file from a subproject
results in a sandbox violation. This means not all dependencies can be
wrapped as a subproject.

One example is wayland-protocols XML files which get scanned and used to
produce C source files.

Teach Meson to recognize when a string path is the result of fetching a
dep.get_variable(), and special case this to be exempt from subproject
violations.

A requirement of this is that the file must be installed by
install_data() or install_subdir() because otherwise it is not actually
representative of what a pkg-config dependency would provide.
2022-04-13 17:28:01 -04:00
Eli Schwartz e5aa47d8af Revert "wayland: Also lookup scanner in pkgconfig"
This reverts commit 7954a4c9cb.
2022-04-07 23:44:34 -04:00
Xavier Claessens 7954a4c9cb wayland: Also lookup scanner in pkgconfig
This moves generally useful logic from GNOME module's
_get_native_binary() into find_program() implementation. We could decide
later to expose it as public API.
2022-04-04 09:17:34 -04:00
Marvin Scholz 2cdddbab56 Add new debug() function
Adds a new debug() function that can be used in the meson.build to
log messages to the meson-log.txt that will not be printed to stdout
when configuring the project.
2022-03-30 06:57:30 -04:00
Xavier Claessens e33ec88ac7 Pass environment down to base Target class 2022-03-29 16:10:28 -04:00
Xavier Claessens f2d21bf8a9 Make compilers list per subproject
Previously subprojects inherited languages already added by main
project, or any previous subproject. This change to have a list of
compilers per interpreters, which means that if a subproject does not
add 'c' language  it won't be able to compile .c files any more, even if
main project added the 'c' language.

This delays processing list of compilers until the interpreter adds the
BuildTarget into its list of targets. That way the interpreter can add
missing languages instead of duplicating that logic into BuildTarget for
the cython case.
2022-03-24 12:27:06 -04:00
Xavier Claessens 8867fb7999 interpreter: Make compiler options per-subproject 2022-03-22 17:20:48 -04:00
Dylan Baker f9445300b3 structured_sources: fix subdir handling
We currently don't handle subdirectories correctly in
structured_sources, which is problematic. To make this easier to handle
correctly, I've simply changed `structured_sources` to only use Files
and not strings as an implementation detail.
2022-03-18 19:46:24 -07:00
Eli Schwartz e54e9f58e5 give subproject interpreters a view of user defined options
We need this for the python module, as implemented in commit
e8375d20a9, but that then crashed in
subprojects because those options were never forwarded to the subproject
interpreter.
2022-03-13 06:50:31 -04:00
Jussi Pakkanen 69ade4f4cf
Merge pull request #9339 from dcbaker/submit/structured_sources
Structured Sources
2022-03-13 01:01:55 +02:00
Eli Schwartz 5cb9f2b066 fix regression in vcs_tag when the VCS program is not installed
We are supposed to fallback on the fallback when running the vcstagger,
but instead we errored out during configure.

Fixes regression in commit b402817fb6.
Before this, we used shutil.which || relative paths, and in the latter
case if it could not be found we still wrote out that path but it failed
to run in vcstagger. Now, we use find_program under the hood, so it
needs to be run in non-fatal mode, and if it is not found, we simply
keep the original command string. It's a VCS command, so if we magically
end up finding it at runtime because it was installed after running
configure, that is *fine*.
2022-03-12 00:31:12 +02:00
Eli Schwartz 7df6c6a728
add early sanity check for test programs existing
It used to be possible to do this:

```
bomb = find_program('nonexisting', required: false)
test('traceback during meson test', bomb)
```

and it would in fact bomb out, with:

```
[0/1] Running all tests.
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/mesonbuild/mesonmain.py", line 149, in run
    return options.run_func(options)
  File "/usr/lib/python3.10/site-packages/mesonbuild/mtest.py", line 2017, in run
    return th.doit()
  File "/usr/lib/python3.10/site-packages/mesonbuild/mtest.py", line 1685, in doit
    runners.extend(self.get_test_runner(test) for test in tests)
  File "/usr/lib/python3.10/site-packages/mesonbuild/mtest.py", line 1685, in <genexpr>
    runners.extend(self.get_test_runner(test) for test in tests)
  File "/usr/lib/python3.10/site-packages/mesonbuild/mtest.py", line 1586, in get_test_runner
    return SingleTestRunner(test, env, name, options)
  File "/usr/lib/python3.10/site-packages/mesonbuild/mtest.py", line 1308, in __init__
    self.cmd = self._get_cmd()
  File "/usr/lib/python3.10/site-packages/mesonbuild/mtest.py", line 1374, in _get_cmd
    test_cmd = self._get_test_cmd()
  File "/usr/lib/python3.10/site-packages/mesonbuild/mtest.py", line 1352, in _get_test_cmd
    if self.options.no_rebuild and not os.path.isfile(testentry):
  File "/usr/lib/python3.10/genericpath.py", line 30, in isfile
    st = os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

ERROR: Unhandled python exception

    This is a Meson bug and should be reported!
```

This is something we explicitly check for elsewhere, for example when
using a not-found program as a command in a custom target or generator.

Check for it when making a test too, and error out with a similar error.

Fixes #10091
2022-03-08 23:49:26 -05:00
Eli Schwartz c231c4bd2a
move a bunch of imports into TYPE_CHECKING blocks
These are only used for type checking, so don't bother importing them at
runtime.

Generally add future annotations at the same time, to make sure that
existing uses of these imports don't need to be quoted.
2022-03-07 19:09:50 -05:00
Dylan Baker 7d1431a060 build: plumb structured sources into BuildTargets 2022-03-07 12:33:33 -08:00
Dylan Baker cbc62e892a interpreter: add an implementation for structured_sources 2022-03-07 12:33:33 -08:00