in toolchains/prebuilt_toolchains.py [0:0]
def get_cmake_definitions() -> str:
"""Define a set of repositories and calls for registering `cmake` toolchains
Returns:
str: The Implementation of `_cmake_toolchains`
"""
archives = []
for version in CMAKE_VERSIONS:
major, minor, _patch = version.split(".")
version_archives = []
version_toolchains = {}
minor_version = "{}.{}".format(major, minor)
for line in urllib.request.urlopen(CMAKE_SHA256_URL_TEMPLATE.format(minor=minor_version, full=version)).readlines():
line = line.decode("utf-8").strip("\n ")
# Only take tar and zip files. The rest can't be easily decompressed.
if not line.endswith(".tar.gz") and not line.endswith(".zip"):
continue
# Only include the targets we care about.
plat_target = None
for target in CMAKE_TARGETS.keys():
if target in line:
plat_target = target
break
if not plat_target:
continue
sha256, file = line.split()
name = file.replace(".tar.gz", "").replace(".zip", "")
bin = "cmake.exe" if "win" in file.lower() else "cmake"
if "Darwin" in file or "macos" in file:
prefix = name + "/CMake.app/Contents"
else:
prefix = name
version_archives.append(
REPO_DEFINITION.format(
name=name,
sha256=sha256,
prefix=prefix,
url=CMAKE_URL_TEMPLATE.format(
full=version,
file=file
),
build="cmake",
template="_CMAKE_BUILD_FILE",
bin=bin,
)
)
version_toolchains.update({plat_target: name})
archives.append("\n".join(
[
" if \"{}\" == version:".format(version),
] + [indent(archive, " " * 8) for archive in version_archives])
)
toolchains_repos = {}
for target, name in version_toolchains.items():
toolchains_repos.update({name: CMAKE_TARGETS[target]})
archives.append(indent(TOOLCHAIN_REPO_DEFINITION.format(
name="cmake_{}_toolchains".format(version),
repos=indent(json.dumps(toolchains_repos, indent=4), " " * 4).lstrip(),
tool="cmake",
), " " * 8))
archives.append(indent(REGISTER_TOOLCHAINS.format(
toolchains="\n".join(
[indent("\"@cmake_{}_toolchains//:{}_toolchain\",".format(
version,
repo
), " " * 8) for repo in toolchains_repos])
), " " * 8))
archives.extend([
indent("return", " " * 8),
"",
])
archives.append(
indent("fail(\"Unsupported version: \" + str(version))", " " * 4))
return "\n".join([archive.rstrip(" ") for archive in archives])