Skip to content

Commit 68d9795

Browse files
authored
Merge 1725e62 into 27bd499
2 parents 27bd499 + 1725e62 commit 68d9795

File tree

24 files changed

+784
-357
lines changed

24 files changed

+784
-357
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## passing `target_type : 'jar'` to `build_target()` is deprecated
2+
3+
This never really made sense, as you can't mix java sources with non-java
4+
sources, but this is even more difficult to ensure that we validate the
5+
arguments correctly given that many `jar()` arguments allow differen types
6+
than other targets do.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Deprecated use of absolute paths to D impdirs
2+
3+
This functionality was deprecated in Meson 0.45 (released in early 2018), and
4+
has been removed.

docs/yaml/functions/build_target.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ description: |
1212
- `static_library` (see [[static_library]])
1313
- `both_libraries` (see [[both_libraries]])
1414
- `library` (see [[library]])
15-
- `jar` (see [[jar]])
15+
- `jar` (see [[jar]]) *(deprecated since 1.1.0)*
1616
1717
This declaration:
1818

mesonbuild/ast/introspection.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from ..mesonlib import MachineChoice, OptionKey
3030
from ..mparser import BaseNode, ArithmeticNode, ArrayNode, ElementaryNode, IdNode, FunctionNode, StringNode
3131
from .interpreter import AstInterpreter
32+
from ..interpreter.type_checking import EXECUTABLE_KWS, STATIC_LIB_KWS, SHARED_LIB_KWS, SHARED_MOD_KWS, JAR_KWS
3233

3334
if T.TYPE_CHECKING:
3435
from ..build import BuildTarget
@@ -261,7 +262,18 @@ def traverse_nodes(inqueue: T.List[BaseNode]) -> T.List[BaseNode]:
261262
extraf_nodes = traverse_nodes(extra_queue)
262263

263264
# Make sure nothing can crash when creating the build class
264-
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'}}
265+
if targetclass is Executable:
266+
checks = EXECUTABLE_KWS
267+
elif targetclass is StaticLibrary:
268+
checks = STATIC_LIB_KWS
269+
elif targetclass is SharedLibrary:
270+
checks = SHARED_LIB_KWS
271+
elif targetclass is SharedModule:
272+
checks = SHARED_MOD_KWS
273+
else:
274+
checks = JAR_KWS
275+
keys = {k.name for k in checks}.intersection({'install', 'build_by_default', 'build_always'})
276+
kwargs_reduced = {k: v for k, v in kwargs.items() if k in keys}
265277
kwargs_reduced = {k: v.value if isinstance(v, ElementaryNode) else v for k, v in kwargs_reduced.items()}
266278
kwargs_reduced = {k: v for k, v in kwargs_reduced.items() if not isinstance(v, BaseNode)}
267279
for_machine = MachineChoice.HOST

mesonbuild/build.py

Lines changed: 20 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -61,61 +61,6 @@
6161
LibTypes = T.Union['SharedLibrary', 'StaticLibrary', 'CustomTarget', 'CustomTargetIndex']
6262
BuildTargetTypes = T.Union['BuildTarget', 'CustomTarget', 'CustomTargetIndex']
6363

