如何使用命令行编译 Delphi 7 项目组文件 (.bpg)?

发布于 2024-11-26 18:27:43 字数 99 浏览 1 评论 0原文

我将很多项目分组到一个项目组中。所有信息都在project.bpg中。现在我想自动构建它们。

如何使用命令行构建所有项目?

我还在使用Delphi 7。

I've grouped a lot of projects in a project group. All the info is in the project.bpg. Now I'd like to automatically build them all.

How do I build all the projects using the command line?

I'm still using Delphi 7.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

相对绾红妆 2024-12-03 18:27:43

我自己从未尝试过,但是这里是一篇德语文章,描述了您可以使用make -f ProjectGroup.bpg 因为 *.bpg 本质上是 makefile。

I never tried it myself, but here is a German article describing that you can use make -f ProjectGroup.bpg because *.bpgs essentially are makefiles.

爺獨霸怡葒院 2024-12-03 18:27:43

您还可以从命令行或批处理文件运行 Delphi,并将 .bpg 文件名作为参数传递。

编辑:示例(对于 D2007,但可以针对 D7 进行调整):

===rebuild.cmd(摘录)===

@echo off
set DelphiPath=C:\Program Files\CodeGear\RAD Studio\5.0\bin
set DelphiExe=bds.exe
set LibPath=V:\Library
set LibBpg=Library.groupproj
set LibErr=Library.err
set RegSubkey=BDSClean

:buildlib
echo Rebuilding %LibBpg%...
if exist "%LibPath%\%LibErr%" del /q "%LibPath%\%LibErr%"
"%DelphiPath%\%DelphiExe%" -pDelphi -r%RegSubkey% -b "%LibPath%\%LibBpg%"
if %errorlevel% == 0 goto buildlibok

You can also run Delphi from the command line or a batch file, passing the .bpg file name as a parameter.

Edit: Example (for D2007, but can be adjusted for D7):

=== rebuild.cmd (excerpt) ===

@echo off
set DelphiPath=C:\Program Files\CodeGear\RAD Studio\5.0\bin
set DelphiExe=bds.exe
set LibPath=V:\Library
set LibBpg=Library.groupproj
set LibErr=Library.err
set RegSubkey=BDSClean

:buildlib
echo Rebuilding %LibBpg%...
if exist "%LibPath%\%LibErr%" del /q "%LibPath%\%LibErr%"
"%DelphiPath%\%DelphiExe%" -pDelphi -r%RegSubkey% -b "%LibPath%\%LibBpg%"
if %errorlevel% == 0 goto buildlibok
木落 2024-12-03 18:27:43

正如我对 Ulrich Gerhardt 答案的评论所说,如果您的项目位于子目录中,则 make project_group.bpg 是无用的。 Make 不会使用相对路径,并且项目将无法正确编译。

我制作了一个 python 脚本来编译每个子目录中的所有 DPR。这是我真正想做的,但我将保留上述答案的标记。虽然它对我没有用,但它确实回答了我的问题。

这是我的compile_all.py 脚本。我相信它可能会对某人有所帮助:

# -*- coding: utf-8 -*-

import os.path
import subprocess
import sys

#put this file in your root dir
BASE_PATH = os.path.dirname(os.path.realpath(__file__)) 
os.chdir(BASE_PATH)

os.environ['PATH'] += "C:\\Program Files\\Borland\\Delphi7\\Bin" #your delphi compiler path
DELPHI = "DCC32.exe"  
DELPHI_PARAMS = ['-B', '-Q', '-$D+', '-$L+']


for root, dirs, files in os.walk(BASE_PATH):
    projects = [project for project in files if project.lower().endswith('.dpr')]
    if ('FastMM' in root ): #put here projects you don't want to compile
        continue
    os.chdir(os.path.join(BASE_PATH, root))
    for project in projects:
        print
        print '*** Compiling:', os.path.join(root, project)
        result = subprocess.call([DELPHI] + DELPHI_PARAMS + [project])
        if result != 0:
            print 'Failed for', project, result
            sys.exit(result)

这种方法的另一个优点是您不需要将新项目添加到 bpg 文件中。如果它在子目录中,它将编译。

As I said as a comment to Ulrich Gerhardt answer, the make project_group.bpg is useless if your projects are in subdirectories. Make won't use relative paths and the projects won't compile correctly.

I've made a python script to compile all the DPRs in every subdirectory. This is what I really wanted to do, but I'll leave the above answer as marked. Although it didn't worked for me, It really answered my question.

Here is my script to compile_all.py . I believe it may help somebody:

# -*- coding: utf-8 -*-

import os.path
import subprocess
import sys

#put this file in your root dir
BASE_PATH = os.path.dirname(os.path.realpath(__file__)) 
os.chdir(BASE_PATH)

os.environ['PATH'] += "C:\\Program Files\\Borland\\Delphi7\\Bin" #your delphi compiler path
DELPHI = "DCC32.exe"  
DELPHI_PARAMS = ['-B', '-Q', '-$D+', '-$L+']


for root, dirs, files in os.walk(BASE_PATH):
    projects = [project for project in files if project.lower().endswith('.dpr')]
    if ('FastMM' in root ): #put here projects you don't want to compile
        continue
    os.chdir(os.path.join(BASE_PATH, root))
    for project in projects:
        print
        print '*** Compiling:', os.path.join(root, project)
        result = subprocess.call([DELPHI] + DELPHI_PARAMS + [project])
        if result != 0:
            print 'Failed for', project, result
            sys.exit(result)

Another vantage of this approach is that you don't need to add new projects to your bpg file. If it is in a subdir, it will compile.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文