Skip to content

Commit

Permalink
Merge pull request #1063 from savetheclocktower/fix-pulsar-p-on-windows
Browse files Browse the repository at this point in the history
Use a different strategy for `pulsar -p` on Windows…
  • Loading branch information
savetheclocktower authored Aug 3, 2024
2 parents 9a6db0d + 7a1a24a commit ddaffa2
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions resources/win/pulsar.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ SET PSARGS=%*
SET ELECTRON_ENABLE_LOGGING=
SET ATOM_ADD=
SET ATOM_NEW_WINDOW=
SET PACKAGE_MODE=
SET PACKAGE_MODE_ARGS=

FOR %%a IN (%*) DO (
IF /I "%%a"=="-f" SET EXPECT_OUTPUT=YES
Expand All @@ -16,15 +18,15 @@ FOR %%a IN (%*) DO (
IF /I "%%a"=="--test" SET EXPECT_OUTPUT=YES
IF /I "%%a"=="--benchmark" SET EXPECT_OUTPUT=YES
IF /I "%%a"=="--benchmark-test" SET EXPECT_OUTPUT=YES
IF /I "%%a"=="-p" SET EXPECT_OUTPUT=YES
IF /I "%%a"=="--package" SET EXPECT_OUTPUT=YES
IF /I "%%a"=="-v" SET EXPECT_OUTPUT=YES
IF /I "%%a"=="--version" SET EXPECT_OUTPUT=YES
IF /I "%%a"=="--enable-electron-logging" SET ELECTRON_ENABLE_LOGGING=YES
IF /I "%%a"=="-a" SET ATOM_ADD=YES
IF /I "%%a"=="--add" SET ATOM_ADD=YES
IF /I "%%a"=="-n" SET ATOM_NEW_WINDOW=YES
IF /I "%%a"=="--new-window" SET ATOM_NEW_WINDOW=YES
IF /I "%%a"=="-p" SET PACKAGE_MODE=YES
IF /I "%%a"=="--package" SET PACKAGE_MODE=YES
IF /I "%%a"=="-w" (
SET EXPECT_OUTPUT=YES
SET WAIT=YES
Expand All @@ -40,6 +42,19 @@ IF "%ATOM_ADD%"=="YES" (
SET EXPECT_OUTPUT=YES
)
)
if "%PACKAGE_MODE%"=="YES" (
REM In package mode, we should shell out directly to `ppm` instead of
REM invoking `Pulsar.exe` at all. But first we need to assemble a list of
REM arguments that `ppm.cmd` will understand.

REM Since batch files don't have `while` loops, we've got to fake them with
REM labels and GOTO.
goto :trim_args_for_package_mode

:package_mode_return
"%~dp0\app\ppm\bin\ppm.cmd" %PACKAGE_MODE_ARGS%
exit 0
)

IF "%EXPECT_OUTPUT%"=="YES" (
IF "%WAIT%"=="YES" (
Expand All @@ -51,3 +66,36 @@ IF "%EXPECT_OUTPUT%"=="YES" (
) ELSE (
"%~dp0\app\ppm\bin\node.exe" "%~dp0\pulsar.js" "Pulsar.exe" %*
)

REM Jump past the subroutines below.
goto :eof

REM The subroutine for assembling a list of arguments to pass to `ppm`.
REM First we trim any arguments that appear previous to `-p` or `--package` on
REM the line.
:trim_args_for_package_mode
if not "%1"=="--package" (
if not "%1"=="-p" (
REM Roughly the same as `ARGV.shift`. Everything except the initial
REM argument moves forward, and the second argument is removed from the
REM list.
SHIFT /1
goto :trim_args_for_package_mode
)
)
REM When we reach this point, `-p`/`--package` is the argument in the %1
REM position. Now we'll call `shift` once more to remove it from the list.
SHIFT /1

:build_args_for_package_mode
REM We need to pass all the remaining arguments to `ppm.cmd`. If all the
REM shifting we did above affected %*, that'd be perfect. But since it doesn't,
REM we'll loop through the remaining arguments and concatenate them into a
REM variable.
if not "%1"=="" (
SET PACKAGE_MODE_ARGS=%PACKAGE_MODE_ARGS% %1%
SHIFT /1
goto :build_args_for_package_mode
)
REM Return from our subroutines so we can finally call `ppm.cmd`.
goto :package_mode_return

0 comments on commit ddaffa2

Please sign in to comment.