From 3fc37fc13e12779343ddaf830ebde7e096f77a41 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 28 Sep 2020 10:21:46 -0700 Subject: [PATCH] compilers/java: Add type annotations --- mesonbuild/compilers/java.py | 46 +++++++++++++++++------------------- run_mypy.py | 1 + 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/mesonbuild/compilers/java.py b/mesonbuild/compilers/java.py index 3b4d2f5a3..895173eb3 100644 --- a/mesonbuild/compilers/java.py +++ b/mesonbuild/compilers/java.py @@ -15,6 +15,7 @@ import os.path import shutil import subprocess +import textwrap import typing as T from ..mesonlib import EnvironmentException, MachineChoice @@ -23,44 +24,40 @@ from .mixins.islinker import BasicLinkerIsCompilerMixin if T.TYPE_CHECKING: from ..envconfig import MachineInfo + from ..environment import Environment class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler): language = 'java' - def __init__(self, exelist, version, for_machine: MachineChoice, - info: 'MachineInfo'): - super().__init__(exelist, version, for_machine, info) + def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, + info: 'MachineInfo', full_version: T.Optional[str] = None): + super().__init__(exelist, version, for_machine, info, full_version=full_version) self.id = 'unknown' self.javarunner = 'java' - def get_werror_args(self): + def get_werror_args(self) -> T.List[str]: return ['-Werror'] - def get_compile_only_args(self): - return [] - - def get_output_args(self, subdir): + def get_output_args(self, subdir: str) -> T.List[str]: if subdir == '': subdir = './' return ['-d', subdir, '-s', subdir] - def get_coverage_args(self): - return [] - - def get_pic_args(self): + def get_pic_args(self) -> T.List[str]: return [] - def get_pch_use_args(self, pch_dir, header): + def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: return [] - def get_pch_name(self, header_name): + def get_pch_name(self, name: str) -> str: return '' - def get_buildtype_args(self, buildtype): + def get_buildtype_args(self, buildtype: str) -> T.List[str]: return java_buildtype_args[buildtype] - def compute_parameters_with_absolute_paths(self, parameter_list, build_dir): + def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], + build_dir: str) -> T.List[str]: for idx, i in enumerate(parameter_list): if i in ['-cp', '-classpath', '-sourcepath'] and idx + 1 < len(parameter_list): path_list = parameter_list[idx + 1].split(os.pathsep) @@ -69,17 +66,18 @@ class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler): return parameter_list - def sanity_check(self, work_dir, environment): + def sanity_check(self, work_dir: str, environment: 'Environment') -> None: src = 'SanityCheck.java' obj = 'SanityCheck' source_name = os.path.join(work_dir, src) with open(source_name, 'w') as ofile: - ofile.write('''class SanityCheck { - public static void main(String[] args) { - int i; - } -} -''') + ofile.write(textwrap.dedent( + '''class SanityCheck { + public static void main(String[] args) { + int i; + } + } + ''')) pc = subprocess.Popen(self.exelist + [src], cwd=work_dir) pc.wait() if pc.returncode != 0: @@ -99,5 +97,5 @@ class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler): "all about it." raise EnvironmentException(m) - def needs_static_linker(self): + def needs_static_linker(self) -> bool: return False diff --git a/run_mypy.py b/run_mypy.py index 495b7d03e..673e01c2d 100755 --- a/run_mypy.py +++ b/run_mypy.py @@ -21,6 +21,7 @@ modules = [ 'mesonbuild/compilers/c_function_attributes.py', 'mesonbuild/compilers/cpp.py', 'mesonbuild/compilers/cuda.py', + 'mesonbuild/compilers/java.py', 'mesonbuild/compilers/objc.py', 'mesonbuild/compilers/objcpp.py', 'mesonbuild/compilers/rust.py',