Skip to content

Commit

Permalink
fix implicit_reexport issues and enforce them going forward
Browse files Browse the repository at this point in the history
This detects cases where module A imports a function from B, and C
imports that same function from A instead of B. It's not part of the API
contract of A, and causes innocent refactoring to break things.
  • Loading branch information
eli-schwartz committed Jul 19, 2023
1 parent cfc3960 commit 7afc692
Show file tree
Hide file tree
Showing 32 changed files with 98 additions and 100 deletions.
1 change: 1 addition & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ strict_optional = False
show_error_context = False
show_column_numbers = True
ignore_missing_imports = True
implicit_reexport = False

follow_imports = silent
warn_redundant_casts = True
Expand Down
14 changes: 7 additions & 7 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class TestSerialisation:
needs_exe_wrapper: bool
is_parallel: bool
cmd_args: T.List[str]
env: build.EnvironmentVariables
env: mesonlib.EnvironmentVariables
should_fail: bool
timeout: T.Optional[int]
workdir: T.Optional[str]
Expand Down Expand Up @@ -512,7 +512,7 @@ def get_executable_serialisation(
extra_bdeps: T.Optional[T.List[build.BuildTarget]] = None,
capture: T.Optional[bool] = None,
feed: T.Optional[bool] = None,
env: T.Optional[build.EnvironmentVariables] = None,
env: T.Optional[mesonlib.EnvironmentVariables] = None,
tag: T.Optional[str] = None,
verbose: bool = False,
installdir_map: T.Optional[T.Dict[str, str]] = None) -> 'ExecutableSerialisation':
Expand Down Expand Up @@ -585,7 +585,7 @@ def as_meson_exe_cmdline(self, exe: T.Union[str, mesonlib.File, build.BuildTarge
capture: T.Optional[bool] = None,
feed: T.Optional[bool] = None,
force_serialize: bool = False,
env: T.Optional[build.EnvironmentVariables] = None,
env: T.Optional[mesonlib.EnvironmentVariables] = None,
verbose: bool = False) -> T.Tuple[T.Sequence[T.Union[str, File, build.Target, programs.ExternalProgram]], str]:
'''
Serialize an executable for running with a generator or a custom target
Expand Down Expand Up @@ -1588,8 +1588,8 @@ def eval_custom_target_command(
cmd = [i.replace('\\', '/') for i in cmd]
return inputs, outputs, cmd

def get_run_target_env(self, target: build.RunTarget) -> build.EnvironmentVariables:
env = target.env if target.env else build.EnvironmentVariables()
def get_run_target_env(self, target: build.RunTarget) -> mesonlib.EnvironmentVariables:
env = target.env if target.env else mesonlib.EnvironmentVariables()
if target.default_env:
introspect_cmd = join_args(self.environment.get_build_command() + ['introspect'])
env.set('MESON_SOURCE_ROOT', [self.environment.get_source_dir()])
Expand Down Expand Up @@ -1959,8 +1959,8 @@ def get_introspection_data(self, target_id: str, target: build.Target) -> T.List

return []

def get_devenv(self) -> build.EnvironmentVariables:
env = build.EnvironmentVariables()
def get_devenv(self) -> mesonlib.EnvironmentVariables:
env = mesonlib.EnvironmentVariables()
extra_paths = set()
library_paths = set()
build_machine = self.environment.machines[MachineChoice.BUILD]
Expand Down
21 changes: 11 additions & 10 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@
MesonBugException, EnvironmentVariables, pickle_load,
)
from .compilers import (
is_object, clink_langs, sort_clink, all_languages,
is_header, is_object, is_source, clink_langs, sort_clink, all_languages,
is_known_suffix, detect_static_linker
)
from .interpreterbase import FeatureNew, FeatureDeprecated

if T.TYPE_CHECKING:
from typing_extensions import Literal
from ._typing import ImmutableListProtocol
from .backend.backends import Backend, ExecutableSerialisation
from .backend.backends import Backend
from .compilers import Compiler
from .interpreter.interpreter import Test, SourceOutputs, Interpreter
from .interpreter.interpreter import SourceOutputs, Interpreter
from .interpreter.interpreterobjects import Test
from .interpreterbase import SubProject
from .linkers.linkers import StaticLinker
from .mesonlib import FileMode, FileOrString
from .mesonlib import ExecutableSerialisation, FileMode, FileOrString
from .modules import ModuleState
from .mparser import BaseNode
from .wrap import WrapMode
Expand Down Expand Up @@ -434,7 +435,7 @@ def get_sources(sources: T.Sequence['FileOrString'], generated_sources: T.Sequen
sources.append(s)

# Filter out headers and all non-source files
return [s for s in sources if environment.is_source(s)]
return [s for s in sources if is_source(s)]

def classify_all_sources(self, sources: T.List[FileOrString], generated_sources: T.Sequence['GeneratedTypes']) -> T.Dict['Compiler', T.List['FileOrString']]:
sources_ = self.get_sources(sources, generated_sources)
Expand Down Expand Up @@ -1494,14 +1495,14 @@ def add_pch(self, language: str, pchlist: T.List[str]) -> None:
if not pchlist:
return
elif len(pchlist) == 1:
if not environment.is_header(pchlist[0]):
if not is_header(pchlist[0]):
raise InvalidArguments(f'PCH argument {pchlist[0]} is not a header.')
elif len(pchlist) == 2:
if environment.is_header(pchlist[0]):
if not environment.is_source(pchlist[1]):
if is_header(pchlist[0]):
if not is_source(pchlist[1]):
raise InvalidArguments('PCH definition must contain one header and at most one source.')
elif environment.is_source(pchlist[0]):
if not environment.is_header(pchlist[1]):
elif is_source(pchlist[0]):
if not is_header(pchlist[1]):
raise InvalidArguments('PCH definition must contain one header and at most one source.')
pchlist = [pchlist[1], pchlist[0]]
else:
Expand Down
3 changes: 1 addition & 2 deletions mesonbuild/compilers/mixins/clike.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
from ... import mesonlib
from ... import mlog
from ...linkers.linkers import GnuLikeDynamicLinkerMixin, SolarisDynamicLinker, CompCertDynamicLinker
from ...mesonlib import LibType
from ...coredata import OptionKey
from ...mesonlib import LibType, OptionKey
from .. import compilers
from ..compilers import CompileCheckMode
from .visualstudio import VisualStudioLikeCompiler
Expand Down
5 changes: 2 additions & 3 deletions mesonbuild/compilers/vala.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
import typing as T

from .. import mlog
from ..mesonlib import EnvironmentException, version_compare, OptionKey

from .compilers import CompileCheckMode, Compiler, LibType
from ..mesonlib import EnvironmentException, version_compare, LibType, OptionKey
from .compilers import CompileCheckMode, Compiler

if T.TYPE_CHECKING:
from ..envconfig import MachineInfo
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/dependencies/boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
from .misc import threads_factory

if T.TYPE_CHECKING:
from ..environment import Environment, Properties
from ..envconfig import Properties
from ..environment import Environment

# On windows 3 directory layouts are supported:
# * The default layout (versioned) installed:
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/dependencies/coarrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

if T.TYPE_CHECKING:
from . factory import DependencyGenerator
from ..environment import Environment, MachineChoice
from ..environment import Environment
from ..mesonlib import MachineChoice


@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE, DependencyMethods.SYSTEM})
Expand Down
8 changes: 4 additions & 4 deletions mesonbuild/dependencies/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
from .pkgconfig import PkgConfigDependency

if T.TYPE_CHECKING:
from ..environment import Environment, MachineChoice
from ..environment import Environment
from .factory import DependencyGenerator


@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE})
def netcdf_factory(env: 'Environment',
for_machine: 'MachineChoice',
for_machine: 'mesonlib.MachineChoice',
kwargs: T.Dict[str, T.Any],
methods: T.List[DependencyMethods]) -> T.List['DependencyGenerator']:
language = kwargs.get('language', 'c')
Expand Down Expand Up @@ -475,7 +475,7 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):

@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.SYSTEM})
def curses_factory(env: 'Environment',
for_machine: 'MachineChoice',
for_machine: 'mesonlib.MachineChoice',
kwargs: T.Dict[str, T.Any],
methods: T.List[DependencyMethods]) -> T.List['DependencyGenerator']:
candidates: T.List['DependencyGenerator'] = []
Expand All @@ -501,7 +501,7 @@ def curses_factory(env: 'Environment',

@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM})
def shaderc_factory(env: 'Environment',
for_machine: 'MachineChoice',
for_machine: 'mesonlib.MachineChoice',
kwargs: T.Dict[str, T.Any],
methods: T.List[DependencyMethods]) -> T.List['DependencyGenerator']:
"""Custom DependencyFactory for ShaderC.
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/dependencies/mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

if T.TYPE_CHECKING:
from .factory import DependencyGenerator
from ..environment import Environment, MachineChoice
from ..environment import Environment
from ..mesonlib import MachineChoice


@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.SYSTEM})
Expand Down
4 changes: 1 addition & 3 deletions mesonbuild/dependencies/pkgconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pathlib import Path

from .base import ExternalDependency, DependencyException, sort_libpaths, DependencyTypeName
from ..mesonlib import OptionKey, OrderedSet, PerMachine, Popen_safe, Popen_safe_logged
from ..mesonlib import EnvironmentVariables, OptionKey, OrderedSet, PerMachine, Popen_safe, Popen_safe_logged
from ..programs import find_external_program, ExternalProgram
from .. import mlog
from pathlib import PurePath
Expand All @@ -30,7 +30,6 @@
from ..mesonlib import MachineChoice
from ..utils.core import EnvironOrDict
from .._typing import ImmutableListProtocol
from ..build import EnvironmentVariables

class PkgConfigDependency(ExternalDependency):
# The class's copy of the pkg-config path. Avoids having to search for it
Expand Down Expand Up @@ -128,7 +127,6 @@ def _call_pkgbin_real(self, args: T.List[str], env: T.Dict[str, str]) -> T.Tuple
@staticmethod
def get_env(environment: 'Environment', for_machine: MachineChoice,
uninstalled: bool = False) -> 'EnvironmentVariables':
from ..build import EnvironmentVariables
env = EnvironmentVariables()
key = OptionKey('pkg_config_path', machine=for_machine)
extra_paths: T.List[str] = environment.coredata.options[key].value[:]
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/dependencies/scalapack.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
from .factory import factory_methods

if T.TYPE_CHECKING:
from ..environment import Environment, MachineChoice
from ..environment import Environment
from ..mesonlib import MachineChoice
from .factory import DependencyGenerator


Expand Down
15 changes: 7 additions & 8 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .. import envconfig
from ..wrap import wrap, WrapMode
from .. import mesonlib
from ..mesonlib import (MesonBugException, MesonException, HoldableObject,
from ..mesonlib import (EnvironmentVariables, ExecutableSerialisation, MesonBugException, MesonException, HoldableObject,
FileMode, MachineChoice, OptionKey, listify,
extract_as_list, has_path_sep, PerMachine)
from ..programs import ExternalProgram, NonExistingExternalProgram
Expand All @@ -36,7 +36,6 @@
from ..interpreterbase import FeatureNew, FeatureDeprecated, FeatureBroken, FeatureNewKwargs, FeatureDeprecatedKwargs
from ..interpreterbase import ObjectHolder, ContextManagerObject
from ..modules import ExtensionModule, ModuleObject, MutableModuleObject, NewExtensionModule, NotFoundExtensionModule
from ..backend.backends import ExecutableSerialisation

from . import interpreterobjects as OBJ
from . import compiler as compilerOBJ
Expand Down Expand Up @@ -458,7 +457,7 @@ def build_holder_map(self) -> None:
build.SymlinkData: OBJ.SymlinkDataHolder,
build.InstallDir: OBJ.InstallDirHolder,
build.IncludeDirs: OBJ.IncludeDirsHolder,
build.EnvironmentVariables: OBJ.EnvironmentVariablesHolder,
mesonlib.EnvironmentVariables: OBJ.EnvironmentVariablesHolder,
build.StructuredSources: OBJ.StructuredSourcesHolder,
compilers.RunResult: compilerOBJ.TryRunResultHolder,
dependencies.ExternalLibrary: OBJ.ExternalLibraryHolder,
Expand Down Expand Up @@ -2166,10 +2165,10 @@ def func_test(self, node: mparser.BaseNode,
kwargs: 'kwtypes.FuncTest') -> None:
self.add_test(node, args, kwargs, True)

def unpack_env_kwarg(self, kwargs: T.Union[build.EnvironmentVariables, T.Dict[str, 'TYPE_var'], T.List['TYPE_var'], str]) -> build.EnvironmentVariables:
def unpack_env_kwarg(self, kwargs: T.Union[EnvironmentVariables, T.Dict[str, 'TYPE_var'], T.List['TYPE_var'], str]) -> EnvironmentVariables:
envlist = kwargs.get('env')
if envlist is None:
return build.EnvironmentVariables()
return EnvironmentVariables()
msg = ENV_KW.validator(envlist)
if msg:
raise InvalidArguments(f'"env": {msg}')
Expand Down Expand Up @@ -2687,7 +2686,7 @@ def func_configure_file(self, node: mparser.BaseNode, args: T.List[TYPE_var],
mlog.log('Configuring', mlog.bold(output), 'with command')
cmd, *args = _cmd
res = self.run_command_impl(node, (cmd, args),
{'capture': True, 'check': True, 'env': build.EnvironmentVariables()},
{'capture': True, 'check': True, 'env': EnvironmentVariables()},
True)
if kwargs['capture']:
dst_tmp = ofile_abs + '~'
Expand Down Expand Up @@ -2967,7 +2966,7 @@ def _add_arguments(self, node: mparser.FunctionNode, argsdict: T.Dict[str, T.Lis
@typed_pos_args('environment', optargs=[(str, list, dict)])
@typed_kwargs('environment', ENV_METHOD_KW, ENV_SEPARATOR_KW.evolve(since='0.62.0'))
def func_environment(self, node: mparser.FunctionNode, args: T.Tuple[T.Union[None, str, T.List['TYPE_var'], T.Dict[str, 'TYPE_var']]],
kwargs: 'TYPE_kwargs') -> build.EnvironmentVariables:
kwargs: 'TYPE_kwargs') -> EnvironmentVariables:
init = args[0]
if init is not None:
FeatureNew.single_use('environment positional arguments', '0.52.0', self.subproject, location=node)
Expand All @@ -2977,7 +2976,7 @@ def func_environment(self, node: mparser.FunctionNode, args: T.Tuple[T.Union[Non
if isinstance(init, dict) and any(i for i in init.values() if isinstance(i, list)):
FeatureNew.single_use('List of string in dictionary value', '0.62.0', self.subproject, location=node)
return env_convertor_with_method(init, kwargs['method'], kwargs['separator'])
return build.EnvironmentVariables()
return EnvironmentVariables()

@typed_pos_args('join_paths', varargs=str, min_varargs=1)
@noKwargs
Expand Down
10 changes: 5 additions & 5 deletions mesonbuild/interpreter/interpreterobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class RunProcess(MesonInterpreterObject):
def __init__(self,
cmd: ExternalProgram,
args: T.List[str],
env: build.EnvironmentVariables,
env: mesonlib.EnvironmentVariables,
source_dir: str,
build_dir: str,
subdir: str,
Expand All @@ -224,7 +224,7 @@ def __init__(self,
def run_command(self,
cmd: ExternalProgram,
args: T.List[str],
env: build.EnvironmentVariables,
env: mesonlib.EnvironmentVariables,
source_dir: str,
build_dir: str,
subdir: str,
Expand Down Expand Up @@ -280,9 +280,9 @@ def stdout_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str:
def stderr_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str:
return self.stderr

class EnvironmentVariablesHolder(ObjectHolder[build.EnvironmentVariables], MutableInterpreterObject):
class EnvironmentVariablesHolder(ObjectHolder[mesonlib.EnvironmentVariables], MutableInterpreterObject):

def __init__(self, obj: build.EnvironmentVariables, interpreter: 'Interpreter'):
def __init__(self, obj: mesonlib.EnvironmentVariables, interpreter: 'Interpreter'):
super().__init__(obj, interpreter)
self.methods.update({'set': self.set_method,
'append': self.append_method,
Expand Down Expand Up @@ -711,7 +711,7 @@ def __init__(self, name: str, project: str, suite: T.List[str],
depends: T.List[T.Union[build.CustomTarget, build.BuildTarget]],
is_parallel: bool,
cmd_args: T.List[T.Union[str, mesonlib.File, build.Target]],
env: build.EnvironmentVariables,
env: mesonlib.EnvironmentVariables,
should_fail: bool, timeout: int, workdir: T.Optional[str], protocol: str,
priority: int, verbose: bool):
super().__init__()
Expand Down
12 changes: 6 additions & 6 deletions mesonbuild/interpreter/kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .. import build
from .. import coredata
from ..compilers import Compiler
from ..mesonlib import MachineChoice, File, FileMode, FileOrString, OptionKey
from ..mesonlib import EnvironmentVariables, MachineChoice, File, FileMode, FileOrString, OptionKey
from ..modules.cmake import CMakeSubprojectOptions
from ..programs import ExternalProgram

Expand Down Expand Up @@ -42,7 +42,7 @@ class BaseTest(TypedDict):
workdir: T.Optional[str]
depends: T.List[T.Union[build.CustomTarget, build.BuildTarget]]
priority: int
env: build.EnvironmentVariables
env: EnvironmentVariables
suite: T.List[str]


Expand Down Expand Up @@ -164,7 +164,7 @@ class RunTarget(TypedDict):

command: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, ExternalProgram, File]]
depends: T.List[T.Union[build.BuildTarget, build.CustomTarget]]
env: build.EnvironmentVariables
env: EnvironmentVariables


class CustomTarget(TypedDict):
Expand All @@ -179,7 +179,7 @@ class CustomTarget(TypedDict):
depend_files: T.List[FileOrString]
depends: T.List[T.Union[build.BuildTarget, build.CustomTarget]]
depfile: T.Optional[str]
env: build.EnvironmentVariables
env: EnvironmentVariables
feed: bool
input: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex,
build.ExtractedObjects, build.GeneratedList, ExternalProgram, File]]
Expand All @@ -196,7 +196,7 @@ class AddTestSetup(TypedDict):
timeout_multiplier: int
is_default: bool
exclude_suites: T.List[str]
env: build.EnvironmentVariables
env: EnvironmentVariables


class Project(TypedDict):
Expand Down Expand Up @@ -240,7 +240,7 @@ class RunCommand(TypedDict):

check: bool
capture: T.Optional[bool]
env: build.EnvironmentVariables
env: EnvironmentVariables


class FeatureOptionRequire(TypedDict):
Expand Down
Loading

0 comments on commit 7afc692

Please sign in to comment.