Skip to content

Commit 0a469c7

Browse files
committed
[WIP] Tweak bazel settings on Windows
1 parent a989aa7 commit 0a469c7

File tree

4 files changed

+126
-3
lines changed

4 files changed

+126
-3
lines changed

.gitlab/bazel/build-deps.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ bazel:build-deps:windows-amd64:
3636
ARCH: x64
3737
SCRIPT: |-
3838
echo "🟡 TODO(regis): compilation errors remain - limiting to a working subset for the time being"
39-
bazel build @zlib//...
40-
# bazel build @bzip2//...
39+
bazel run --enable_runfiles=yes //bazel/buildifier

MODULE.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ bazel_dep(name = "rules_pkg", version = "1.1.0")
1212
#########################
1313

1414
bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2", dev_dependency = True)
15+
single_version_override(
16+
module_name = "buildifier_prebuilt",
17+
patch_strip = 1,
18+
patches = ["//bazel/patches:buildifier_prebuilt.runner.bat.template.patch"],
19+
version = "8.2.0.2",
20+
)
1521

1622
bazel_dep(name = "rules_multitool", version = "1.9.0")
1723

MODULE.bazel.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
diff --git a/runner.bat.template b/runner.bat.template
2+
index c27e34d..13ca3fa 100644
3+
--- a/runner.bat.template
4+
+++ b/runner.bat.template
5+
@@ -1,71 +1,45 @@
6+
@echo off
7+
-setlocal EnableDelayedExpansion
8+
9+
-set BUILDIFIER_SHORT_PATH=@@BUILDIFIER_SHORT_PATH@@
10+
-set EXTRA_ARGS=@@ARGS@@
11+
-set WORKSPACE=@@WORKSPACE@@
12+
-
13+
-REM When --enable_runfiles, we should be able to locate buildifier directly through symlink.
14+
-for %%I in (%BUILDIFIER_SHORT_PATH%) do set "buildifier_short_path=%%~fI"
15+
-
16+
-REM If we can't find it, then parse the MANIFEST file to find buildifier.
17+
-if not exist !buildifier_short_path! (
18+
- if not exist MANIFEST (
19+
- echo Runfiles are not enabled, yet a MANIFEST file cannot be found
20+
- exit /b 1
21+
- )
22+
- type MANIFEST
23+
- for /F "tokens=1" %%F IN ('findstr /L /C:buildifier.exe MANIFEST') DO (
24+
- set "buildifier_short_path=%%~fF"
25+
- )
26+
-)
27+
-
28+
-if not exist !buildifier_short_path! (
29+
- echo Failed to find buildifier at !buildifier_short_path!
30+
- exit /b 1
31+
-)
32+
-
33+
-if defined TEST_WORKSPACE (
34+
- if not defined BUILD_WORKSPACE_DIRECTORY (
35+
- if defined WORKSPACE (
36+
- cd "%WORKSPACE%"
37+
- ) else (
38+
- set follow_links=1
39+
- )
40+
- )
41+
-) else (
42+
- cd "%BUILD_WORKSPACE_DIRECTORY%"
43+
-)
44+
-
45+
-call :collectFiles .
46+
-
47+
-!buildifier_short_path! %EXTRA_ARGS% !files_to_analyze!
48+
-
49+
-exit /b !ERRORLEVEL!
50+
-
51+
-REM Utility function to collect all wanted files.
52+
-REM Exclude patterns are not supported by `dir.exe`.
53+
-:collectFiles
54+
-
55+
-REM First, non-symlinked files
56+
-pushd %~1
57+
-FOR /F %%f IN ('dir /b/a:-d-l-h *.bzl *.sky *.bazel *.BUILD BUILD BUILD.*.oss WORKSPACE WORKSPACE.bzlmod WORKSPACE.oss WORKSPACE.*.oss 2^>nul') DO (
58+
- REM echo File %~1\%%f
59+
- set files_to_analyze=!files_to_analyze! %~1\%%f
60+
-)
61+
-popd
62+
-
63+
-REM Next, directories.
64+
-REM
65+
-REM Interestingly, turning on the exclude hidden files option (-h) excludes the
66+
-REM `.git` directory but not other directories starting with a `.` like
67+
-REM `.github` or `.bcr`. I don't know why it works this way, but hey it works.
68+
-if defined follow_links (
69+
- FOR /F %%d IN ('dir /b/a:d-h %~1 2^>nul') DO (
70+
- call :collectFiles "%~1\%%d"
71+
- )
72+
-) else (
73+
- FOR /F %%d IN ('dir /b/a:d-l-h %~1 2^>nul') DO (
74+
- call :collectFiles "%~1\%%d"
75+
- )
76+
-)
77+
+set ARGS=@@ARGS@@
78+
+
79+
+rem Remove the leading '(' and trailing ')' characters that surround the arguments
80+
+set stripped_args=%ARGS:~1,-1%
81+
+
82+
+rem Unquote the arguments
83+
+set stripped_args=%stripped_args:'=%
84+
+
85+
+rem Get the absolute path to the buildifier executable
86+
+for /f "tokens=2" %%i in ('findstr /r "\<buildifier\.exe\>" MANIFEST') do (set buildifier_abs_path=%%i)
87+
+
88+
+powershell ^
89+
+function Buildify($Root)^
90+
+{^
91+
+ $Folder = (New-Object -Com Scripting.FileSystemObject).GetFolder($Root);^
92+
+ $Files = $Folder.Files ^| Where-Object {^
93+
+ $_.Name -eq 'BUILD.bazel' `^
94+
+ -or $_.Name -eq 'BUILD' `^
95+
+ -or $_.Name -eq 'WORKSPACE' `^
96+
+ -or $_.Name -eq 'WORKSPACE.bazel' `^
97+
+ -or $_.Name -eq 'WORKSPACE.oss' `^
98+
+ -or $_.Name -clike '*.bzl' `^
99+
+ -or $_.Name -clike '*.sky' `^
100+
+ -or $_.Name -clike '*.BUILD' `^
101+
+ -or $_.Name -clike 'BUILD.*.bazel' `^
102+
+ -or $_.Name -clike 'BUILD.*.oss' `^
103+
+ -or $_.Name -clike 'WORKSPACE.*.bazel' `^
104+
+ -or $_.Name -clike 'WORKSPACE.*.oss'^
105+
+ };^
106+
+ foreach ($File in $Files)^
107+
+ {^
108+
+ ^& '%buildifier_abs_path%' %stripped_args% $File.Path;^
109+
+ };^
110+
+ foreach ($SubFolder in $Folder.Subfolders)^
111+
+ {^
112+
+ $CurrentItem = Get-Item $SubFolder.Path -ErrorAction SilentlyContinue;^
113+
+ if ($CurrentItem -and !$CurrentItem.Attributes.ToString().Contains('ReparsePoint'))^
114+
+ {^
115+
+ Buildify($SubFolder.Path);^
116+
+ };^
117+
+ };^
118+
+};^
119+
+Buildify('%BUILD_WORKSPACE_DIRECTORY%');

0 commit comments

Comments
 (0)