Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
CB-5660 use enabledelayedexpansion to handle )s in path
Refactoring file finding to a separate script which is mostly only used on WinXP
- it also needs to be copied by create.js

Avoid using %~...s in favor of relying on quotes
  • Loading branch information
jsoref authored and bryanhiggins committed Jan 31, 2014
1 parent ae20ff5 commit 0449138496a5bd1659f7d9cd81cc75b2289cc5a5
Showing 17 changed files with 111 additions and 84 deletions.
@@ -18,11 +18,6 @@ goto comment
under the License.
:comment

set INITCALL="%~dps0init"
if not exist INITCALL (
set INITCALL="%~dp0init"
)

call %INITCALL%
call "%~dp0init"
if ERRORLEVEL 1 exit /B %ERRORLEVEL%

@@ -17,13 +17,13 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment
set BIN_DIR=%~dp0
set "BIN_DIR=%~dp0"

call "%BIN_DIR%init"
if ERRORLEVEL 1 exit /B %ERRORLEVEL%

if exist "%BIN_DIR%..\package.json" (
pushd %BIN_DIR%..
pushd "%BIN_DIR%.."
call "%CORDOVA_NODE%\npm" install
if ERRORLEVEL 1 exit /B 1
popd
@@ -129,6 +129,7 @@ function copyFilesToProject() {
utils.copyFile(path.join(BIN_DIR, "lib", "signing-utils.js"), path.join(project_path, "cordova", "lib"));

// copy repo level init script to project
utils.copyFile(path.join(BIN_DIR, "whereis.cmd"), path.join(project_path, "cordova"));
utils.copyFile(path.join(BIN_DIR, "init.bat"), path.join(project_path, "cordova"));
utils.copyFile(path.join(BIN_DIR, "init"), path.join(project_path, "cordova"));

@@ -17,70 +17,71 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment
setlocal enabledelayedexpansion

set /P CORDOVA_VERSION=<%~dps0..\VERSION
set CORDOVA_HOME_DIR=%USERPROFILE%\.cordova\lib\blackberry10\cordova\%CORDOVA_VERSION%
set LOCAL_NODE_BINARY=%CORDOVA_HOME_DIR%\bin\dependencies\node\bin
set LOCAL_BBTOOLS_BINARY=%CORDOVA_HOME_DIR%\bin\dependencies\bb-tools\bin
set /P CORDOVA_VERSION=<"%~dp0..\VERSION"
set "CORDOVA_HOME_DIR=!USERPROFILE!\.cordova\lib\blackberry10\cordova\!CORDOVA_VERSION!"
set "LOCAL_NODE_BINARY=!CORDOVA_HOME_DIR!\bin\dependencies\node\bin"
set "LOCAL_BBTOOLS_BINARY=!CORDOVA_HOME_DIR!\bin\dependencies\bb-tools\bin"

set FOUNDJAVA=
for %%e in (%PATHEXT%) do (
for %%X in (java%%e) do (
if not defined FOUNDJAVA (
set FOUNDJAVA=%%~$PATH:X
)
)
set FOUNDWHERE=
for /f "usebackq delims=" %%e in (`where where 2^>nul`) do (
if not defined FOUNDWHERE set "FOUNDWHERE=%%e"
)
if not defined FOUNDJAVA (
set JAVAPATH="%ProgramFiles(x86)%\java\jre7\bin;%ProgramW6432%\java\jre7\bin;"
for %%e in (%PATHEXT%) do (
for %%X in (java%%e) do (
if not defined FOUNDJAVAAT (
set FOUNDJAVAAT=%%~dp$JAVAPATH:X
)
if not defined FOUNDWHERE set "FOUNDWHERE=%~dp0\whereis"

set FOUNDJAVAAT=
for /f "usebackq delims=" %%e in (`"%FOUNDWHERE%" java 2^>nul`) do (
if not defined FOUNDJAVAAT set "FOUNDJAVAAT=%%~dpe"
)
:: While we could normally ask where.exe to search an arbitrary environment variable,
:: it's too complicated to teach whereis.cmd to do that
:: instead we're going to replace PATH with a special PATH
:: In case you're curious, you can't nest ::'s inside ()s
if not defined FOUNDJAVAAT (
setlocal enabledelayedexpansion
SET "PATH=%ProgramFiles(x86)%\java\jre7\bin;%ProgramW6432%\java\jre7\bin;"
for /f "usebackq delims=" %%e in (`"%FOUNDWHERE%" java 2^>nul`) do (
set "FOUNDJAVAAT=%%~dpe"
)
if defined FOUNDJAVAAT (
for /f "delims=" %%C in (""!FOUNDJAVAAT!"") do (
endlocal
set "FOUNDJAVAAT=%%~C"
)
if defined FOUNDJAVAAT (
set "PATH=!PATH!;!FOUNDJAVAAT!"
)
) else (
endlocal
)
)
if defined FOUNDJAVAAT (
set PATH=%PATH%;%FOUNDJAVAAT%
)
:: While there are two endlocal calls, they're mutually exclusive and bookend the setlocal

if defined CORDOVA_NODE (
if exist "%CORDOVA_NODE%" (
if defined CORDOVA_BBTOOLS (
if exist "%CORDOVA_BBTOOLS%" (
goto end
)
)
if exist "!CORDOVA_NODE!" (
if defined CORDOVA_BBTOOLS (
if exist "!CORDOVA_BBTOOLS!" (
goto end
)
)
)
)

if exist "%LOCAL_NODE_BINARY%" (
set CORDOVA_NODE=%LOCAL_NODE_BINARY%
if exist "!LOCAL_NODE_BINARY!" (
set "CORDOVA_NODE=!LOCAL_NODE_BINARY!"
) else (
set FOUNDNODE=
for %%e in (%PATHEXT%) do (
for %%X in (node%%e) do (
if not defined FOUNDNODE (
set FOUNDNODE=%%~$PATH:X
for %%F in ("%%~$PATH:X") do set CORDOVA_NODE=%%~dpF
)
)
)
for /f "usebackq delims=" %%e in (`%FOUNDWHERE% node 2^>nul`) do (
set "CORDOVA_NODE=%%~dpe"
)
)

if exist "%LOCAL_BBTOOLS_BINARY%" (
set CORDOVA_BBTOOLS=%LOCAL_BBTOOLS_BINARY%
if exist "!LOCAL_BBTOOLS_BINARY!" (
set "CORDOVA_BBTOOLS=!LOCAL_BBTOOLS_BINARY!"
) else (
set FOUNDBBTOOLS=
for %%e in (%PATHEXT%) do (
for %%X in (blackberry-nativepackager%%e) do (
if not defined FOUNDBBTOOLS (
set FOUNDBBTOOLS=%%~$PATH:X
for %%F in ("%%~$PATH:X") do set CORDOVA_BBTOOLS=%%~dpF
)
)
)
for /f "usebackq delims=" %%e in (`%FOUNDWHERE% blackberry-nativepackager 2^>nul`) do (
set "CORDOVA_BBTOOLS=%%~dpe"
)
)

:end
@@ -97,27 +98,38 @@ if exist "%~dp0..\package.json" (
exit /b 2
)
)
if not defined FOUNDJAVA (
if not defined FOUNDJAVAAT (
echo java cannot be found on the path. Aborting.
exit /b 2
)
if not exist "%CORDOVA_BBTOOLS%\blackberry-nativepackager.bat" (
if not exist "!CORDOVA_BBTOOLS!\blackberry-nativepackager.bat" (
echo blackberry-nativepackager cannot be found on the path. Aborting.
exit /b 2
)
if not exist "%CORDOVA_BBTOOLS%\blackberry-deploy.bat" (
if not exist "!CORDOVA_BBTOOLS!\blackberry-deploy.bat" (
echo blackberry-deploy cannot be found on the path. Aborting.
exit /b 2
)
if not exist "%CORDOVA_BBTOOLS%\blackberry-signer.bat" (
if not exist "!CORDOVA_BBTOOLS!\blackberry-signer.bat" (
echo blackberry-signer cannot be found on the path. Aborting.
exit /b 2
)
if not exist "%CORDOVA_BBTOOLS%\blackberry-debugtokenrequest.bat" (
if not exist "!CORDOVA_BBTOOLS!\blackberry-debugtokenrequest.bat" (
echo blackberry-debugtokenrequest cannot be found on the path. Aborting.
exit /b 2
)

"%CORDOVA_NODE%\node" "%~dp0\check_reqs.js" %*
"!CORDOVA_NODE!\node" "%~dp0\check_reqs.js" %*

:: Export variables we want to share with the caller
for /f "delims=" %%A in (""!CORDOVA_NODE!"") do (
for /f "delims=" %%B in (""!CORDOVA_BBTOOLS!"") do (
for /f "delims=" %%C in (""!PATH!"") do (
endlocal
set "CORDOVA_NODE=%%~A"
set "CORDOVA_BBTOOLS=%%~B"
set "PATH=%%~C"
)
)
)
exit /b 0
@@ -17,7 +17,7 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment
call "%~dps0init"
call "%~dp0init"
if ERRORLEVEL 1 exit /B 1

"%CORDOVA_NODE%\node.exe" "%~dps0\lib\target" %*
"%CORDOVA_NODE%\node.exe" "%~dp0\lib\target" %*
@@ -17,5 +17,5 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment
call "%~dps0init"
"%CORDOVA_NODE%\node.exe" "%~dps0\lib\bb10-ndk-version" %*
call "%~dp0init"
"%CORDOVA_NODE%\node.exe" "%~dp0\lib\bb10-ndk-version" %*
@@ -17,7 +17,7 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment
call "%~dps0init"
call "%~dp0init"
if ERRORLEVEL 1 exit /B 1

"%CORDOVA_NODE%\node.exe" "%~dps0\lib\build" %*
"%CORDOVA_NODE%\node.exe" "%~dp0\lib\build" %*
@@ -17,7 +17,7 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment
call "%~dps0init"
call "%~dp0init"
if ERRORLEVEL 1 exit /B 1

"%CORDOVA_NODE%\node.exe" "%~dps0\lib\clean" %*
"%CORDOVA_NODE%\node.exe" "%~dp0\lib\clean" %*
@@ -17,7 +17,7 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment
call "%~dps0init"
call "%~dp0init"
if ERRORLEVEL 1 exit /B 1

"%CORDOVA_NODE%\node.exe" "%~dps0\lib\install-device" %*
"%CORDOVA_NODE%\node.exe" "%~dp0\lib\install-device" %*
@@ -17,7 +17,7 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment
call "%~dps0init"
call "%~dp0init"
if ERRORLEVEL 1 exit /B 1

"%CORDOVA_NODE%\node.exe" "%~dps0\lib\install-emulator" %*
"%CORDOVA_NODE%\node.exe" "%~dp0\lib\install-emulator" %*
@@ -19,4 +19,4 @@
call "%~dp0..\init"
if ERRORLEVEL 1 exit /B 1

"%CORDOVA_NODE%\node.exe" "%~dps0\list-devices.js"
"%CORDOVA_NODE%\node.exe" "%~dp0\list-devices.js"
@@ -19,4 +19,4 @@
call "%~dp0..\init"
if ERRORLEVEL 1 exit /B 1

"%CORDOVA_NODE%\node.exe" "%~dps0\list-emulator-images.js"
"%CORDOVA_NODE%\node.exe" "%~dp0\list-emulator-images.js"
@@ -19,4 +19,4 @@
call "%~dp0..\init"
if ERRORLEVEL 1 exit /B 1

"%CORDOVA_NODE%\node.exe" "%~dps0\list-started-emulators.js"
"%CORDOVA_NODE%\node.exe" "%~dp0\list-started-emulators.js"
@@ -17,7 +17,7 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment
call "%~dps0init"
call "%~dp0init"
if ERRORLEVEL 1 exit /B 1

"%CORDOVA_NODE%\node.exe" "%~dps0\lib\run" %*
"%CORDOVA_NODE%\node.exe" "%~dp0\lib\run" %*
@@ -17,7 +17,7 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment
call "%~dps0init"
call "%~dp0init"
if ERRORLEVEL 1 exit /B 1

"%CORDOVA_NODE%\node.exe" "%~dps0\lib\version" %*
"%CORDOVA_NODE%\node.exe" "%~dp0\lib\version" %*
@@ -17,5 +17,5 @@ goto comment
specific language governing permissions and limitations
under the License.
:comment
call "%~dps0init"
"%CORDOVA_NODE%\node.exe" "%~dps0\lib\update.js" %*
call "%~dp0init"
"%CORDOVA_NODE%\node.exe" "%~dp0\lib\update.js" %*
@@ -0,0 +1,19 @@
@echo off
setlocal enabledelayedexpansion
set var_a=%1
call :sub %var_a%
if exist %var_b% if not exist %var_b%\nul goto exit
for %%i in (.com .exe .cmd .bat) do (
call :sub %var_a%%%i
if exist !var_b! goto exit
)
echo INFO: could not find files for the given pattern(s) 1>&2
exit /b 1

:sub
set var_b=%~$PATH:1
goto :EOF

:exit
echo %var_b%
exit /b 0

0 comments on commit 0449138

Please sign in to comment.