python: add type hints
This commit is contained in:
@ -1,17 +1,19 @@
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from typing import Optional, TextIO
|
||||
from collections.abc import Mapping
|
||||
|
||||
from build.project import Project
|
||||
|
||||
def __write_cmake_compiler(f, language, compiler):
|
||||
def __write_cmake_compiler(f: TextIO, language: str, compiler: str) -> None:
|
||||
s = compiler.split(' ', 1)
|
||||
if len(s) == 2:
|
||||
print(f'set(CMAKE_{language}_COMPILER_LAUNCHER {s[0]})', file=f)
|
||||
compiler = s[1]
|
||||
print(f'set(CMAKE_{language}_COMPILER {compiler})', file=f)
|
||||
|
||||
def __write_cmake_toolchain_file(f, toolchain):
|
||||
def __write_cmake_toolchain_file(f: TextIO, toolchain) -> None:
|
||||
if '-darwin' in toolchain.actual_arch:
|
||||
cmake_system_name = 'Darwin'
|
||||
elif toolchain.is_windows:
|
||||
@ -52,7 +54,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
""")
|
||||
|
||||
def configure(toolchain, src, build, args=(), env=None):
|
||||
def configure(toolchain, src: str, build: str, args: list[str]=[], env: Optional[Mapping[str, str]]=None) -> None:
|
||||
cross_args = []
|
||||
|
||||
if toolchain.is_windows:
|
||||
@ -91,16 +93,17 @@ def configure(toolchain, src, build, args=(), env=None):
|
||||
subprocess.check_call(configure, env=env, cwd=build)
|
||||
|
||||
class CmakeProject(Project):
|
||||
def __init__(self, url, md5, installed, configure_args=[],
|
||||
windows_configure_args=[],
|
||||
env=None,
|
||||
def __init__(self, url: str, md5: str, installed: str,
|
||||
configure_args: list[str]=[],
|
||||
windows_configure_args: list[str]=[],
|
||||
env: Optional[Mapping[str, str]]=None,
|
||||
**kwargs):
|
||||
Project.__init__(self, url, md5, installed, **kwargs)
|
||||
self.configure_args = configure_args
|
||||
self.windows_configure_args = windows_configure_args
|
||||
self.env = env
|
||||
|
||||
def configure(self, toolchain):
|
||||
def configure(self, toolchain) -> str:
|
||||
src = self.unpack(toolchain)
|
||||
build = self.make_build_path(toolchain)
|
||||
configure_args = self.configure_args
|
||||
@ -109,7 +112,7 @@ class CmakeProject(Project):
|
||||
configure(toolchain, src, build, configure_args, self.env)
|
||||
return build
|
||||
|
||||
def _build(self, toolchain):
|
||||
def _build(self, toolchain) -> None:
|
||||
build = self.configure(toolchain)
|
||||
subprocess.check_call(['ninja', '-v', 'install'],
|
||||
cwd=build, env=toolchain.env)
|
||||
|
Reference in New Issue
Block a user