Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion extension/download_tool.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ def _get_platform(rctx):

return "{}-{}".format(os_key, arch_key)

def _binary_path_for_platform(binary_subpath, platform):
"""Return the binary path as packaged for the selected platform."""
if platform.startswith("windows-") and not binary_subpath.endswith(".exe"):
return binary_subpath + ".exe"
return binary_subpath

# Exposed only so the path resolution can be covered without downloading LLVM.
download_tool_test_utils = struct(
binary_path_for_platform = _binary_path_for_platform,
)

def _download_tool_impl(rctx):
"""Download and extract a tool for the current platform."""
platform = _get_platform(rctx)
Expand Down Expand Up @@ -56,7 +67,7 @@ def _download_tool_impl(rctx):
)

# Create BUILD.bazel that exports the tool binary
binary_path = rctx.attr.binary_subpath
binary_path = _binary_path_for_platform(rctx.attr.binary_subpath, platform)
rctx.file("BUILD.bazel", content = """
package(default_visibility = ["//visibility:public"])

Expand Down
3 changes: 3 additions & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Unit tests for the devtools runtime scripts."""

load("@rules_python//python:py_test.bzl", "py_test")
load(":download_tool_test.bzl", "download_tool_test_suite")

download_tool_test_suite(name = "download_tool_tests")

py_test(
name = "compile_commands_test",
Expand Down
34 changes: 34 additions & 0 deletions tests/download_tool_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Tests for platform-specific LLVM binary paths."""

load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
load("//extension:download_tool.bzl", "download_tool_test_utils")

def _windows_binary_path_test_impl(ctx):
env = unittest.begin(ctx)
binary_path = download_tool_test_utils.binary_path_for_platform

asserts.equals(env, "bin/clang-format.exe", binary_path("bin/clang-format", "windows-x86_64"))
asserts.equals(env, "bin/clang-tidy.exe", binary_path("bin/clang-tidy", "windows-x86_64"))
asserts.equals(env, "bin/custom-tool.exe", binary_path("bin/custom-tool.exe", "windows-x86_64"))

return unittest.end(env)

windows_binary_path_test = unittest.make(_windows_binary_path_test_impl)

def _unix_binary_path_test_impl(ctx):
env = unittest.begin(ctx)
binary_path = download_tool_test_utils.binary_path_for_platform

asserts.equals(env, "bin/clang-format", binary_path("bin/clang-format", "linux-x86_64"))
asserts.equals(env, "bin/clang-tidy", binary_path("bin/clang-tidy", "darwin-aarch64"))

return unittest.end(env)

unix_binary_path_test = unittest.make(_unix_binary_path_test_impl)

def download_tool_test_suite(name):
unittest.suite(
name,
windows_binary_path_test,
unix_binary_path_test,
)