blob: 47d71d68140b698957aec2b01dfb51dd25b69e74 [file] [log] [blame]
Brian Silverman7d89e282021-11-17 17:36:54 -08001#!/usr/bin/env python3
2# Copyright 2018 The Bazel Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15"""LLVM pre-built distribution file names."""
16
17import platform
18import sys
19
20_known_distros = ["freebsd", "suse", "ubuntu", "arch", "manjaro", "debian", "fedora", "centos", "amzn", "raspbian"]
21
22def _major_llvm_version(llvm_version):
23 return int(llvm_version.split(".")[0])
24
25def _minor_llvm_version(llvm_version):
26 return int(llvm_version.split(".")[1])
27
28def _darwin(llvm_version, arch):
29 major_llvm_version = _major_llvm_version(llvm_version)
30 suffix = "darwin-apple" if major_llvm_version == 9 else "apple-darwin"
31 return "clang+llvm-{llvm_version}-{arch}-{suffix}.tar.xz".format(
32 llvm_version=llvm_version, arch=arch, suffix=suffix)
33
34def _windows(llvm_version, arch):
35 if arch.endswith('64'):
36 win_arch = "win64"
37 else:
38 win_arch = "win32"
39
40 return "LLVM-{llvm_version}-{win_arch}.exe".format(
41 llvm_version=llvm_version,
42 win_arch=win_arch)
43
44def _ubuntu_osname(arch, version, major_llvm_version, llvm_version):
45 if arch == "powerpc64le":
46 if major_llvm_version > 11:
47 return "linux-gnu-ubuntu-18.04"
48 else:
49 return "linux-gnu-ubuntu-16.04"
50
51 os_name = "linux-gnu-ubuntu-16.04"
52
53 if version.startswith("20.10") and (llvm_version in ["11.0.1", "11.1.0"]):
54 os_name = "linux-gnu-ubuntu-20.10"
55 elif version.startswith("20"):
56 if major_llvm_version < 11 or llvm_version in ["11.0.1", "11.1.0"]:
57 # There is no binary packages specifically for 20.04, but those for 18.04 works on
58 # 20.04
59 os_name = "linux-gnu-ubuntu-18.04"
60 elif major_llvm_version > 11:
61 # release 11.0.0 started providing packaging for ubuntu 20.04.
62 os_name = "linux-gnu-ubuntu-20.04"
63 elif version.startswith("18"):
64 if llvm_version in ["8.0.0", "9.0.0", "10.0.0"]:
65 os_name = "linux-gnu-ubuntu-18.04"
66 else:
67 os_name = "linux-gnu-ubuntu-16.04"
68
69 return os_name
70
71def _linux(llvm_version, arch):
72 release_file_path = "/etc/os-release"
73 with open(release_file_path) as release_file:
74 lines = release_file.readlines()
75 info = dict()
76 for line in lines:
77 line = line.strip()
78 if not line:
79 continue
80 [key, val] = line.split('=', 1)
81 info[key] = val
82 if "ID" not in info:
83 sys.exit("Could not find ID in /etc/os-release.")
84 distname = info["ID"].strip('\"')
85
86 if distname not in _known_distros:
87 for distro in info["ID_LIKE"].strip('\"').split(' '):
88 if distro in _known_distros:
89 distname = distro
90 break
91
92 version = None
93 if "VERSION_ID" in info:
94 version = info["VERSION_ID"].strip('"')
95
96 major_llvm_version = _major_llvm_version(llvm_version)
97
98 # NOTE: Many of these systems are untested because I do not have access to them.
99 # If you find this mapping wrong, please send a Pull Request on Github.
100 if arch in ["aarch64", "armv7a", "mips", "mipsel"]:
101 os_name = "linux-gnu"
102 elif distname == "freebsd":
103 os_name = "unknown-freebsd-%s" % version
104 elif distname == "suse":
105 os_name = _resolve_version_for_suse(major_llvm_version, _minor_llvm_version(llvm_version))
106 elif distname == "ubuntu":
107 os_name = _ubuntu_osname(arch, version, major_llvm_version, llvm_version)
108 elif ((distname in ["linuxmint", "pop"]) and (version.startswith("20") or version.startswith("19"))):
109 if major_llvm_version < 11 or llvm_version in ["11.0.1", "11.1.0"]:
110 # There is no binary packages specifically for 20.04, but those for 18.04 works on
111 # 20.04
112 os_name = "linux-gnu-ubuntu-18.04"
113 else:
114 # release 11.0.0 started providing packaging for ubuntu 20.04.
115 os_name = "linux-gnu-ubuntu-20.04"
116 elif distname in ["manjaro"] or (distname == "linuxmint" and version.startswith("18")):
117 os_name = "linux-gnu-ubuntu-16.04"
118 elif distname == "debian":
119 int_version = None
120 try:
121 int_version = int(version)
122 except ValueError:
123 pass
124 if int_version is None or int_version >= 10:
125 if major_llvm_version < 11 or llvm_version in ["11.0.1", "11.1.0"]:
126 os_name = "linux-gnu-ubuntu-18.04"
127 else:
128 os_name = "linux-gnu-ubuntu-20.04"
129 elif int_version == 9 and major_llvm_version >= 7:
130 os_name = "linux-gnu-ubuntu-16.04"
131 elif int_version == 8 and major_llvm_version < 7:
132 os_name = "linux-gnu-debian8"
133 elif ((distname == "fedora" and int(version) >= 27) or
134 (distname == "centos" and int(version) >= 7)) and major_llvm_version < 7:
135 os_name = "linux-gnu-Fedora27"
136 elif distname == "centos" and major_llvm_version >= 7:
137 os_name = "linux-sles11.3"
138 elif distname == "fedora" and major_llvm_version >= 7:
139 if major_llvm_version < 11 or llvm_version in ["11.0.1", "11.1.0"]:
140 os_name = "linux-gnu-ubuntu-18.04"
141 else:
142 os_name = "linux-gnu-ubuntu-20.04"
143 elif distname == "arch" and major_llvm_version >= 11:
144 os_name = "linux-gnu-ubuntu-20.04"
145 elif distname == "arch" and major_llvm_version >= 10:
146 os_name = "linux-gnu-ubuntu-18.04"
147 elif distname == "arch" and major_llvm_version >= 7:
148 os_name = "linux-gnu-ubuntu-16.04"
149 elif distname == "amzn":
150 # Based on the ID_LIKE field, sles seems like the closest available
151 # distro for which LLVM releases are widely available.
152 if major_llvm_version >= 11:
153 os_name = "linux-sles12.4"
154 else:
155 os_name = "linux-sles11.3"
156 elif distname == "raspbian":
157 arch = "armv7a"
158 os_name = "linux-gnueabihf"
159 else:
160 sys.exit("Unsupported linux distribution and version: %s, %s" % (distname, version))
161
162 return "clang+llvm-{llvm_version}-{arch}-{os_name}.tar.xz".format(
163 llvm_version=llvm_version,
164 arch=arch,
165 os_name=os_name)
166
167def _resolve_version_for_suse(major_llvm_version, minor_llvm_version):
168 if major_llvm_version < 10:
169 os_name = "linux-sles11.3"
170 elif major_llvm_version == 10 and minor_llvm_version == 0:
171 os_name = "linux-sles11.3"
172 else:
173 os_name = "linux-sles12.4"
174 return os_name
175
176def main():
177 """Prints the pre-built distribution file name."""
178
179 if len(sys.argv) != 2:
180 sys.exit("Usage: %s llvm_version" % sys.argv[0])
181
182 llvm_version = sys.argv[1]
183
184 system = platform.system()
185 arch = platform.machine()
186
187 if system == "Darwin":
188 print(_darwin(llvm_version, arch))
189 sys.exit()
190
191 if system == "Windows":
192 print(_windows(llvm_version, arch))
193 sys.exit()
194
195 if system == "Linux":
196 print(_linux(llvm_version, arch))
197 sys.exit()
198
199 sys.exit("Unsupported system: %s" % system)
200
201if __name__ == '__main__':
202 main()