From 3654872966689022fc4451d8354a28346aad8868 Mon Sep 17 00:00:00 2001 From: mickeyh Date: Thu, 15 Feb 2024 07:08:52 -0800 Subject: [PATCH] Fix hugo binary resolution on MacOS and Windows. Also impoves some minor quality of life improvements: - Only infer `os_arch` if it isn't provided to `hugo_repository`. - Update default Hugo version to 0.122.0 (the most recent). TESTED=manual: Successfully built a site on OSX and Windows. --- hugo/internal/hugo_repository.bzl | 33 ++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/hugo/internal/hugo_repository.bzl b/hugo/internal/hugo_repository.bzl index 6d4c5df..fb3e96e 100644 --- a/hugo/internal/hugo_repository.bzl +++ b/hugo/internal/hugo_repository.bzl @@ -1,8 +1,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -HUGO_BUILD_FILE = """ +HUGO_BUILD_FILE = """ package(default_visibility = ["//visibility:public"]) -exports_files( ["hugo"] ) +exports_files(["hugo"]) """ def _hugo_repository_impl(repository_ctx): @@ -11,18 +11,21 @@ def _hugo_repository_impl(repository_ctx): hugo = "hugo_extended" os_arch = repository_ctx.attr.os_arch - + archive_suffix = "tar.gz" os_name = repository_ctx.os.name.lower() - if os_name.startswith("mac os"): - os_arch = "macOS-64bit" - elif os_name.find("windows") != -1: - os_arch = "Windows-64bit" - else: - os_arch = "Linux-64bit" - - url = "https://github.com/gohugoio/hugo/releases/download/v{version}/{hugo}_{version}_{os_arch}.tar.gz".format( + if os_arch == "": + if os_name.startswith("mac os"): + os_arch = "darwin-universal" + elif os_name.find("windows") != -1: + os_arch = "windows-amd64" + archive_suffix = "zip" + else: + os_arch = "Linux-64bit" + + url = "https://github.com/gohugoio/hugo/releases/download/v{version}/{hugo}_{version}_{os_arch}.{archive_suffix}".format( hugo = hugo, os_arch = os_arch, + archive_suffix = archive_suffix, version = repository_ctx.attr.version, ) @@ -31,13 +34,19 @@ def _hugo_repository_impl(repository_ctx): sha256 = repository_ctx.attr.sha256, ) + # On Windows, the Hugo binary is named `hugo.exe`. We must symlink to + # `hugo` so that there is a consistent location for the binary across + # platforms. + if os_name.find("windows") != -1: + repository_ctx.symlink("hugo.exe", "hugo") + repository_ctx.file("BUILD.bazel", HUGO_BUILD_FILE) hugo_repository = repository_rule( _hugo_repository_impl, attrs = { "version": attr.string( - default = "0.55.5", + default = "0.122.0", doc = "The hugo version to use", ), "sha256": attr.string(