|
| 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..1544c66 100644 |
| 16 | +--- a/runner.bat.template |
| 17 | ++++ b/runner.bat.template |
| 18 | +@@ -1,71 +1,71 @@ |
| 19 | +-@echo off |
| 20 | +-setlocal EnableDelayedExpansion |
| 21 | +- |
| 22 | +-set BUILDIFIER_SHORT_PATH=@@BUILDIFIER_SHORT_PATH@@ |
| 23 | +-set EXTRA_ARGS=@@ARGS@@ |
| 24 | +-set WORKSPACE=@@WORKSPACE@@ |
| 25 | +- |
| 26 | +-REM When --enable_runfiles, we should be able to locate buildifier directly through symlink. |
| 27 | +-for %%I in (%BUILDIFIER_SHORT_PATH%) do set "buildifier_short_path=%%~fI" |
| 28 | +- |
| 29 | +-REM If we can't find it, then parse the MANIFEST file to find buildifier. |
| 30 | +-if not exist !buildifier_short_path! ( |
| 31 | +- if not exist MANIFEST ( |
| 32 | +- echo Runfiles are not enabled, yet a MANIFEST file cannot be found |
| 33 | +- exit /b 1 |
| 34 | +- ) |
| 35 | +- type MANIFEST |
| 36 | +- for /F "tokens=1" %%F IN ('findstr /L /C:buildifier.exe MANIFEST') DO ( |
| 37 | +- set "buildifier_short_path=%%~fF" |
| 38 | +- ) |
| 39 | +-) |
| 40 | +- |
| 41 | +-if not exist !buildifier_short_path! ( |
| 42 | +- echo Failed to find buildifier at !buildifier_short_path! |
| 43 | +- exit /b 1 |
| 44 | +-) |
| 45 | +- |
| 46 | +-if defined TEST_WORKSPACE ( |
| 47 | +- if not defined BUILD_WORKSPACE_DIRECTORY ( |
| 48 | +- if defined WORKSPACE ( |
| 49 | +- cd "%WORKSPACE%" |
| 50 | +- ) else ( |
| 51 | +- set follow_links=1 |
| 52 | +- ) |
| 53 | +- ) |
| 54 | +-) else ( |
| 55 | +- cd "%BUILD_WORKSPACE_DIRECTORY%" |
| 56 | +-) |
| 57 | +- |
| 58 | +-call :collectFiles . |
| 59 | +- |
| 60 | +-!buildifier_short_path! %EXTRA_ARGS% !files_to_analyze! |
| 61 | +- |
| 62 | +-exit /b !ERRORLEVEL! |
| 63 | +- |
| 64 | +-REM Utility function to collect all wanted files. |
| 65 | +-REM Exclude patterns are not supported by `dir.exe`. |
| 66 | +-:collectFiles |
| 67 | +- |
| 68 | +-REM First, non-symlinked files |
| 69 | +-pushd %~1 |
| 70 | +-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 ( |
| 71 | +- REM echo File %~1\%%f |
| 72 | +- set files_to_analyze=!files_to_analyze! %~1\%%f |
| 73 | +-) |
| 74 | +-popd |
| 75 | +- |
| 76 | +-REM Next, directories. |
| 77 | +-REM |
| 78 | +-REM Interestingly, turning on the exclude hidden files option (-h) excludes the |
| 79 | +-REM `.git` directory but not other directories starting with a `.` like |
| 80 | +-REM `.github` or `.bcr`. I don't know why it works this way, but hey it works. |
| 81 | +-if defined follow_links ( |
| 82 | +- FOR /F %%d IN ('dir /b/a:d-h %~1 2^>nul') DO ( |
| 83 | +- call :collectFiles "%~1\%%d" |
| 84 | +- ) |
| 85 | +-) else ( |
| 86 | +- FOR /F %%d IN ('dir /b/a:d-l-h %~1 2^>nul') DO ( |
| 87 | +- call :collectFiles "%~1\%%d" |
| 88 | +- ) |
| 89 | +-) |
| 90 | ++@echo on |
| 91 | ++setlocal EnableDelayedExpansion |
| 92 | ++ |
| 93 | ++set BUILDIFIER_SHORT_PATH=@@BUILDIFIER_SHORT_PATH@@ |
| 94 | ++set EXTRA_ARGS=@@ARGS@@ |
| 95 | ++set WORKSPACE=@@WORKSPACE@@ |
| 96 | ++ |
| 97 | ++REM When --enable_runfiles, we should be able to locate buildifier directly through symlink. |
| 98 | ++for %%I in (%BUILDIFIER_SHORT_PATH%) do set "buildifier_short_path=%%~fI" |
| 99 | ++ |
| 100 | ++REM If we can't find it, then parse the MANIFEST file to find buildifier. |
| 101 | ++if not exist !buildifier_short_path! ( |
| 102 | ++ if not exist MANIFEST ( |
| 103 | ++ echo Runfiles are not enabled, yet a MANIFEST file cannot be found |
| 104 | ++ exit /b 1 |
| 105 | ++ ) |
| 106 | ++ type MANIFEST |
| 107 | ++ for /F "tokens=1" %%F IN ('findstr /L /C:buildifier.exe MANIFEST') DO ( |
| 108 | ++ set "buildifier_short_path=%%~fF" |
| 109 | ++ ) |
| 110 | ++) |
| 111 | ++ |
| 112 | ++if not exist !buildifier_short_path! ( |
| 113 | ++ echo Failed to find buildifier at !buildifier_short_path! |
| 114 | ++ exit /b 1 |
| 115 | ++) |
| 116 | ++ |
| 117 | ++if defined TEST_WORKSPACE ( |
| 118 | ++ if not defined BUILD_WORKSPACE_DIRECTORY ( |
| 119 | ++ if defined WORKSPACE ( |
| 120 | ++ cd "%WORKSPACE%" |
| 121 | ++ ) else ( |
| 122 | ++ set follow_links=1 |
| 123 | ++ ) |
| 124 | ++ ) |
| 125 | ++) else ( |
| 126 | ++ cd "%BUILD_WORKSPACE_DIRECTORY%" |
| 127 | ++) |
| 128 | ++ |
| 129 | ++call :collectFiles . |
| 130 | ++ |
| 131 | ++!buildifier_short_path! %EXTRA_ARGS% !files_to_analyze! |
| 132 | ++ |
| 133 | ++exit /b !ERRORLEVEL! |
| 134 | ++ |
| 135 | ++REM Utility function to collect all wanted files. |
| 136 | ++REM Exclude patterns are not supported by `dir.exe`. |
| 137 | ++:collectFiles |
| 138 | ++ |
| 139 | ++REM First, non-symlinked files |
| 140 | ++pushd %~1 |
| 141 | ++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 ( |
| 142 | ++ REM echo File %~1\%%f |
| 143 | ++ set files_to_analyze=!files_to_analyze! %~1\%%f |
| 144 | ++) |
| 145 | ++popd |
| 146 | ++ |
| 147 | ++REM Next, directories. |
| 148 | ++REM |
| 149 | ++REM Interestingly, turning on the exclude hidden files option (-h) excludes the |
| 150 | ++REM `.git` directory but not other directories starting with a `.` like |
| 151 | ++REM `.github` or `.bcr`. I don't know why it works this way, but hey it works. |
| 152 | ++if defined follow_links ( |
| 153 | ++ FOR /F %%d IN ('dir /b/a:d-h %~1 2^>nul') DO ( |
| 154 | ++ call :collectFiles "%~1\%%d" |
| 155 | ++ ) |
| 156 | ++) else ( |
| 157 | ++ FOR /F %%d IN ('dir /b/a:d-l-h %~1 2^>nul') DO ( |
| 158 | ++ call :collectFiles "%~1\%%d" |
| 159 | ++ ) |
| 160 | ++) |
0 commit comments