summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2024-11-16 15:27:44 +0100
committerDylan Baker <dylan@pnwbakers.com>2024-12-19 09:25:20 -0800
commit15c2c9811411e5e84419bcee487fb3a84ac2756c (patch)
tree1237a185415fec8135fad99b0d7b73fb82d0d6e4
parent8b9846d9a9d29b427860891c9b699eb4305e348b (diff)
downloadmeson-15c2c9811411e5e84419bcee487fb3a84ac2756c.tar.gz
introspect: add machine to target_sources
Even though the "targets" introspection info already includes the command line arguments used to invoke the compiler, this is not enough to correlated with the "compilers" introspection info and get extra information from there. Together with the existing "language" key, adding a "machine" key is enough to identify completely an entry in the compilers info. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--docs/markdown/IDE-integration.md8
-rw-r--r--docs/markdown/snippets/introspect_machine.md5
-rw-r--r--mesonbuild/ast/introspection.py3
-rw-r--r--mesonbuild/backend/backends.py3
-rw-r--r--mesonbuild/backend/ninjabackend.py1
-rw-r--r--mesonbuild/mintro.py1
-rw-r--r--unittests/allplatformstests.py12
7 files changed, 29 insertions, 4 deletions
diff --git a/docs/markdown/IDE-integration.md b/docs/markdown/IDE-integration.md
index 77edb755d..ce8d8b42e 100644
--- a/docs/markdown/IDE-integration.md
+++ b/docs/markdown/IDE-integration.md
@@ -93,6 +93,7 @@ can provide code completion for all source files.
```json
{
"language": "language ID",
+ "machine": "build" / "host",
"compiler": ["The", "compiler", "command"],
"parameters": ["list", "of", "compiler", "parameters"],
"sources": ["list", "of", "all", "source", "files", "for", "this", "language"],
@@ -100,6 +101,13 @@ can provide code completion for all source files.
}
```
+*(New in 1.7.0)* The `machine` and `language` keys make it possible to
+to access further information about the compiler in the `compilers`
+introspection information. `machine` can be absent if `language` is
+`unknown`. In this case, information about the compiler is not
+available; Meson is therefore unable to know if the output relates
+to either the build of the host machine.
+
It should be noted that the compiler parameters stored in the
`parameters` differ from the actual parameters used to compile the
file. This is because the parameters are optimized for the usage in an
diff --git a/docs/markdown/snippets/introspect_machine.md b/docs/markdown/snippets/introspect_machine.md
new file mode 100644
index 000000000..9b19bd6a2
--- /dev/null
+++ b/docs/markdown/snippets/introspect_machine.md
@@ -0,0 +1,5 @@
+## "machine" entry in target introspection data
+
+The JSON data returned by `meson introspect --targets` now has a `machine`
+entry in each `target_sources` block. The new entry can be one of `build`
+or `host` for compiler-built targets, or absent for `custom_target` targets.
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py
index 3e8d564e2..6bc6286f2 100644
--- a/mesonbuild/ast/introspection.py
+++ b/mesonbuild/ast/introspection.py
@@ -283,7 +283,7 @@ class IntrospectionInterpreter(AstInterpreter):
kwargs_reduced = {k: v for k, v in kwargs.items() if k in targetclass.known_kwargs and k in {'install', 'build_by_default', 'build_always'}}
kwargs_reduced = {k: v.value if isinstance(v, ElementaryNode) else v for k, v in kwargs_reduced.items()}
kwargs_reduced = {k: v for k, v in kwargs_reduced.items() if not isinstance(v, BaseNode)}
- for_machine = MachineChoice.HOST
+ for_machine = MachineChoice.BUILD if kwargs.get('native', False) else MachineChoice.HOST
objects: T.List[T.Any] = []
empty_sources: T.List[T.Any] = []
# Passing the unresolved sources list causes errors
@@ -294,6 +294,7 @@ class IntrospectionInterpreter(AstInterpreter):
new_target = {
'name': target.get_basename(),
+ 'machine': target.for_machine.get_lower_case_name(),
'id': target.get_id(),
'type': target.get_typename(),
'defined_in': os.path.normpath(os.path.join(self.source_root, self.subdir, environment.build_filename)),
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index a4be50f66..d2c6a4696 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -41,13 +41,14 @@ if T.TYPE_CHECKING:
from ..linkers.linkers import StaticLinker
from ..mesonlib import FileMode, FileOrString
- from typing_extensions import TypedDict
+ from typing_extensions import TypedDict, NotRequired
_ALL_SOURCES_TYPE = T.List[T.Union[File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]]
class TargetIntrospectionData(TypedDict):
language: str
+ machine: NotRequired[str]
compiler: T.List[str]
parameters: T.List[str]
sources: T.List[str]
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 5716ea29e..64921ffa6 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -837,6 +837,7 @@ class NinjaBackend(backends.Backend):
# The new entry
src_block = {
'language': lang,
+ 'machine': comp.for_machine.get_lower_case_name(),
'compiler': comp.get_exelist(),
'parameters': parameters,
'sources': [],
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
index 810a2b674..b9b09c557 100644
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -211,6 +211,7 @@ def list_targets_from_source(intr: IntrospectionInterpreter) -> T.List[T.Dict[st
'build_by_default': i['build_by_default'],
'target_sources': [{
'language': 'unknown',
+ 'machine': i['machine'],
'compiler': [],
'parameters': [],
'sources': [str(x) for x in sources],
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index b6a87af1f..1b1e16928 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -3333,7 +3333,7 @@ class AllPlatformTests(BasePlatformTests):
('win_subsystem', (str, None)),
]
- targets_sources_typelist = [
+ targets_sources_unknown_lang_typelist = [
('language', str),
('compiler', list),
('parameters', list),
@@ -3342,6 +3342,10 @@ class AllPlatformTests(BasePlatformTests):
('unity_sources', (list, None)),
]
+ targets_sources_typelist = targets_sources_unknown_lang_typelist + [
+ ('machine', str),
+ ]
+
target_sources_linker_typelist = [
('linker', list),
('parameters', list),
@@ -3456,7 +3460,10 @@ class AllPlatformTests(BasePlatformTests):
targets_to_find.pop(i['name'], None)
for j in i['target_sources']:
if 'compiler' in j:
- assertKeyTypes(targets_sources_typelist, j)
+ if j['language'] == 'unknown':
+ assertKeyTypes(targets_sources_unknown_lang_typelist, j)
+ else:
+ assertKeyTypes(targets_sources_typelist, j)
self.assertEqual(j['sources'], [os.path.normpath(f) for f in tgt[4]])
else:
assertKeyTypes(target_sources_linker_typelist, j)
@@ -3558,6 +3565,7 @@ class AllPlatformTests(BasePlatformTests):
sources += j.get('sources', [])
i['target_sources'] = [{
'language': 'unknown',
+ 'machine': 'host',
'compiler': [],
'parameters': [],
'sources': sources,