|
| 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