Skip to content

Commit ad3de9c

Browse files
committed
[WIP] Tweak bazel settings on Windows
1 parent 57d6a61 commit ad3de9c

File tree

4 files changed

+135
-2
lines changed

4 files changed

+135
-2
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Keep the server alive for at most 8 hours of inactivity
44
startup --max_idle_secs=28800
5+
startup --windows_enable_symlinks
56

67
common --enable_platform_specific_config # Supported OS identifiers are linux, macos, windows, freebsd, and openbsd
78

.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 //bazel/buildifier

MODULE.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ 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.windows.patch"],
19+
)
1520

1621
bazel_dep(name = "rules_multitool", version = "1.9.0")
1722

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
diff --git a/buildifier/factory.bzl b/buildifier/factory.bzl
2+
index 6a8098c..f708ea3 100644
3+
--- a/buildifier/factory.bzl
4+
+++ b/buildifier/factory.bzl
5+
@@ -151,7 +151,7 @@ def buildifier_impl_factory(ctx, *, test_rule):
6+
7+
substitutions = {
8+
"@@ARGS@@": shell.array_literal(args) if out_ext == ".bash" else shell.array_literal(args)[1:][:-1].replace("'", ""),
9+
- "@@BUILDIFIER_SHORT_PATH@@": shell.quote(buildifier.short_path) if out_ext == ".bash" else buildifier.path,
10+
+ "@@BUILDIFIER_SHORT_PATH@@": shell.quote(buildifier.short_path) if out_ext == ".bash" else buildifier.short_path,
11+
"@@EXCLUDE_PATTERNS@@": exclude_patterns_str,
12+
"@@WORKSPACE@@": workspace,
13+
}
14+
diff --git a/runner.bat.template b/runner.bat.template
15+
index c27e34d..1c5600f 100644
16+
--- a/runner.bat.template
17+
+++ b/runner.bat.template
18+
@@ -1,4 +1,4 @@
19+
-@echo off
20+
+@echo on
21+
setlocal EnableDelayedExpansion
22+
23+
set BUILDIFIER_SHORT_PATH=@@BUILDIFIER_SHORT_PATH@@
24+
@@ -6,52 +6,80 @@ set EXTRA_ARGS=@@ARGS@@
25+
set WORKSPACE=@@WORKSPACE@@
26+
27+
REM When --enable_runfiles, we should be able to locate buildifier directly through symlink.
28+
-for %%I in (%BUILDIFIER_SHORT_PATH%) do set "buildifier_short_path=%%~fI"
29+
+set buildifier_path=%BUILDIFIER_SHORT_PATH:/=\%
30+
+for %%I in (%buildifier_path%) do (
31+
+ set "buildifier_path=%%~fI"
32+
+)
33+
34+
-REM If we can't find it, then parse the MANIFEST file to find buildifier.
35+
-if not exist !buildifier_short_path! (
36+
- if not exist MANIFEST (
37+
- echo Runfiles are not enabled, yet a MANIFEST file cannot be found
38+
- exit /b 1
39+
- )
40+
- type MANIFEST
41+
- for /F "tokens=1" %%F IN ('findstr /L /C:buildifier.exe MANIFEST') DO (
42+
- set "buildifier_short_path=%%~fF"
43+
+set manifest_path=MANIFEST
44+
+if not exist %manifest_path% (
45+
+ set manifest_path=..\MANIFEST
46+
+)
47+
+if not exist %manifest_path% (
48+
+ echo a MANIFEST file cannot be found
49+
+ exit /b 1
50+
+)
51+
+
52+
+REM find the workspace directory in manifest.
53+
+REM No good way in bat to read path of a symlink's target
54+
+set workspace_dir=
55+
+for /F "tokens=2 delims= " %%F IN ('findstr /l /c:"WORKSPACE" %manifest_path%') DO (
56+
+ set "workspace_dir=%%~dpF"
57+
+)
58+
+
59+
+REM If the buildifier isn't immediately available via short_path from
60+
+REM current directory, then parse the MANIFEST file to find buildifier.
61+
+if not exist !buildifier_path! (
62+
+ for /F "tokens=2 delims= " %%F IN ('findstr /l /c:"buildifier.exe" %manifest_path%') DO (
63+
+ set "buildifier_path=%%F"
64+
)
65+
)
66+
67+
-if not exist !buildifier_short_path! (
68+
- echo Failed to find buildifier at !buildifier_short_path!
69+
+if not exist !buildifier_path! (
70+
+ echo Failed to find buildifier at !buildifier_path!
71+
exit /b 1
72+
)
73+
74+
-if defined TEST_WORKSPACE (
75+
- if not defined BUILD_WORKSPACE_DIRECTORY (
76+
- if defined WORKSPACE (
77+
- cd "%WORKSPACE%"
78+
- ) else (
79+
- set follow_links=1
80+
- )
81+
+if defined BUILD_WORKSPACE_DIRECTORY (
82+
+ rem either a build, or a run/build inside a test
83+
+ echo cd %BUILD_WORKSPACE_DIRECTORY%
84+
+ cd %BUILD_WORKSPACE_DIRECTORY%
85+
+) else if defined TEST_WORKSPACE (
86+
+ if defined workspace_dir (
87+
+ echo cd: %workspace_dir%
88+
+ cd %workspace_dir%
89+
+ ) else (
90+
+ REM this path doesn't seem required in bazel 7.2; manifest is always present
91+
+ echo set follow_links=1
92+
+ set follow_links=1
93+
)
94+
) else (
95+
- cd "%BUILD_WORKSPACE_DIRECTORY%"
96+
+ echo Failed to find workspace to check
97+
)
98+
99+
call :collectFiles .
100+
101+
-!buildifier_short_path! %EXTRA_ARGS% !files_to_analyze!
102+
+if !files_to_analyze! == "" (
103+
+ echo Failed to find files to analyze
104+
+ exit /b 1
105+
+)
106+
+echo !buildifier_path! %EXTRA_ARGS% !files_to_analyze!
107+
+!buildifier_path! %EXTRA_ARGS% !files_to_analyze!
108+
109+
exit /b !ERRORLEVEL!
110+
111+
REM Utility function to collect all wanted files.
112+
REM Exclude patterns are not supported by `dir.exe`.
113+
:collectFiles
114+
-
115+
REM First, non-symlinked files
116+
pushd %~1
117+
+REM echo collecting in %cd%
118+
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 (
119+
- REM echo File %~1\%%f
120+
- set files_to_analyze=!files_to_analyze! %~1\%%f
121+
+ set FILE=%~1\%%f
122+
+ REM remove .\ prefix
123+
+ set FILE=!FILE:.\=!
124+
+ REM echo Found %~1\%%f adding !FILE!
125+
+ set files_to_analyze=!files_to_analyze! !FILE!
126+
)
127+
popd
128+

0 commit comments

Comments
 (0)