@echo off
remremremremremremremremremremremremremremremremremremremsetlocal EnableDelayedExpansion
set "tool=%~n0"
remremif not defined WATERUI_FAKE_RUSTC_VERSION set "WATERUI_FAKE_RUSTC_VERSION=1.0.0"
if not defined WATERUI_FAKE_RUSTC_UPDATED_VERSION set "WATERUI_FAKE_RUSTC_UPDATED_VERSION=99.0.0"
if not defined WATERUI_FAKE_CARGO_VERSION set "WATERUI_FAKE_CARGO_VERSION=1.95.0"
if not defined WATERUI_FAKE_XCODE_VERSION set "WATERUI_FAKE_XCODE_VERSION=16.4"
if not defined WATERUI_FAKE_ADB_VERSION set "WATERUI_FAKE_ADB_VERSION=36.0.0-test"
if not defined WATERUI_FAKE_KOTLINC_VERSION set "WATERUI_FAKE_KOTLINC_VERSION=0.0.0"
if not defined WATERUI_FAKE_SCCACHE_VERSION set "WATERUI_FAKE_SCCACHE_VERSION=1.0.0"
if not defined WATERUI_FAKE_UNAME_MACHINE set "WATERUI_FAKE_UNAME_MACHINE=x86_64"
goto :dispatch
remrem:respond
call set "v=%%WATERUI_FAKE_%~1%%"
if defined v (echo !v! & exit /b 0)
if exist "%WATERUI_FAKE_RESPONSES%\%~1" (type "%WATERUI_FAKE_RESPONSES%\%~1" & exit /b 0)
exit /b 1
rem:respond_file
if exist "%WATERUI_FAKE_RESPONSES%\%~1" (type "%WATERUI_FAKE_RESPONSES%\%~1" & exit /b 0)
exit /b 1
rem:respond_or_empty
call set "v=%%WATERUI_FAKE_%~1%%"
if defined v (echo !v!)
if exist "%WATERUI_FAKE_RESPONSES%\%~1" (type "%WATERUI_FAKE_RESPONSES%\%~1")
exit /b 0
rem:last_arg
set "last_arg=%~1"
shift
if not "%~1"=="" goto :last_arg
exit /b 0
remrem:list_contains
set "list= %~1 "
if "!list: %~2 =!"=="!list!" (exit /b 1) else (exit /b 0)
remrem:module_exists
if exist "%WATERUI_FAKE_RESPONSES%\PKG_CONFIG_%~1" exit /b 0
exit /b 1
remrem:contains
call set "hay=%%%~1%%"
if not "!hay:%~2=!"=="!hay!" (exit /b 0) else (exit /b 1)
:dispatch
if /i "%tool%"=="rustup" goto :rustup
if /i "%tool%"=="rustc" goto :rustc
if /i "%tool%"=="cargo" goto :cargo
if /i "%tool%"=="espup" goto :espup
if /i "%tool%"=="xcodebuild" goto :xcodebuild
if /i "%tool%"=="xcode-select" goto :xcode_select
if /i "%tool%"=="xcrun" goto :xcrun
if /i "%tool%"=="sdkmanager" goto :sdkmanager
if /i "%tool%"=="adb" goto :adb
if /i "%tool%"=="emulator" goto :emulator
if /i "%tool%"=="java" goto :exit_ok
if /i "%tool%"=="javac" goto :exit_ok
if /i "%tool%"=="kotlinc" goto :kotlinc
if /i "%tool%"=="cmake" goto :simple_version
if /i "%tool%"=="meson" goto :simple_version
if /i "%tool%"=="sccache" goto :sccache
if /i "%tool%"=="wasm-pack" goto :simple_version
if /i "%tool%"=="sh" goto :simple_version
if /i "%tool%"=="bash" goto :simple_version
if /i "%tool%"=="brew" goto :exit_ok
if /i "%tool%"=="vswhere" goto :vswhere
if /i "%tool%"=="winget" goto :winget
if /i "%tool%"=="apt-get" goto :exit_ok
if /i "%tool%"=="dnf" goto :exit_ok
if /i "%tool%"=="zypper" goto :exit_ok
if /i "%tool%"=="sudo" goto :exit_ok
if /i "%tool%"=="dpkg-query" goto :dpkg_query
if /i "%tool%"=="dpkg" goto :dpkg
if /i "%tool%"=="rpm" goto :rpm
if /i "%tool%"=="pacman" goto :pacman
if /i "%tool%"=="apk" goto :apk
if /i "%tool%"=="pkg-config" goto :pkg_config
if not "%tool%"=="%tool:clang=%" goto :exit_ok
if /i "%tool%"=="ld" goto :exit_ok
if /i "%tool%"=="ld64" goto :exit_ok
if /i "%tool%"=="uname" goto :uname
goto :exit_ok
:exit_ok
exit /b 0
:rustup
remremremset "state_toolchains=%HOME%\.fake-rustup-toolchains"
set "state_default=%HOME%\.fake-rustup-default"
set "state_targets=%HOME%\.fake-rustup-targets"
set "state_components=%HOME%\.fake-rustup-components"
if defined RUSTUP_HOME (set "rustup_home=%RUSTUP_HOME%") else (set "rustup_home=%HOME%\.rustup")
if not defined WATERUI_FAKE_RUSTC_HOST set "WATERUI_FAKE_RUSTC_HOST=x86_64-unknown-fake"
if "%*"=="show active-toolchain" goto :rustup_active_toolchain
set "args=%*"
if not defined args exit /b 2
for %%a in (%*) do set "last_arg=%%a"
remremif "!args:~0,17!"=="toolchain install" goto :rustup_install
if "!args:~0,13!"=="toolchain add" goto :rustup_install
if "!args:~0,14!"=="toolchain list" (
if defined WATERUI_FAKE_RUSTUP_TOOLCHAINS echo !WATERUI_FAKE_RUSTUP_TOOLCHAINS!
if exist "%WATERUI_FAKE_RESPONSES%\RUSTUP_TOOLCHAINS" type "%WATERUI_FAKE_RESPONSES%\RUSTUP_TOOLCHAINS"
if exist "%state_toolchains%" type "%state_toolchains%"
exit /b 0
)
if "!args:~0,7!"=="default" goto :rustup_default
if "!args:~0,6!"=="update" (>"%HOME%\.fake-rustc-version" echo %WATERUI_FAKE_RUSTC_UPDATED_VERSION% & exit /b 0)
if "!args:~0,23!"=="target list --installed" (
if defined WATERUI_FAKE_RUSTUP_INSTALLED_TARGETS echo !WATERUI_FAKE_RUSTUP_INSTALLED_TARGETS!
if exist "%WATERUI_FAKE_RESPONSES%\RUSTUP_INSTALLED_TARGETS" type "%WATERUI_FAKE_RESPONSES%\RUSTUP_INSTALLED_TARGETS"
if exist "%state_targets%" type "%state_targets%"
exit /b 0
)
if "!args:~0,10!"=="target add" (>>"%state_targets%" echo !last_arg! & exit /b 0)
if "!args:~0,14!"=="component list" (
if defined WATERUI_FAKE_RUSTUP_INSTALLED_COMPONENTS echo !WATERUI_FAKE_RUSTUP_INSTALLED_COMPONENTS!
if exist "%WATERUI_FAKE_RESPONSES%\RUSTUP_INSTALLED_COMPONENTS" type "%WATERUI_FAKE_RESPONSES%\RUSTUP_INSTALLED_COMPONENTS"
if exist "%state_components%" type "%state_components%"
exit /b 0
)
if "!args:~0,13!"=="component add" (>>"%state_components%" echo !last_arg! & exit /b 0)
if "!args:~0,3!"=="run" goto :rustup_run
if "%1"=="--version" (echo rustup 1.28.2 (waterui-test) & exit /b 0)
if "%1"=="-V" (echo rustup 1.28.2 (waterui-test) & exit /b 0)
exit /b 2
remrem:rustup_install
>>"%state_toolchains%" echo !last_arg!
mkdir "!rustup_home!\toolchains\!last_arg!" 2>nul
exit /b 0
remremrem:rustup_run
set "run_tool=%~dp0%~3.cmd"
shift
shift
set "run_args="
:rustup_run_args
if not "%~2"=="" (set "run_args=!run_args! %~2" & shift & goto :rustup_run_args)
call "%run_tool%" %run_args%
exit /b %errorlevel%
rem:rustup_default
>>"%state_toolchains%" echo !last_arg!
>"%state_default%" echo !last_arg!
mkdir "!rustup_home!\toolchains\!last_arg!" 2>nul
exit /b 0
remrem:rustup_active_toolchain
if defined WATERUI_FAKE_RUSTUP_NO_ACTIVE_TOOLCHAIN echo error: no active toolchain 1>&2
if defined WATERUI_FAKE_RUSTUP_NO_ACTIVE_TOOLCHAIN exit /b 1
if defined WATERUI_FAKE_RUSTUP_TOOLCHAIN_NOT_INSTALLED goto :rustup_pinned_toolchain
set "def_channel="
if exist "%state_default%" for /f "usebackq delims=" %%l in ("%state_default%") do set "def_channel=%%l"
if defined def_channel (echo !def_channel!-%WATERUI_FAKE_RUSTC_HOST% (default) & exit /b 0)
call :respond RUSTUP_ACTIVE_TOOLCHAIN
exit /b %errorlevel%
remremremremremrem:rustup_pinned_toolchain
set "pin=%WATERUI_FAKE_RUSTUP_TOOLCHAIN_NOT_INSTALLED%"
set "pin_installed="
if exist "%state_toolchains%" for /f "usebackq delims=" %%l in ("%state_toolchains%") do if "%%l"=="!pin!" set "pin_installed=file"
if exist "!rustup_home!\toolchains\!pin!" set "pin_installed=dir"
if not defined pin_installed (
echo error: toolchain '!pin!' is not installed 1>&2
exit /b 1
)
set "pin_suffixed="
if /i "!pin!"=="stable" set "pin_suffixed=1"
if /i "!pin!"=="beta" set "pin_suffixed=1"
if /i "!pin!"=="nightly" set "pin_suffixed=1"
for %%d in (0 1 2 3 4 5 6 7 8 9) do if "!pin:~0,1!"=="%%d" set "pin_suffixed=1"
if defined pin_suffixed (echo !pin!-%WATERUI_FAKE_RUSTC_HOST% (overridden by rust-toolchain.toml) & exit /b 0)
echo !pin! (overridden by rust-toolchain.toml)
exit /b 0
:rustc
set "rustc_version=%WATERUI_FAKE_RUSTC_VERSION%"
if exist "%HOME%\.fake-rustc-version" for /f "usebackq delims=" %%v in ("%HOME%\.fake-rustc-version") do set "rustc_version=%%v"
if "%1"=="--version" (echo rustc %rustc_version% (waterui-test 2026-01-01) & exit /b 0)
if "%1"=="-vV" (
if defined WATERUI_FAKE_RUSTC_HOST (
echo rustc %rustc_version% (waterui-test)
echo binary: rustc
echo commit-hash: fake
echo commit-date: 2026-01-01
echo host: %WATERUI_FAKE_RUSTC_HOST%
echo release: %rustc_version%
echo LLVM version: 20.1.0
exit /b 0
)
call :respond RUSTC_VERBOSE & exit /b !errorlevel!
)
exit /b 2
:cargo
if not defined WATERUI_FAKE_CARGO_VERSION set "WATERUI_FAKE_CARGO_VERSION=1.95.0"
if "%1"=="--version" (echo cargo %WATERUI_FAKE_CARGO_VERSION% (waterui-test) & exit /b 0)
if "%1"=="install" goto :cargo_install
if "%1"=="binstall" goto :cargo_install
exit /b 0
remrem:cargo_install
set "krate="
for %%a in (%*) do (
if not defined krate (
set "arg=%%a"
if not "!arg:~0,1!"=="-" if not /i "%%a"=="install" if not /i "%%a"=="binstall" set "krate=%%a"
)
)
if defined krate if not exist "%~dp0!krate!.cmd" copy /y "%~f0" "%~dp0!krate!.cmd" >nul
exit /b 0
remrem:espup
if not "%1"=="install" exit /b 0
if defined RUSTUP_HOME (set "esp=%RUSTUP_HOME%\toolchains\esp") else (set "esp=%HOME%\.rustup\toolchains\esp")
mkdir "%esp%\xtensa-esp32-elf-clang\1.0\esp-clang\lib" 2>nul
mkdir "%esp%\xtensa-esp-elf\1.0\xtensa-esp-elf\bin" 2>nul
mkdir "%esp%\lib\rustlib\src\rust" 2>nul
set "args=%*"
call :contains args --esp-riscv-gcc && (mkdir "%HOME%\.espressif\tools\riscv32-esp-elf\1.0\riscv32-esp-elf\bin" 2>nul)
exit /b 0
:xcodebuild
set "args=%*"
call :contains args version && (echo Xcode %WATERUI_FAKE_XCODE_VERSION% & echo Build version 16F6 & exit /b 0)
exit /b 0
:xcode_select
if "%1"=="-p" (call :respond_or_empty XCODE_SELECT_DEVELOPER_DIR & exit /b 0)
exit /b 0
:xcrun
set "args=%*"
call :contains args --show-sdk-path && (call :respond XCRUN_SDK_PATH & exit /b !errorlevel!)
if "%*"=="simctl list --json" (call :respond XCRUN_SIMCTL_DEVICES & exit /b !errorlevel!)
if "%*"=="simctl delete unavailable" exit /b 0
if "!args:~0,14!"=="simctl create " exit /b 0
exit /b 1
:sdkmanager
remremset "args=%*"
call :contains args --licenses && exit /b 0
call :contains args --install && exit /b 0
call :contains args --list && (call :respond_or_empty SDKMANAGER_LIST & exit /b 0)
call :contains args --version && (echo 5.0 & exit /b 0)
exit /b 0
:adb
if "%*"=="version" (echo Android Debug Bridge version 1.0.41 & echo Version %WATERUI_FAKE_ADB_VERSION% & exit /b 0)
if "%*"=="devices -l" (echo List of devices attached & call :respond_or_empty ADB_DEVICES & exit /b 0)
if "%*"=="start-server" (if defined WATERUI_FAKE_ADB_START_SERVER_STATUS (exit /b %WATERUI_FAKE_ADB_START_SERVER_STATUS%) else (exit /b 0))
set "args=%*"
call :contains args "emu avd name" && (call :respond_or_empty ADB_EMU_AVD_NAME & exit /b 0)
call :contains args getprop && (call :respond_or_empty ADB_GETPROP & exit /b 0)
call :contains args wait-for-device && exit /b 0
exit /b 0
:emulator
set "args=%*"
call :contains args -list-avds && (call :respond_or_empty EMULATOR_AVDS & exit /b 0)
exit /b 0
:kotlinc
if "%1"=="-version" (echo info: kotlinc-jvm %WATERUI_FAKE_KOTLINC_VERSION% (JRE 17.0.0) & exit /b 0)
exit /b 0
:sccache
if "%1"=="--version" (echo sccache %WATERUI_FAKE_SCCACHE_VERSION% (waterui-test) & exit /b 0)
if "%1"=="-version" (echo sccache %WATERUI_FAKE_SCCACHE_VERSION% (waterui-test) & exit /b 0)
if "%1"=="-v" (echo sccache %WATERUI_FAKE_SCCACHE_VERSION% (waterui-test) & exit /b 0)
exit /b 0
:simple_version
if "%1"=="--version" (echo %tool% 1.0.0 (waterui-test) & exit /b 0)
if "%1"=="-version" (echo %tool% 1.0.0 (waterui-test) & exit /b 0)
if "%1"=="-v" (echo %tool% 1.0.0 (waterui-test) & exit /b 0)
exit /b 0
:vswhere
call :respond_or_empty VSWHERE
exit /b 0
:winget
if "%1 %2"=="list --id" (
call :list_contains "%WATERUI_FAKE_WINGET_INSTALLED%" "%~3" & exit /b !errorlevel!
)
if "%1"=="install" exit /b 0
exit /b 2
:dpkg_query
if not "%1"=="-W" exit /b 1
call :last_arg %*
call :list_contains "%WATERUI_FAKE_DPKG_INSTALLED%" "%last_arg%" && (echo install ok installed & exit /b 0)
exit /b 1
:dpkg
if "%1"=="--print-foreign-architectures" (call :respond_or_empty DPKG_FOREIGN_ARCHES & exit /b 0)
exit /b 0
:rpm
if not "%1"=="-q" exit /b 1
call :last_arg %*
call :list_contains "%WATERUI_FAKE_RPM_INSTALLED%" "%last_arg%"
exit /b %errorlevel%
:pacman
if not "%1"=="-Q" exit /b 0
call :last_arg %*
call :list_contains "%WATERUI_FAKE_PACMAN_INSTALLED%" "%last_arg%" && (echo %last_arg% 1.0 & exit /b 0)
exit /b 1
:apk
if not "%1 %2"=="info -e" exit /b 0
call :last_arg %*
call :list_contains "%WATERUI_FAKE_APK_INSTALLED%" "%last_arg%"
exit /b %errorlevel%
:pkg_config
remremremif "%1"=="--version" (echo 1.8.1 & exit /b 0)
if "%1"=="--exists" (
call :module_exists "%~2" & exit /b !errorlevel!
)
set "args=%*"
call :contains args "--atleast-version=" && (
call :last_arg %*
call :module_exists "!last_arg!" || exit /b 1
call :list_contains "%WATERUI_FAKE_PKG_CONFIG_TOO_OLD%" "!last_arg!" && exit /b 1
exit /b 0
)
if "%1"=="--modversion" (
call :respond_file "PKG_CONFIG_%~2" & exit /b !errorlevel!
)
call :contains args "--variable=" && (
rem rem call :respond "PKG_CONFIG_VAR_%~2" & exit /b !errorlevel!
)
exit /b 0
:uname
if "%1"=="-m" (echo %WATERUI_FAKE_UNAME_MACHINE% & exit /b 0)
echo WaterUITest
exit /b 0