64-
pch_kwargs = {'c_pch', 'cpp_pch'}
65-
66-
lang_arg_kwargs = {f'{lang}_args' for lang in all_languages}
67-
lang_arg_kwargs |= {
68-
'd_import_dirs',
69-
'd_unittest',
70-
'd_module_versions',
71-
'd_debug',
72-
}
73-
74-
vala_kwargs = {'vala_header', 'vala_gir', 'vala_vapi'}
75-
rust_kwargs = {'rust_crate_type'}
76-
cs_kwargs = {'resources', 'cs_args'}
77-
78-
buildtarget_kwargs = {
79-
'build_by_default',
80-
'build_rpath',
81-
'dependencies',
82-
'extra_files',
83-
'gui_app',
84-
'link_with',
85-
'link_whole',
86-
'link_args',
87-
'link_depends',
88-
'implicit_include_directories',
89-
'include_directories',
90-
'install',
91-
'install_rpath',
92-
'install_dir',
93-
'install_mode',
94-
'install_tag',
95-
'name_prefix',
96-
'name_suffix',
97-
'native',
98-
'objects',
99-
'override_options',
100-
'sources',
101-
'gnu_symbol_visibility',
102-
'link_language',
103-
'win_subsystem',
104-
}
105-
106-
known_build_target_kwargs = (
107-
buildtarget_kwargs |
108-
lang_arg_kwargs |
109-
pch_kwargs |
110-
vala_kwargs |
111-
rust_kwargs |
112-
cs_kwargs)
113-
114-
known_exe_kwargs = known_build_target_kwargs | {'implib', 'export_dynamic', 'pie'}
115-
known_shlib_kwargs = known_build_target_kwargs | {'version', 'soversion', 'vs_module_defs', 'darwin_versions'}
116-
known_shmod_kwargs = known_build_target_kwargs | {'vs_module_defs'}
117-
known_stlib_kwargs = known_build_target_kwargs | {'pic', 'prelink'}
118-
known_jar_kwargs = known_exe_kwargs | {'main_class', 'java_resources'}
11964

12065
def _process_install_tag(install_tag: T.Optional[T.List[T.Optional[str]]],
12166
num_outputs: int) -> T.List[T.Optional[str]]:
@@ -679,7 +624,6 @@ def should_install(self) -> bool:
679624
return False
680625

681626
class BuildTarget(Target):
682-
known_kwargs = known_build_target_kwargs
683627

684628
install_dir: T.List[T.Union[str, Literal[False]]]
685629

