external-project: Add typing annotation

pull/7490/head
Xavier Claessens 4 years ago committed by Xavier Claessens
parent 9d338200da
commit 6ec0b535ba
  1. 27
      mesonbuild/modules/unstable_external_project.py
  2. 9
      mesonbuild/scripts/externalproject.py

@ -14,6 +14,7 @@
import os, subprocess, shlex
from pathlib import Path
import typing as T
from . import ExtensionModule, ModuleReturnValue
from .. import mlog, build
@ -21,13 +22,25 @@ from ..mesonlib import (MesonException, Popen_safe, MachineChoice,
get_variable_regex, do_replacement)
from ..interpreterbase import InterpreterObject, InterpreterException, FeatureNew
from ..interpreterbase import stringArgs, permittedKwargs
from ..interpreter import DependencyHolder, InstallDir
from ..interpreter import Interpreter, DependencyHolder, InstallDir
from ..compilers.compilers import cflags_mapping, cexe_mapping
from ..dependencies.base import InternalDependency, PkgConfigDependency
from ..environment import Environment
class ExternalProject(InterpreterObject):
def __init__(self, interpreter, subdir, project_version, subproject, environment, build_machine, host_machine,
configure_command, configure_options, cross_configure_options, env, verbose):
def __init__(self,
interpreter: Interpreter,
subdir: str,
project_version: T.Dict[str, str],
subproject: str,
environment: Environment,
build_machine: str,
host_machine: str,
configure_command: T.List[str],
configure_options: T.List[str],
cross_configure_options: T.List[str],
env: build.EnvironmentVariables,
verbose: bool):
InterpreterObject.__init__(self)
self.methods.update({'dependency': self.dependency_method,
})
@ -116,10 +129,10 @@ class ExternalProject(InterpreterObject):
self.build_dir.mkdir(parents=True, exist_ok=True)
self._run('configure', configure_cmd)
def _quote_and_join(self, array):
def _quote_and_join(self, array: T.List[str]) -> str:
return ' '.join([shlex.quote(i) for i in array])
def _validate_configure_options(self, required_keys):
def _validate_configure_options(self, required_keys: T.List[str]):
# Ensure the user at least try to pass basic info to the build system,
# like the prefix, libdir, etc.
for key in required_keys:
@ -131,7 +144,7 @@ class ExternalProject(InterpreterObject):
m = 'At least one configure option must contain "{}" key'
raise InterpreterException(m.format(key_format))
def _format_options(self, options, variables):
def _format_options(self, options: T.List[str], variables: T.Dict[str, str]) -> T.List[str]:
out = []
missing = set()
regex = get_variable_regex('meson')
@ -146,7 +159,7 @@ class ExternalProject(InterpreterObject):
"Variables {} in configure options are missing.".format(var_list))
return out
def _run(self, step, command):
def _run(self, step: str, command: T.List[str]):
mlog.log('External project {}:'.format(self.name), mlog.bold(step))
output = None if self.verbose else subprocess.DEVNULL
p, o, e = Popen_safe(command, cwd=str(self.build_dir), env=self.run_env,

@ -17,11 +17,12 @@ import argparse
import multiprocessing
import subprocess
from pathlib import Path
import typing as T
from ..mesonlib import Popen_safe
class ExternalProject:
def __init__(self, options):
def __init__(self, options: argparse.Namespace):
self.name = options.name
self.src_dir = options.srcdir
self.build_dir = options.builddir
@ -46,13 +47,13 @@ class ExternalProject:
with open(self.stampfile, 'w') as f:
pass
def gnu_make(self):
def gnu_make(self) -> bool:
p, o, e = Popen_safe([self.make, '--version'])
if p.returncode == 0 and 'GNU Make' in o:
return True
return False
def build(self):
def build(self) -> int:
make_cmd = [self.make]
if not self.verbose:
make_cmd.append('--quiet')
@ -73,7 +74,7 @@ class ExternalProject:
return 0
def _run(self, command):
def _run(self, command: T.List[str]) -> int:
output = None if self.verbose else subprocess.DEVNULL
p, o, e = Popen_safe(command, stderr=subprocess.STDOUT, stdout=output,
cwd=self.build_dir)

Loading…
Cancel
Save