包含第三方组件的项目目录结构

发布于 2024-11-02 15:01:38 字数 1159 浏览 0 评论 0原文

我必须维护用 Delphi 编写的旧软件。源代码树真是一团糟。我正在尝试做两件事:建立干净的目录结构并设置自动构建过程。

现在我已经生成了以下目录树

  \Project
     \build\output   
     \dist\release
     \dist\debug
     \doc
     \env
     \res
     \src

\src 目录包含 *.pas*.dfm 文件和 project.dpr.各种资源(图标、图像和字体)位于 \res 目录中。 \env 用于创建各种环境以进行调试。 IDE 设置为将 project.exe 构建到此目录中。 构建脚本存储在 build 文件夹中。这些脚本在 dcc32.exe 的帮助下在 dist\releasedist\debug 文件夹中生成产品分发(exe 中包含和不包含调试信息) 。 build\output 用于在 IDE 或构建脚本内的构建过程中保存 dcu 文件。

我的方法有一个小缺陷。我无法从新计算机开始,从我的存储库中签出代码,开始构建脚本并接收准备使用的项目分发。我需要先打开IDE,安装所需的组件(例如RXLibMemoEx),设置库路径等。只有在这些步骤之后我才能运行我的构建脚本。

直到上周这还不是一个大问题。我修改了第 3 方组件以修复错误(该组件不再维护:-(),因此我必须将此组件的代码添加到我的项目结构中。此时,如果我从我需要检查第 3 方库的代码是否有更改。如果库的代码发生更改,我需要重新编译组件并重新安装它们。

问题

  1. 有没有办法从命令行重新安装 Delphi 7 中的组件?没有硬编码 D7 安装路径的方法
  2. 如何在项目树中存储第三方组件的代码?
  3. 我应该将在其中生成的 bpldcu我应该将它们放置在 Project\build\output 中吗?还是将输出放置到另一个位置(不要覆盖 Delphi 设置),但更改项目配置中的库路径?

I have to maintain old software written in Delphi. The source tree is a real mess. I'm trying to do 2 things: to make clean directory structure and to set up automated build process.

Right now i have produced following directory tree

  \Project
     \build\output   
     \dist\release
     \dist\debug
     \doc
     \env
     \res
     \src

\src directory contains *.pas and *.dfm files and project.dpr. Various resources (icons, images and fonts) are reside in \res directory. \env is used to create various environments for debugging purposes. IDE was setted up to build project.exe into this dir.
Build scripts are stored in build folder. These scripts produce product distribution (with and without debug information in exe) in dist\release and dist\debug folders with help of dcc32.exe. build\output is used to save dcu files during build process inside IDE or inside build script.

There is a little flaw in my approach. I can not start with fresh computer, checkout code from my repo, start building script and receive ready to use disitribution of the project. I need to open IDE first, install required components (e.g. RXLib and MemoEx), set up library paths and so on. Only after that steps i can run my building scripts.

It was not a big problem until last week. I've modified 3rd party component in order to fix a bug (this component isn't maintained anymore :-(), so i have to add code of this component to the structure of my project. At this point if i will checkout from the repo I need to check if there were changes in code of 3rd party libs. If code of libs was changed I need to recompile components and reinstall them.

Questions

  1. Is there any way to reinstall components in Delphi 7 from command line? Is there any way to do it without hardcoding installation path of D7?
  2. How would you store code of third part components in project tree?
  3. Where should i place bpl and dcu which will be produced during build of components. Should i place them at Project\build\output? Or it will be better to place output to another location (do not override Delphi settings), but change Library path in project configuration?

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

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

发布评论

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

评论(3

不醒的梦 2024-11-09 15:01:38
  1. 您只需使用 delphi 命令行编译器编译该包即可。如果 Delphi bin 路径在您的 PATH 中,则无需对安装路径进行硬编码。如果您的构建系统能够从注册表中读取,您将获得路径,例如 HKEY_LOCAL_MACHINE\SOFTWARE\CodeGear\BDS\6.0\RootDir (在本例中为 Delphi 2009)。

  2. 我会为每个包添加另一个带有子分支的分支组件。不要将它们与您的项目混合。

  3. 根据我的经验,最好的做法是将它们保留在 delphi 目标中(取决于 delphi 版本)。

  1. You just have to compile the package with the delphi commandline compiler. If the Delphi bin path is in your PATH you don't have to hard code the installtion path. If your build system is able to read from the registry you get the path e.g. HKEY_LOCAL_MACHINE\SOFTWARE\CodeGear\BDS\6.0\RootDir (Delphi 2009 in this case).

  2. I would add another branch components with subbranches for every package. Do not mix them with your projects.

  3. From my experience the best practive is to keep them in the delphi destination (where depends on the delphi version).

千鲤 2024-11-09 15:01:38

更新:注意到问题的“从命令行安装请求”部分。

您无法真正从命令行安装,但构建一些东西很容易
就是这样做的。您可以使用 DCC32.EXE 编译包。

组件的安装由注册表项控制。对于每个版本的 Delphi,注册表中的位置都不同,但它确实遵循相同的基本模式。
示例:

德尔福 2007
HKEY_CURRENT_USER\Software\Borland\BDS\5.0\Known Packages
德尔福XE
'HKEY_CURRENT_USER\Software\Embarcadero\BDS\8.0\Known Packages'

在构建所有第 3 方组件后,我们使用 FinalBuilder 更新此内容。
它使每个开发人员更容易保持同步。

至于目录结构,我预先考虑版本控制并执行以下操作。

根目录...

C:\dev\trunk\

这使我能够以简单的格式创建分支。

C:\dev\branch1\

从那里我执行以下操作:

我使用 \Bin 和 \DCU 的公共目录,因为我进行了大量的包开发
其中许多需要在设计时加载。这可以避免添加很多
目录到系统路径以使 Delphi 满意。

\output\DelphiXE\Bin
\output\DelphiXE\Dcu

如果需要这样,可以增强这一点:

\output\DelphiXE\Release\Bin
\output\DelphiXE\Release\Dcu
\output\DelphiXE\Debug\Bin
\output\DelphiXE\Debug\Dcu

对于每个项目,我都会这样做,尽管我经常将多个项目放在同一个项目中
目录如果依赖大部分相同的代码。

\project\ (DPR/DPK Here)
\project\source (if the project is small, if not I break it out further)
\project\forms\
\project\classes\
\project\datamodules\
\project\resources\
\project\install\ (Install Scripts)
etc...

不同项目通用的组件和代码的finally。

\Commonlib\ (Directory for my code that common among projects)
\Components\3rdPartyName\
\Components\3rdPartyName2\
\Components\3rdPartyName3\

我这样做是为了通过仅使用版本控制修订号来了解构成我的应用程序版本 X 的所有内容。

最重要的是,我为

C:\DEV\TRUNK\

创建一个环境变量,然后在系统库路径中使用该环境变量。
像这样:

%MYCODE%components\3rdParty1;%MYCODE%components\3rdParty2\

然后,如果我必须切换分支,我可以更改环境变量,重新启动 Delphi 以及使用该版本的代码库的所有内容。

Update: Noticed the Install from command line Request part of the question.

You can't really install from the command line but it would be easy to build something
that did that. You can compile the packages using DCC32.EXE.

The installation of components is controlled by registry entries. The location in the registry is different for each version of Delphi, but it does follow the same basic pattern.
Examples:

Delphi 2007
HKEY_CURRENT_USER\Software\Borland\BDS\5.0\Known Packages
Delphi XE
'HKEY_CURRENT_USER\Software\Embarcadero\BDS\8.0\Known Packages'

We update this using FinalBuilder, after we have build all the 3rd party components.
It makes it easier to keep each developer in sync.

As for directory structure, I think about version control up front and do the following.

Root Directory...

C:\dev\trunk\

This allows me to create branches in an easy format.

C:\dev\branch1\

From there I do the following:

I use a common directory for \Bin and \DCU since I do a lot of package development
many of which need to be loaded at design time. This prevents having to add many
directories to the system path to keep Delphi happy.

\output\DelphiXE\Bin
\output\DelphiXE\Dcu

This can be enhanced if need to be like this:

\output\DelphiXE\Release\Bin
\output\DelphiXE\Release\Dcu
\output\DelphiXE\Debug\Bin
\output\DelphiXE\Debug\Dcu

The for each project, I do this, although often I place more than one project in the same
directory if the rely on the majority of the same code.

\project\ (DPR/DPK Here)
\project\source (if the project is small, if not I break it out further)
\project\forms\
\project\classes\
\project\datamodules\
\project\resources\
\project\install\ (Install Scripts)
etc...

The finally for components and code common to different projects.

\Commonlib\ (Directory for my code that common among projects)
\Components\3rdPartyName\
\Components\3rdPartyName2\
\Components\3rdPartyName3\

I do it this way so I know every thing made up my version X of my application by just using the version control revision number.

To top this off I create an environment variable for

C:\DEV\TRUNK\

Then I use the environment variable in the system library path.
Like this:

%MYCODE%components\3rdParty1;%MYCODE%components\3rdParty2\

Then if I have to switch branches I can change the environment variable relaunch Delphi and everything using that version of the code base.

坠似风落 2024-11-09 15:01:38

1:是和否,您可以设计您自己的组件从命令行安装(其中“从命令行”意味着以编程方式安装它们,如果您确实想要命令行,您可能需要编写工具)。第三方组件通常附带一个安装程序,该安装程序的作用比安装和注册组件本身还要多。理论上,您可以自动化安装程序执行的所有操作,并本质上重新打包组件供您自己使用,但这样做可能会遇到法律障碍。

2:第 3 方组件不与项目绑定。将这些文件存储在项目目录中并不是一个好主意。当您在其他项目中重用相同的组件时会发生什么?您是否将所有源文件复制到新项目中?对于我自己的工作,我已将所有第 3 方组件安装到一个文件夹中,与任何项目的目录分开,并将该文件夹置于版本控制之下。

3:为每个项目使用单独的输出目录是一个好主意,它使使用条件编译变得更加容易。我建议为调试和发布使用单独的输出目录。关于第 3 方 BPL,它们也不是项目的一部分,因为没有一个项目“拥有它们”。

1: Yes and no, you can design your own components to be installed from the command line (where "from the command line" means install them programatically, if you really want command line, you might need to write the tool). 3rd party components usually come with an installer that does more then install and register the components themselves. Theoretically you can automate everything the installer does and essentially repackage the component for your own use, but you might run into legal barriers doing this.

2: 3rd party components aren't tied to a project. Storing those files in the project directory is not a good idea. What happens when you reuse the same components in an other project? Do you copy all source files to the new project? For my own work I've got all 3rd party components installed into one folder, separate from any project's directory, and I keep that folder under version control.

3: Using a separate output directory for each project is a good idea, it makes using conditional compilation much easier. I'd suggest separate output directories for Debug and Release. About 3rd party BPL's, they're also not part of the project because no single project "owns them".

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