@@ -720,7 +664,6 @@ def __init__(self, name: str, subdir: str, subproject: SubProject, for_machine:
720664
# 2. Compiled objects created by and extracted from another target
721665
self.process_objectlist(objects)
722666
self.process_kwargs(kwargs)
723-
self.check_unknown_kwargs(kwargs)
724667
if not any([self.sources, self.generated, self.objects, self.link_whole_targets, self.structured_sources]):
725668
mlog.warning(f'Build target {name} has no sources. '
726669
'This was never supposed to be allowed but did because of a bug, '
@@ -756,19 +699,6 @@ def validate_install(self):
756699
else:
757700
mlog.warning('Installing target build for the build machine. This will fail in a cross build.')
758701

759-
def check_unknown_kwargs(self, kwargs):
760-
# Override this method in derived classes that have more
761-
# keywords.
762-
self.check_unknown_kwargs_int(kwargs, self.known_kwargs)
763-
764-
def check_unknown_kwargs_int(self, kwargs, known_kwargs):
765-
unknowns = []
766-
for k in kwargs:
767-
if k not in known_kwargs:
768-
unknowns.append(k)
769-
if len(unknowns) > 0:
770-
mlog.warning('Unknown keyword argument(s) in target {}: {}.'.format(self.name, ', '.join(unknowns)))
771-
772702
def process_objectlist(self, objects):
773703
assert isinstance(objects, list)
774704
for s in objects:
@@ -1074,8 +1004,8 @@ def process_kwargs(self, kwargs):
10741004
self.add_pch('cpp', extract_as_list(kwargs, 'cpp_pch'))
10751005

10761006
if not isinstance(self, Executable) or 'export_dynamic' in kwargs:
1077-
self.vala_header = kwargs.get('vala_header', self.name + '.h')
1078-
self.vala_vapi = kwargs.get('vala_vapi', self.name + '.vapi')
1007+
self.vala_header = kwargs.get('vala_header') or self.name + '.h'
1008+
self.vala_vapi = kwargs.get('vala_vapi') or self.name + '.vapi'
10791009
self.vala_gir = kwargs.get('vala_gir', None)
10801010

10811011
dfeatures = defaultdict(list)
@@ -1118,10 +1048,10 @@ def process_kwargs(self, kwargs):
11181048
self.add_deps(deplist)
11191049
# If an item in this list is False, the output corresponding to
11201050
# the list index of that item will not be installed
1121-
self.install_dir = typeslistify(kwargs.get('install_dir', []),
1051+
self.install_dir = typeslistify(kwargs.get('install_dir') or [],
11221052
(str, bool))
11231053
self.install_mode = kwargs.get('install_mode', None)
1124-
self.install_tag = stringlistify(kwargs.get('install_tag', [None]))
1054+
self.install_tag = [kwargs['install_tag']] if kwargs.get('install_tag') else [None]
11251055
main_class = kwargs.get('main_class', '')
11261056
if not isinstance(main_class, str):
11271057
raise InvalidArguments('Main class must be a string')
@@ -1130,17 +1060,13 @@ def process_kwargs(self, kwargs):
11301060
# This kwarg is deprecated. The value of "none" means that the kwarg
11311061
# was not specified and win_subsystem should be used instead.
11321062
self.gui_app = None
1133-
if 'gui_app' in kwargs:
1134-
if 'win_subsystem' in kwargs:
1063+
if kwargs.get('gui_app') is not None:
1064+
if kwargs.get('win_subsystem') is not None:
11351065
raise InvalidArguments('Can specify only gui_app or win_subsystem for a target, not both.')
11361066
self.gui_app = kwargs['gui_app']
11371067
if not isinstance(self.gui_app, bool):
11381068
raise InvalidArguments('Argument gui_app must be boolean.')
1139-
self.win_subsystem = self.validate_win_subsystem(kwargs.get('win_subsystem', 'console'))
1140-
elif 'gui_app' in kwargs:
1141-
raise InvalidArguments('Argument gui_app can only be used on executables.')
1142-
elif 'win_subsystem' in kwargs:
1143-
raise InvalidArguments('Argument win_subsystem can only be used on executables.')
1069+
self.win_subsystem = self.validate_win_subsystem(kwargs.get('win_subsystem') or 'console')
11441070
extra_files = extract_as_list(kwargs, 'extra_files')
11451071
for i in extra_files:
11461072
assert isinstance(i, File)
@@ -1162,30 +1088,12 @@ def process_kwargs(self, kwargs):
11621088
if not os.path.isfile(trial):
11631089
raise InvalidArguments(f'Tried to add non-existing resource {r}.')
11641090
self.resources = resources
1165-
if 'name_prefix' in kwargs:
1166-
name_prefix = kwargs['name_prefix']
1167-
if isinstance(name_prefix, list):
1168-
if name_prefix:
1169-
raise InvalidArguments('name_prefix array must be empty to signify default.')
1170-
else:
1171-
if not isinstance(name_prefix, str):
1172-
raise InvalidArguments('name_prefix must be a string.')
1173-
self.prefix = name_prefix
1174-
self.name_prefix_set = True
1175-
if 'name_suffix' in kwargs:
1176-
name_suffix = kwargs['name_suffix']
1177-
if isinstance(name_suffix, list):
1178-
if name_suffix:
1179-
raise InvalidArguments('name_suffix array must be empty to signify default.')
1180-
else:
1181-
if not isinstance(name_suffix, str):
1182-
raise InvalidArguments('name_suffix must be a string.')
1183-
if name_suffix == '':
1184-
raise InvalidArguments('name_suffix should not be an empty string. '
1185-
'If you want meson to use the default behaviour '
1186-
'for each platform pass `[]` (empty array)')
1187-
self.suffix = name_suffix
1188-
self.name_suffix_set = True
1091+
if kwargs.get('name_prefix') is not None:
1092+
self.prefix = kwargs['name_prefix']
1093+
self.name_prefix_set = True
1094+
if kwargs.get('name_suffix') is not None:
1095+
self.suffix = kwargs['name_suffix']
1096+
self.name_suffix_set = True
11891097
if isinstance(self, StaticLibrary):
11901098
# You can't disable PIC on OS X. The compiler ignores -fno-PIC.
11911099
# PIC is always on for Windows (all code is position-independent
@@ -1226,7 +1134,7 @@ def _extract_pic_pie(self, kwargs, arg: str, option: str):
12261134
return True
12271135

12281136
k = OptionKey(option)
1229-
if arg in kwargs:
1137+
if kwargs.get(arg) is not None:
12301138
val = kwargs[arg]
12311139
elif k in self.environment.coredata.options:
12321140
val = self.environment.coredata.options[k].value
@@ -1778,7 +1686,6 @@ def get_subdir(self) -> str:
17781686

17791687

17801688
class Executable(BuildTarget):
1781-
known_kwargs = known_exe_kwargs
17821689

17831690
typename = 'executable'
17841691

@@ -1907,7 +1814,6 @@ def get_command(self) -> 'ImmutableListProtocol[str]':
19071814
return self.outputs
19081815

19091816
class StaticLibrary(BuildTarget):
1910-
known_kwargs = known_stlib_kwargs
19111817

19121818
typename = 'static library'
19131819

@@ -1979,7 +1885,6 @@ def is_internal(self) -> bool:
19791885
return not self.need_install
19801886

19811887
class SharedLibrary(BuildTarget):
1982-
known_kwargs = known_shlib_kwargs
19831888

19841889
typename = 'shared library'
19851890

@@ -2151,57 +2056,19 @@ def determine_filenames(self):
21512056
if create_debug_file:
21522057
self.debug_filename = os.path.splitext(self.filename)[0] + '.pdb'
21532058

2154-
@staticmethod
2155-
def _validate_darwin_versions(darwin_versions):
2156-
try:
2157-
if isinstance(darwin_versions, int):
2158-
darwin_versions = str(darwin_versions)
2159-
if isinstance(darwin_versions, str):
2160-
darwin_versions = 2 * [darwin_versions]
2161-
if not isinstance(darwin_versions, list):
2162-
raise InvalidArguments('Shared library darwin_versions: must be a string, integer,'
2163-
f'or a list, not {darwin_versions!r}')
2164-
if len(darwin_versions) > 2:
2165-
raise InvalidArguments('Shared library darwin_versions: list must contain 2 or fewer elements')
2166-
if len(darwin_versions) == 1:
2167-
darwin_versions = 2 * darwin_versions
2168-
for i, v in enumerate(darwin_versions[:]):
2169-
if isinstance(v, int):
2170-
v = str(v)
2171-
if not isinstance(v, str):
2172-
raise InvalidArguments('Shared library darwin_versions: list elements '
2173-
f'must be strings or integers, not {v!r}')
2174-
if not re.fullmatch(r'[0-9]+(\.[0-9]+){0,2}', v):
2175-
raise InvalidArguments('Shared library darwin_versions: must be X.Y.Z where '
2176-
'X, Y, Z are numbers, and Y and Z are optional')
2177-
parts = v.split('.')
2178-
if len(parts) in {1, 2, 3} and int(parts[0]) > 65535:
2179-
raise InvalidArguments('Shared library darwin_versions: must be X.Y.Z '
2180-
'where X is [0, 65535] and Y, Z are optional')
2181-
if len(parts) in {2, 3} and int(parts[1]) > 255:
2182-
raise InvalidArguments('Shared library darwin_versions: must be X.Y.Z '
2183-
'where Y is [0, 255] and Y, Z are optional')
2184-
if len(parts) == 3 and int(parts[2]) > 255:
2185-
raise InvalidArguments('Shared library darwin_versions: must be X.Y.Z '
2186-
'where Z is [0, 255] and Y, Z are optional')
2187-
darwin_versions[i] = v
2188-
except ValueError:
2189-
raise InvalidArguments('Shared library darwin_versions: value is invalid')
2190-
return darwin_versions
2191-
21922059
def process_kwargs(self, kwargs):
21932060
super().process_kwargs(kwargs)
21942061

21952062
if not self.environment.machines[self.for_machine].is_android():
21962063
# Shared library version
2197-
if 'version' in kwargs:
2064+
if 'version' in kwargs and kwargs['version'] is not None:
21982065
self.ltversion = kwargs['version']
21992066
if not isinstance(self.ltversion, str):
22002067
raise InvalidArguments('Shared library version needs to be a string, not ' + type(self.ltversion).__name__)
22012068
if not re.fullmatch(r'[0-9]+(\.[0-9]+){0,2}', self.ltversion):
22022069
raise InvalidArguments(f'Invalid Shared library version "{self.ltversion}". Must be of the form X.Y.Z where all three are numbers. Y and Z are optional.')
22032070
# Try to extract/deduce the soversion
2204-
if 'soversion' in kwargs:
2071+
if 'soversion' in kwargs and kwargs['soversion'] is not None:
22052072
self.soversion = kwargs['soversion']
22062073
if isinstance(self.soversion, int):
22072074
self.soversion = str(self.soversion)
@@ -2213,14 +2080,14 @@ def process_kwargs(self, kwargs):
22132080
# number of the version by default.
22142081
self.soversion = self.ltversion.split('.')[0]
22152082
# macOS, iOS and tvOS dylib compatibility_version and current_version
2216-
if 'darwin_versions' in kwargs:
2217-
self.darwin_versions = self._validate_darwin_versions(kwargs['darwin_versions'])
2083+
if 'darwin_versions' in kwargs and kwargs['darwin_versions'] is not None:
2084+
self.darwin_versions = kwargs['darwin_versions']
22182085
elif self.soversion:
22192086
# If unspecified, pick the soversion
22202087
self.darwin_versions = 2 * [self.soversion]
22212088

22222089
# Visual Studio module-definitions file
2223-
if 'vs_module_defs' in kwargs:
2090+
if kwargs.get('vs_module_defs') is not None:
22242091
path = kwargs['vs_module_defs']
22252092
if isinstance(path, str):
22262093
if os.path.isabs(path):
@@ -2239,7 +2106,7 @@ def process_kwargs(self, kwargs):
22392106
'a file object or a Custom Target')
22402107
self.process_link_depends(path)
22412108

2242-
if 'rust_crate_type' in kwargs:
2109+
if 'rust_crate_type' in kwargs and kwargs['rust_crate_type'] is not None:
22432110
rust_crate_type = kwargs['rust_crate_type']
22442111
if isinstance(rust_crate_type, str):
22452112
self.rust_crate_type = rust_crate_type
@@ -2313,7 +2180,6 @@ def is_linkable_target(self):
23132180
# A shared library that is meant to be used with dlopen rather than linking
23142181
# into something else.
23152182
class SharedModule(SharedLibrary):
2316-
known_kwargs = known_shmod_kwargs
23172183

23182184
typename = 'shared module'
23192185

@@ -2683,7 +2549,6 @@ def __repr__(self):
26832549
return repr_str.format(self.__class__.__name__, self.get_id())
26842550

26852551
class Jar(BuildTarget):
2686-
known_kwargs = known_jar_kwargs
26872552

26882553
typename = 'jar'
26892554

mesonbuild/coredata.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import copy
16+
1517
from . import mlog, mparser
1618
import pickle, os, uuid
1719
import sys
@@ -896,7 +898,7 @@ def process_new_compiler(self, lang: str, comp: 'Compiler', env: 'Environment')
896898
for key in comp.base_options:
897899
if key in self.options:
898900
continue
899-
oobj = compilers.base_options[key]
901+
oobj = copy.deepcopy(compilers.base_options[key])
900902
if key in env.options:
901903
oobj.set_value(env.options[key])
902904
enabled_opts.append(key)

0 commit comments

Comments
 (0)