-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolchains.py
145 lines (116 loc) · 4.16 KB
/
toolchains.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#
# Copyright (C) 2020 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""APIs for accessing toolchains."""
import functools
from pathlib import Path
from typing import List
from builder_registry import BuilderRegistry
import paths
import version
class Toolchain:
"""Base toolchain."""
path: Path
build_path: Path
def __init__(self, path: Path, build_path: Path) -> None:
self.path = path
self.build_path = build_path
@property
def cc(self) -> Path: # pylint: disable=invalid-name
"""Returns the path to c compiler."""
return self.path / 'bin' / 'clang'
@property
def cxx(self) -> Path:
"""Returns the path to c++ compiler."""
return self.path / 'bin' / 'clang++'
@property
def cl(self) -> Path:
"""Returns the path to windows c++ compiler."""
return self.path / 'bin' / 'clang-cl'
@property
def ar(self) -> Path:
"""Returns the path to llvm-ar."""
return self.path / 'bin' / 'llvm-ar'
@property
def lipo(self) -> Path:
"""Returns the path to llvm-lipo."""
return self.path / 'bin' / 'llvm-lipo'
@property
def lld(self) -> Path:
"""Returns the path to ld.lld."""
return self.path / 'bin' / 'ld.lld'
@property
def lld_link(self) -> Path:
"""Returns the path to lld-link."""
return self.path / 'bin' / 'lld-link'
@property
def rc(self) -> Path:
"""Returns the path to llvm-windres."""
return self.path / 'bin' / 'llvm-windres'
@property
def ranlib(self) -> Path:
"""Returns the path to llvm-ranlib."""
return self.path / 'bin' / 'llvm-ranlib'
@property
def addr2line(self) -> Path:
"""Returns the path to llvm-addr2line."""
return self.path / 'bin' / 'llvm-addr2line'
@property
def nm(self) -> Path:
"""Returns the path to llvm-nm."""
return self.path / 'bin' / 'llvm-nm'
@property
def objcopy(self) -> Path:
"""Returns the path to llvm-objcopy."""
return self.path / 'bin' / 'llvm-objcopy'
@property
def objdump(self) -> Path:
"""Returns the path to llvm-objdump."""
return self.path / 'bin' / 'llvm-objdump'
@property
def readelf(self) -> Path:
"""Returns the path to llvm-readelf."""
return self.path / 'bin' / 'llvm-readelf'
@property
def mt(self) -> Path:
"""Returns the path to llvm-mt."""
return self.path / 'bin' / 'llvm-mt'
@property
def strip(self) -> Path:
"""Returns the path to llvm-strip."""
return self.path / 'bin' / 'llvm-strip'
@property
def lib_dirs(self) -> List[Path]:
"""Returns the paths to lib dirs."""
return [self.path / 'lib', self.path / 'lib' / 'x86_64-unknown-linux-gnu', self.path / 'lib' / 'x86_64-unknown-linux-musl']
@property
def _version_file(self) -> Path:
return self.path / 'include' / 'clang' / 'Basic'/ 'Version.inc'
@functools.cached_property
def version(self) -> version.Version:
return version.Version(self._version_file)
@property
def clang_lib_dir(self) -> Path:
return self.lib_dirs[0] / 'clang' / self.version.major_version()
@property
def clang_builtin_header_dir(self) -> Path:
return self.clang_lib_dir / 'include'
@property
def libcxx_headers(self) -> Path:
return self.path / 'include' / 'c++' / 'v1'
def get_prebuilt_toolchain() -> Toolchain:
"""Returns the prebuilt toolchain."""
# Prebuilt toolchain doesn't have a build path. Use a temp path instead.
return Toolchain(paths.CLANG_PREBUILT_DIR, Path('.'))