diff options
author | Haibo Huang <hhb@google.com> | 2020-03-23 16:21:36 -0700 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2020-03-24 15:20:03 -0700 |
commit | 75261ebb1ec687c3c360561bb4753cae1192f696 (patch) | |
tree | 189a8fd1fab0d41386c2611ee18eaa6977b8da1c /toolchains.py | |
parent | bb77d66ad61d94733f9498e2b13d6260bf4f2e82 (diff) | |
download | llvm_android-75261ebb1ec687c3c360561bb4753cae1192f696.tar.gz |
Refactor stage2
In this change I reverted some plain variables back to
@property method and throws NotImplementedError. Because this pattern
caused too many trouble with mypy and pylint.
Rather than # disable everywhere, I'd just fold and use @property.
Change-Id: I8660b6fb41ce89d9d5d3d159adce6feeb449eab8
Diffstat (limited to 'toolchains.py')
-rw-r--r-- | toolchains.py | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/toolchains.py b/toolchains.py index 37cbc89..3c747e1 100644 --- a/toolchains.py +++ b/toolchains.py @@ -20,26 +20,66 @@ from pathlib import Path import constants import hosts import paths +import version class Toolchain: """Base toolchain.""" - cc: Path # pylint: disable=invalid-name - cxx: Path path: Path + @property + def cc(self) -> Path: # pylint: disable=invalid-name + """Returns the path to c compiler.""" + raise NotImplementedError() + + @property + def cxx(self) -> Path: + """Returns the path to c++ compiler.""" + raise NotImplementedError() + + @property + def lib_dir(self) -> Path: + """Returns the path to lib dir.""" + raise NotImplementedError() + + def get_resource_dir(self, arch: str = '') -> Path: + """Returns resource dir path for an arch.""" + raise NotImplementedError() + class _HostToolchain(Toolchain): """Base toolchain that compiles host binary.""" + def __init__(self, path: Path) -> None: + self.path = path + @property - def cc(self) -> Path: # type: ignore + def cc(self) -> Path: # pylint: disable=invalid-name return self.path / 'bin' / 'clang' @property - def cxx(self) -> Path: # type: ignore + def cxx(self) -> Path: + """Returns the path to c++ compiler.""" return self.path / 'bin' / 'clang++' + @property + def lib_dir(self) -> Path: + """Returns the path to lib dir.""" + return self.path / 'lib64' + + @property + def _version_file(self) -> Path: + return self.path / 'include' / 'clang' / 'Basic'/ 'Version.inc' + + @property + def _version(self) -> version.Version: + return version.Version(self._version_file) + + def get_resource_dir(self, arch: str = '') -> Path: + """Returns the path to resource dir.""" + return (self.lib_dir / 'clang' / self._version.long_version() / + 'lib' / 'linux' / arch) + def _clang_prebuilt_path(host: hosts.Host) -> Path: """Returns the path to prebuilt clang toolchain.""" @@ -47,7 +87,11 @@ def _clang_prebuilt_path(host: hosts.Host) -> Path: host.os_tag / constants.CLANG_PREBUILT_VERSION) -class PrebuiltToolchain(_HostToolchain): - """A prebuilt toolchain used to build stage1.""" +def build_toolchain_for_path(path: Path) -> Toolchain: + """Returns a toolchain object for a given path.""" + return _HostToolchain(path) + - path: Path = _clang_prebuilt_path(hosts.build_host()) +def get_prebuilt_toolchain() -> Toolchain: + """Returns the prebuilt toolchain.""" + return build_toolchain_for_path(_clang_prebuilt_path(hosts.build_host())) |