Skip to content

Commit

Permalink
interpreter: deprecated language args that don't apply to targets
Browse files Browse the repository at this point in the history
`java_args` is only valid for `jar()` (and `build_target()`, but that's
deprecated), while all other language args are invalid for `jar()`. This
deprecates all of those arguments, that shouldn't be allowed, and
provides useful error messages. As an advantage, this avoids generating
useless `java_static_args` and `java_shared_args`.

In order to get useful error messages for both build_target and
executable + *library, we need to separate LIBRARY and BUILD_TARGET a
bit.
  • Loading branch information
dcbaker committed Sep 26, 2023
1 parent 4602af7 commit 626624b
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,24 +513,37 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus
since='1.3.0',
validator=in_set_validator({'rust', 'c'}))

_BASE_LANG_KW: KwargInfo[T.List[str]] = KwargInfo(
'UNKNOWN',
ContainerTypeInfo(list, (str)),
listify=True,
default=[],
)

_LANGUAGE_KWS: T.List[KwargInfo[T.List[str]]] = [
KwargInfo(f'{lang}_args', ContainerTypeInfo(list, (str, File)), listify=True, default=[])
for lang in compilers.all_languages - {'rust', 'vala'}
_BASE_LANG_KW.evolve(name=f'{lang}_args')
for lang in compilers.all_languages - {'rust', 'vala', 'java'}
]
_LANGUAGE_KWS.append(KwargInfo(
_LANGUAGE_KWS.append(KwargInfo( # cannot use _BASE_LANG_KW because type is not evolveable
'vala_args', ContainerTypeInfo(list, (str, File)), listify=True, default=[]))
_LANGUAGE_KWS.append(KwargInfo(
'rust_args', ContainerTypeInfo(list, str), listify=True, default=[], since='0.41.0'))
_LANGUAGE_KWS.append(_BASE_LANG_KW.evolve(name='rust_args', since='0.41.0'))

# We need this deprecated values more than the non-deprecated values. So we'll evolve them out elsewhere.
_JAVA_LANG_KW: KwargInfo[T.List[str]] = _BASE_LANG_KW.evolve(
name='java_args',
deprecated='1.3.0',
deprecated_message='This does not, and never has, done anything. It should be removed'
)

# Applies to all build_target like classes
_ALL_TARGET_KWS: T.List[KwargInfo] = [
*_LANGUAGE_KWS,
OVERRIDE_OPTIONS_KW,
]

# Applies to all build_target classes except jar
_BUILD_TARGET_KWS: T.List[KwargInfo] = [
*_ALL_TARGET_KWS,
*_LANGUAGE_KWS,
RUST_CRATE_TYPE_KW,
]

Expand Down Expand Up @@ -599,6 +612,7 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup
EXECUTABLE_KWS = [
*_BUILD_TARGET_KWS,
*_EXCLUSIVE_EXECUTABLE_KWS,
_JAVA_LANG_KW,
]

# Arguments exclusive to library types
Expand All @@ -615,6 +629,7 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup
*_BUILD_TARGET_KWS,
*_EXCLUSIVE_STATIC_LIB_KWS,
*_EXCLUSIVE_LIB_KWS,
_JAVA_LANG_KW,
]

# Arguments exclusive to SharedLibrary. These are separated to make integrating
Expand All @@ -630,6 +645,7 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup
*_BUILD_TARGET_KWS,
*_EXCLUSIVE_SHARED_LIB_KWS,
*_EXCLUSIVE_LIB_KWS,
_JAVA_LANG_KW,
]

# Arguments exclusive to SharedModule. These are separated to make integrating
Expand All @@ -641,19 +657,24 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup
*_BUILD_TARGET_KWS,
*_EXCLUSIVE_SHARED_MOD_KWS,
*_EXCLUSIVE_LIB_KWS,
_JAVA_LANG_KW,
]

# Arguments exclusive to JAR. These are separated to make integrating
# them into build_target easier
_EXCLUSIVE_JAR_KWS: T.List[KwargInfo] = [
KwargInfo('main_class', str, default=''),
KwargInfo('java_resources', (StructuredSources, NoneType), since='0.62.0'),
_JAVA_LANG_KW.evolve(deprecated=None, deprecated_message=None),
]

# The total list of arguments used by JAR
JAR_KWS = [
*_ALL_TARGET_KWS,
*_EXCLUSIVE_JAR_KWS,
*[a.evolve(deprecated='1.3.0', deprecated_message='This argument has never done anything in jar(), and should be removed')
for a in _LANGUAGE_KWS],
# This is the only not deprecated case
]

# Arguments used by both_library and library
Expand All @@ -663,11 +684,15 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup
*_EXCLUSIVE_SHARED_LIB_KWS,
*_EXCLUSIVE_SHARED_MOD_KWS,
*_EXCLUSIVE_STATIC_LIB_KWS,
_JAVA_LANG_KW,
]

# Arguments used by build_Target
BUILD_TARGET_KWS = [
*LIBRARY_KWS,
*_BUILD_TARGET_KWS,
*_EXCLUSIVE_SHARED_LIB_KWS,
*_EXCLUSIVE_SHARED_MOD_KWS,
*_EXCLUSIVE_STATIC_LIB_KWS,
*_EXCLUSIVE_EXECUTABLE_KWS,
*[a.evolve(deprecated='1.3.0', deprecated_message='The use of "jar" in "build_target()" is deprecated, and this argument is only used by jar()')
for a in _EXCLUSIVE_JAR_KWS],
Expand Down

0 comments on commit 626624b

Please sign in to comment.