mirror of
https://github.com/bazel-contrib/bazel-lib
synced 2024-11-27 17:43:27 +00:00
da6fb88da7
* feat: add runfiles helpers needed for rules_js * chore: code review feedback
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
"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
|
|
"""
|