| 239 | |
| 240 | |
| 241 | class ToolchainPackage(EnvVersionedPackage): |
| 242 | def __init__(self, name, explicit_version=None, platform_release=None): |
| 243 | toolchain_packages_home = os.environ.get("IMPALA_TOOLCHAIN_PACKAGES_HOME") |
| 244 | if not toolchain_packages_home: |
| 245 | logging.error("Impala environment not set up correctly, make sure " |
| 246 | "$IMPALA_TOOLCHAIN_PACKAGES_HOME is set.") |
| 247 | sys.exit(1) |
| 248 | target_comp = None |
| 249 | if ":" in name: |
| 250 | parts = name.split(':') |
| 251 | name = parts[0] |
| 252 | target_comp = parts[1] |
| 253 | compiler = get_toolchain_compiler() |
| 254 | label = get_platform_release_label(release=platform_release).toolchain |
| 255 | # Most common return values for machine are x86_64 or aarch64 |
| 256 | arch = platform.machine() |
| 257 | if arch not in ['aarch64', 'x86_64']: |
| 258 | raise Exception("Unsupported architecture '{}' for pre-built native-toolchain. " |
| 259 | "Fetch and build it locally by setting NATIVE_TOOLCHAIN_HOME".format(arch)) |
| 260 | toolchain_build_id = os.environ["IMPALA_TOOLCHAIN_BUILD_ID_{}".format(arch.upper())] |
| 261 | toolchain_host = os.environ["IMPALA_TOOLCHAIN_HOST"] |
| 262 | template_subs = {'compiler': compiler, 'label': label, 'arch': arch, |
| 263 | 'toolchain_build_id': toolchain_build_id, |
| 264 | 'toolchain_host': toolchain_host} |
| 265 | archive_basename_tmpl = "${name}-${version}-${compiler}-${label}-${arch}" |
| 266 | url_prefix_tmpl = "https://${toolchain_host}/build/${toolchain_build_id}/" + \ |
| 267 | "${name}/${version}-${compiler}/" |
| 268 | unpack_directory_tmpl = "${name}-${version}" |
| 269 | super(ToolchainPackage, self).__init__(name, url_prefix_tmpl, |
| 270 | toolchain_packages_home, |
| 271 | explicit_version=explicit_version, |
| 272 | archive_basename_tmpl=archive_basename_tmpl, |
| 273 | unpack_directory_tmpl=unpack_directory_tmpl, |
| 274 | template_subs_in=template_subs, |
| 275 | target_comp=target_comp) |
| 276 | |
| 277 | def needs_download(self): |
| 278 | # If the directory doesn't exist, we need the download |
| 279 | unpack_dir = self.pkg_directory() |
| 280 | if not os.path.isdir(unpack_dir): return True |
| 281 | version_file = os.path.join(unpack_dir, "toolchain_package_version.txt") |
| 282 | if not os.path.exists(version_file): return True |
| 283 | with open(version_file, "r") as f: |
| 284 | return f.read().strip() != self.archive_basename |
| 285 | |
| 286 | def download(self): |
| 287 | # Remove the existing package directory if it exists (since this has additional |
| 288 | # conditions as part of needs_download()) |
| 289 | unpack_dir = self.pkg_directory() |
| 290 | if os.path.exists(unpack_dir): |
| 291 | logging.info("Removing existing package directory {0}".format(unpack_dir)) |
| 292 | shutil.rmtree(unpack_dir) |
| 293 | super(ToolchainPackage, self).download() |
| 294 | # Write the toolchain_package_version.txt file |
| 295 | version_file = os.path.join(unpack_dir, "toolchain_package_version.txt") |
| 296 | with open(version_file, "w") as f: |
| 297 | f.write(self.archive_basename) |
| 298 |
no outgoing calls
no test coverage detected