windows - Batch scripting failed string comparison -
debugging script below "rpmbuild.bat". note: contains bugs, not complete. command line:
rpmbuild.bat -bb --target "noarch-pc-windows 7" --buildroot d:\mypath\myapp\buildroot --define "_topdir d:\mypath\myapp" myapp.spec
the idea take above ".bat" cmd parameters, modify them , redirect (via cygwin) unix tool same name (rpmbuild). have smth like:
bash -c "rpmbuild -bb --target ""noarch-pc-windows 7"" --buildroot /cygdrive/d/mypath/myapp/buildroot --define ""_topdir /cygdrive/d/mypath/myapp"" myapp.spec"
for transforming paths proper way, there utility cygpath.
below source of rpmbuild.bat. fails compile on line string comparison proposed here
setlocal enableextensions enabledelayedexpansion pushd . set param_count = 0 %%p in (%*) ( set /a param_count += 1 set params[param_count] = %%p if param_count gtr 1 if params[param_count-1]=="--buildroot" ( rem update buildroot path cygwin path /f "tokens=*" %%i in ('cygpath %%p') set params[param_count]=%%i ) rem string comparison topdir set str1 = %%p if not x%str1:_topdir=%==x%str1% ( rem update topdir path set topdir=%%p set topdir=%topdir:~9,-1% /f "tokens=*" %%i in ('cygpath "%topdir%"') set new_topdir=%%i set params[param_count] = "_topdir %new_topdir" ) rem string comparison .spec if not x%str1:.spec=%==x%str1% ( rem replace path in spec-file set old_path=%topdir:\=\\% set new_path=%new_topdir:/=\/% sed -s -i -e s/%old_path%\\/%new_path%\//g %%p ) ) rem construct new rpmbuild command in cygwin set rpmbuild_command = bash -c "rpmbuild /l %%i in (1,1,param_count) set rpmbuild_command=!rpmbuild_command! %%i set rpmbuild_command=!rpmbuild_command!" rem execute rpmbuild %rpmbuild_command popd endlocal
how fix?
- here
set "str1 "=" %%p"
, 2 unwanted spaces - here
if not x%str1:_topdir=%==x%str1%
insidefor
code block needdelayed expansion
!variables!
, error occures more in script.
Comments
Post a Comment