2024-01-27 03:36:04 +01:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import stat
|
|
|
|
import urllib.request
|
|
|
|
|
|
|
|
BUILDIFIER_VERSION = "v6.4.0"
|
2024-05-17 00:00:17 +02:00
|
|
|
RELEASE_URL = (
|
|
|
|
f"https://mdb-build-public.s3.amazonaws.com/bazel-buildifier-binaries/{BUILDIFIER_VERSION}/"
|
|
|
|
)
|
2024-01-27 03:36:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
def determine_platform():
|
|
|
|
syst = platform.system()
|
|
|
|
pltf = None
|
|
|
|
if syst == "Darwin":
|
|
|
|
pltf = "darwin"
|
|
|
|
elif syst == "Windows":
|
|
|
|
pltf = "windows"
|
|
|
|
elif syst == "Linux":
|
|
|
|
pltf = "linux"
|
|
|
|
else:
|
|
|
|
raise RuntimeError("Platform cannot be inferred.")
|
|
|
|
return pltf
|
|
|
|
|
|
|
|
|
|
|
|
def determine_architecture():
|
|
|
|
arch = None
|
|
|
|
machine = platform.machine()
|
|
|
|
if machine in ("AMD64", "x86_64"):
|
|
|
|
arch = "amd64"
|
|
|
|
elif machine in ("arm", "arm64", "aarch64"):
|
|
|
|
arch = "arm64"
|
|
|
|
else:
|
|
|
|
raise RuntimeError(f"Detected architecture is not supported: {machine}")
|
|
|
|
|
|
|
|
return arch
|
|
|
|
|
|
|
|
|
2024-09-24 16:14:22 +02:00
|
|
|
def download(download_location: str = "./"):
|
2024-01-27 03:36:04 +01:00
|
|
|
operating_system = determine_platform()
|
|
|
|
architechture = determine_architecture()
|
|
|
|
if operating_system == "windows" and architechture == "arm64":
|
|
|
|
raise RuntimeError("There are no published arm windows releases for buildifier.")
|
|
|
|
|
2024-09-24 16:14:22 +02:00
|
|
|
extension = ".exe" if operating_system == "windows" else ""
|
|
|
|
binary_name = f"buildifier-{operating_system}-{architechture}{extension}"
|
|
|
|
url = f"{RELEASE_URL}{binary_name}"
|
|
|
|
|
|
|
|
file_location = os.path.join(download_location, f"buildifier{extension}")
|
|
|
|
urllib.request.urlretrieve(url, file_location)
|
|
|
|
print(f"Downloaded buildifier from {url} to {file_location}")
|
|
|
|
os.chmod(file_location, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
|
|
|
print(f"Set user executable permissions on {file_location}")
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2024-01-27 03:36:04 +01:00
|
|
|
parser = argparse.ArgumentParser(
|
2024-05-17 00:00:17 +02:00
|
|
|
prog="DownloadBuildifier",
|
|
|
|
description="This downloads buildifier, it is intended for use in evergreen."
|
|
|
|
"This is our temperary solution to get bazel linting while we determine a "
|
|
|
|
"long-term solution for getting buildifier on evergreen/development hosts.",
|
|
|
|
)
|
2024-01-27 03:36:04 +01:00
|
|
|
|
2024-05-17 00:00:17 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"--download-location",
|
|
|
|
"-f",
|
|
|
|
help="Name of directory to download the buildifier binary to.",
|
|
|
|
default="./",
|
|
|
|
)
|
2024-01-27 03:36:04 +01:00
|
|
|
|
2024-09-24 16:14:22 +02:00
|
|
|
args = parser.parse_known_args()
|
2024-01-27 03:36:04 +01:00
|
|
|
|
2024-09-24 16:14:22 +02:00
|
|
|
download(download_location=args[0].download_location)
|
2024-01-27 03:36:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|