0

调试“rpmbuild.bat”下面的脚本。注意:它包含错误,不完整。这是命令行:

rpmbuild.bat -bb --target "noarch-pc-windows 7" --buildroot D:\MyPath\MyApp\buildroot --define "_topdir D:\MyPath\MyApp" MyApp.spec

这个想法是采用上面的“.bat”cmd参数,修改它们并(通过cygwin)重定向到具有相同名称的unix工具(rpmbuild)。所以要有这样的东西:

bash -c "rpmbuild -bb --target ""noarch-pc-windows 7"" --buildroot /cygdrive/d/MyPath/MyApp/buildroot --define ""_topdir /cygdrive/d/MyPath/MyApp"" MyApp.spec"

为了以正确的方式转换路径,有一个实用程序cygpath

以下是rpmbuild.bat的来源。但它无法按照此处建议的字符串比较进行编译

SETLOCAL EnableExtensions EnableDelayedExpansion
PUSHD .

SET PARAM_COUNT = 0
FOR %%P IN (%*) DO (
    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 with cygwin path
        FOR /F "tokens=*" %%i in ('cygpath %%P') do SET PARAMS[PARAM_COUNT]=%%i
    )

    REM string comparison for TOPDIR
    SET str1 = %%P
    IF NOT x%str1:_topdir=%==x%str1% (
        REM Update topdir path
        SET TOPDIR=%%P
        SET TOPDIR=%TOPDIR:~9,-1%
        FOR /F "tokens=*" %%i in ('cygpath "%TOPDIR%"') do SET NEW_TOPDIR=%%i
        SET PARAMS[PARAM_COUNT] = "_topdir %NEW_TOPDIR"
    )

    REM string comparison for .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
FOR /L %%i IN (1,1,PARAM_COUNT) DO SET RPMBUILD_COMMAND=!RPMBUILD_COMMAND! %%i
SET RPMBUILD_COMMAND=!RPMBUILD_COMMAND!"

REM Execute rpmbuild
%RPMBUILD_COMMAND

POPD
ENDLOCAL

怎么修?

4

1 回答 1

2
  1. 给你SET "str1 "=" %%P",两个不需要的空格
  2. 在这里,IF NOT x%str1:_topdir=%==x%str1%您位于for需要的代码块内delayed expansion !variables!,此错误在您的脚本中更频繁地发生。
于 2013-08-28T19:07:02.483 回答