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
6 changes: 5 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "ht
http_archive(
name = "com_github_bazelbuild_buildtools",
patch_strip = 1,
patches = ["//bazel/patches:buildifier.patch"],
patches = [
"//bazel/patches:buildifier-build.patch", # https://github.com/bazelbuild/buildtools/pull/1398
"//bazel/patches:buildifier-internal-factory.patch", # https://github.com/bazelbuild/buildtools/pull/1399
"//bazel/patches:buildifier-runner-bat-template.patch", # ^ https://github.com/bazelbuild/buildtools/pull/1400
],
sha256 = "53119397bbce1cd7e4c590e117dcda343c2086199de62932106c80733526c261",
strip_prefix = "buildtools-8.2.1",
urls = ["https://github.com/bazelbuild/buildtools/archive/refs/tags/v8.2.1.tar.gz"],
Expand Down
3 changes: 1 addition & 2 deletions bazel/buildifier/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier", "buildifier_test")

exclude_patterns = [
"./.bazelbsp/**",
"./.cache/**",
"./.*", # all "hidden" directories at the root of the workspace: ./.bazelbsp, ./.cache, ./.git, etc.
]

buildifier(
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions bazel/patches/buildifier-internal-factory.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/buildifier/internal/factory.bzl b/buildifier/internal/factory.bzl
index 0ad56ff..c33f0b6 100644
--- a/buildifier/internal/factory.bzl
+++ b/buildifier/internal/factory.bzl
@@ -161,4 +161,8 @@ def buildifier_impl_factory(ctx, test_rule = False):
fail("Cannot use 'exclude_patterns' in a test rule without 'no_sandbox'")
- exclude_patterns = ["\\! -path %s" % shell.quote(pattern) for pattern in ctx.attr.exclude_patterns]
- exclude_patterns_str = " ".join(exclude_patterns)
+ if ctx.executable.buildifier.extension.lower() == "exe":
+ exclude_patterns = [shell.quote(pattern.replace("/", "\\")) for pattern in ctx.attr.exclude_patterns]
+ exclude_patterns_str = ", ".join(exclude_patterns)
+ else:
+ exclude_patterns = ["\\! -path %s" % shell.quote(pattern) for pattern in ctx.attr.exclude_patterns]
+ exclude_patterns_str = " ".join(exclude_patterns)

48 changes: 48 additions & 0 deletions bazel/patches/buildifier-runner-bat-template.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
diff --git a/buildifier/runner.bat.template b/buildifier/runner.bat.template
index 13ca3fa..d8ccac9 100644
--- a/buildifier/runner.bat.template
+++ b/buildifier/runner.bat.template
@@ -11,9 +11,34 @@ set stripped_args=%stripped_args:'=%
rem Get the absolute path to the buildifier executable
-for /f "tokens=2" %%i in ('findstr /r "\<buildifier\.exe\>" MANIFEST') do (set buildifier_abs_path=%%i)
+if exist MANIFEST (
+ set manifest_file=MANIFEST
+) else if exist "%RUNFILES_MANIFEST_FILE%" (
+ set "manifest_file=%RUNFILES_MANIFEST_FILE:/=\%"
+) else (
+ >&2 echo Error: manifest file not found
+ exit /b 1
+)
+for /f "tokens=2" %%i in ('findstr /r "\<buildifier\.exe\>" "%manifest_file%"') do (set buildifier_abs_path=%%i)

powershell ^
+function Should-Exclude($Path)^
+{^
+ $relPath = '.' + $Path.Substring('%BUILD_WORKSPACE_DIRECTORY%'.Length);^
+ foreach ($pattern in @(@@EXCLUDE_PATTERNS@@))^
+ {^
+ if ($relPath -clike $pattern)^
+ {^
+ return $true;^
+ };^
+ };^
+ return $false;^
+};^
function Buildify($Root)^
{^
+ if (Should-Exclude $Root)^
+ {^
+ return;^
+ };^
$Folder = (New-Object -Com Scripting.FileSystemObject).GetFolder($Root);^
$Files = $Folder.Files ^| Where-Object {^
+ (^
$_.Name -eq 'BUILD.bazel' `^
@@ -30,2 +55,3 @@ function Buildify($Root)^
-or $_.Name -clike 'WORKSPACE.*.oss'^
+ ) -and -not (Should-Exclude $_.Path)^
};^
@@ -44,2 +70,2 @@ function Buildify($Root)^
};^
-Buildify('%BUILD_WORKSPACE_DIRECTORY%');
+Buildify('%BUILD_WORKSPACE_DIRECTORY:/=\%');