-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add runfiles helpers needed for rules_js (#3)
* feat: add runfiles helpers needed for rules_js * chore: code review feedback
- Loading branch information
Showing
7 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"Helpers for rules running on windows" | ||
|
||
# cmd.exe function for looking up runfiles. | ||
# Equivalent of the BASH_RLOCATION_FUNCTION in paths.bzl. | ||
# Use this to write actions that don't require bash. | ||
# Originally by @meteorcloudy in | ||
# https://github.com/bazelbuild/rules_nodejs/commit/f06553a | ||
BATCH_RLOCATION_FUNCTION = r""" | ||
rem Usage of rlocation function: | ||
rem call :rlocation <runfile_path> <abs_path> | ||
rem The rlocation function maps the given <runfile_path> to its absolute | ||
rem path and stores the result in a variable named <abs_path>. | ||
rem This function fails if the <runfile_path> doesn't exist in mainifest | ||
rem file. | ||
:: Start of rlocation | ||
goto :rlocation_end | ||
:rlocation | ||
if "%~2" equ "" ( | ||
echo>&2 ERROR: Expected two arguments for rlocation function. | ||
exit 1 | ||
) | ||
if "%RUNFILES_MANIFEST_ONLY%" neq "1" ( | ||
set %~2=%~1 | ||
exit /b 0 | ||
) | ||
if exist "%RUNFILES_DIR%" ( | ||
set RUNFILES_MANIFEST_FILE=%RUNFILES_DIR%_manifest | ||
) | ||
if "%RUNFILES_MANIFEST_FILE%" equ "" ( | ||
set RUNFILES_MANIFEST_FILE=%~f0.runfiles\MANIFEST | ||
) | ||
if not exist "%RUNFILES_MANIFEST_FILE%" ( | ||
set RUNFILES_MANIFEST_FILE=%~f0.runfiles_manifest | ||
) | ||
set MF=%RUNFILES_MANIFEST_FILE:/=\% | ||
if not exist "%MF%" ( | ||
echo>&2 ERROR: Manifest file %MF% does not exist. | ||
exit 1 | ||
) | ||
set runfile_path=%~1 | ||
for /F "tokens=2* usebackq" %%i in (`%SYSTEMROOT%\system32\findstr.exe /l /c:"!runfile_path! " "%MF%"`) do ( | ||
set abs_path=%%i | ||
) | ||
if "!abs_path!" equ "" ( | ||
echo>&2 ERROR: !runfile_path! not found in runfiles manifest | ||
exit 1 | ||
) | ||
set %~2=!abs_path! | ||
exit /b 0 | ||
:rlocation_end | ||
:: End of rlocation | ||
""" |