Batch file 有没有一种方法可以不使用keil而使用脚本来构建arm项目?
最近我在做一些使用arm但没有操作系统的项目。Batch file 有没有一种方法可以不使用keil而使用脚本来构建arm项目?,batch-file,arm,keil,Batch File,Arm,Keil,最近我在做一些使用arm但没有操作系统的项目。 现在当我编译它时,我必须打开keil。 但是keil在编辑方面很弱,所以我正在考虑编写一个脚本来执行keil的编译器,以构建项目。 但我对基尔知之甚少,所以我想知道这是否可行,以避免无用的工作 感谢您的帮助。如artless noise所述,您可以直接在命令行上调用armcc,或将其集成到构建系统中,如make、scons等。一个好的起点是让Keil uVision为您创建一个批处理文件:。 另一种可能是从命令行调用Keil,将项目文件作为命令行参
现在当我编译它时,我必须打开keil。
但是keil在编辑方面很弱,所以我正在考虑编写一个脚本来执行keil的编译器,以构建项目。
但我对基尔知之甚少,所以我想知道这是否可行,以避免无用的工作
感谢您的帮助。如artless noise所述,您可以直接在命令行上调用armcc,或将其集成到构建系统中,如make、scons等。一个好的起点是让Keil uVision为您创建一个批处理文件:。 另一种可能是从命令行调用Keil,将项目文件作为命令行参数,并带有构建项目的选项。。 顺便说一句,我还使用此命令行选项在模拟器中进行自动单元测试和flash下载。编辑2021: 因为Kiel仍然没有改进他们的命令行工具,所以重新审视了这个答案
- 更正了脚本中的一个小错误
- 修复了Kiel命令行文档的链接
- 将脚本添加到,以便更容易分叉
原始答复: 下面是我编写Keil uVision4编译器脚本的尝试 Keil的基本上从2011年起就没有改变过,而且非常有限——特别是在构建服务器上使用编译器 此外,Keil uVision4编译器非常奇怪,尤其是在创建输出时,但在理论上支持两种方法-但是有时不创建、只创建一个、另一个或同时创建两个输出文件。此批处理脚本尝试处理所有这些情况 另一个问题是Flex许可证服务器在使用时。此脚本允许您定义要重试生成的次数,并设置尝试生成之间的间隔。如果在生成过程中突然撤销许可证,它也会成功恢复 如果您对此脚本有任何补充,请在此处发布
@echo off
setlocal
:: KeiluVisionBuilder.cmd
:: Written by Flemming Steffensen, 2019.
:: Free for use and abuse by anyone.
:: ======================
:: Configuration
::
set WaitForLicenseTimeout=60
set BuildAttemptsMax=10
set "ProjectFileName=bootloader.uvprojx"
set "ProjectPath=MyProject\bootloader\"
set "Compiler=C:\Keil_v5\UV4\UV4.exe"
set "OutFolder=OutputFolderDefinedIn_MyProject\"
::
:: ======================
:: Do not edit below this line
set BuildAttempt=0
pushd %ProjectPath%
:PerformBuild
echo:
echo:Performing Keil Build...
if exist build.log del build.log
if exist %OutFolder%*.build_log.htm del %OutFolder%*.build_log.htm
start /wait %Compiler% -j0 -b %ProjectFileName% -o build.log
set ReportedError=%ERRORLEVEL%
:: Scan build.log to determine if the license is locked.
find /c "Error: *** All Flex licenses are in use! ***" build.log >nul
if %errorlevel% equ 0 (
set /a BuildAttempt=%BuildAttempt% + 1
echo:Error: *** All Flex licenses are in use!
if %BuildAttempt% equ %BuildAttemptsMax% goto NoLicenseAvailable
echo:Retrying ^(%BuildAttempt% of %BuildAttemptsMax%^) in %WaitForLicenseTimeout% seconds
waitfor SignalNeverComming /T %WaitForLicenseTimeout% >nul 2>&1
goto PerformBuild
)
:: Scan alternative build.log to determine if the license is locked.
find /c "Failed to check out a license" %OutFolder%*.build_log.htm >nul
if %errorlevel% equ 0 (
set /a BuildAttempt=%BuildAttempt% + 1
echo:Error: Failed to check out a license
if %BuildAttempt% equ %BuildAttemptsMax% goto NoLicenseAvailable
echo:Retrying ^(%BuildAttempt% of %BuildAttemptsMax%^) in %WaitForLicenseTimeout% seconds
waitfor SignalNeverComming /T %WaitForLicenseTimeout% >nul 2>&1
goto PerformBuild
)
goto NoLicenseProblem
:NoLicenseAvailable
echo:Error: After %BuildAttempt% attempts, the Flex license still appear to be unavailable. Failing the build!
echo:
popd
exit /b 1
:NoLicenseProblem
:: Parse exit codes
set KnownErrors=0 1 2 3 11 12 13 15 20 41
echo:Kiel compiler exited with error code %ReportedError%
for %%a in (%KnownErrors%) do (
if [%ReportedError%] equ [%%a] goto Error%ReportedError%
)
goto UnknownError
:Error0
echo Compilation successful
goto ExitButContinueJob
:Error1
echo Warnings were found
goto ExitButContinueJob
:Error2
echo Errors were found
goto ExitCritical
:Error3
echo Error 3 = Fatal Errors
goto ExitCritical
:Error11
echo Error 11 = Cannot open project file for writing
goto ExitCritical
:Error12
echo Error 12 = Device with given name in not found in database
goto ExitCritical
:Error13
echo Error 13 = Error writing project file
goto ExitCritical
:Error15
echo Error 15 = Error reading import XML file
goto ExitCritical
:Error20
echo Error 20 = Can not convert the project file.
goto ExitCritical
:Error41
echo Error 41 = Can not create the logfile requested using the -l switch.
goto ExitCritical
:UnknownError
echo Error %ReportedError% = Unknown error
goto ExitCritical
:ExitCritical
echo:
if [%ReportedError%] neq 0 exit /b %ReportedError%
:ExitButContinueJob
echo:
popd
exit /b 0
直接打电话有什么不对?它应该在windows上命名为armcc.exe,并且可能位于程序文件目录中的某个位置;但是我已经有15年没有使用Windows了。如果你正在使用这些脚本或者已经对其进行了修改,如果你有反馈的话,那就太好了。这些脚本在什么地方还可用吗?@fsteff这段时间链接好像已经死了,所以可能没有。但是您应该能够重新创建一些包装器函数,以便非常轻松地调用命令行。谢谢。我知道,事实上我已经知道了,但我很想看到另一个解决方案。我在Keil提供的有限文档中发现了几个真正的错误,并且我仍然在发现我的包装失败的情况。Flex许可证有一个错误。@fsteff这方面的Keil文档非常糟糕。我不知道这在以后的版本中是否有所改进,我不再使用它了。但我不知怎么地记得,为了捕捉Flex许可证错误,我做了以下工作:-使用
-o
选项启动Keil。-等待进程结束。-检查返回代码-如果返回代码!=0,根据返回代码(来自文档)进行处理-如果返回代码==0,则在日志文件中进行正则表达式搜索以查找FlexLM错误-使用正则表达式从日志文件中提取其他有趣的内容