组织搜索路径 [英] Organizing the search path

查看:103
本文介绍了组织搜索路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们通过工具|选项|环境变量创建变量:

We create via "Tools | Options | Environment Variables" Variables like that:

$(Sources) = D:\Sources\Delphi
$(OurLib) = $(Sources)\OurLib\Src
$(OurApp1) = $(Sources)\Applications\App1\3.x
$(ThirdParty) = $(Sources)\ThirdPartyComponents

我们在项目中使用这些变量这样的搜索路径:

We use these Variables in the project search path like that:

($OurApp1)\Src\Core;($OurApp1)\Src\GUI;($OurApp1)\Src\Plugins;$(ThirdParty)\JVCL

但是自Delphi 2009以来,由于这些变量不再被完全评估(参见 QC#73276 )。所以编译器找不到目录中的文件。解决方法:仅使用环境变量中的完整目录。

But this is broken (meanwhile fixed) since Delphi 2009 as these variables are not evaluated completely anymore (see QC #73276). So the files in the directories are not found by the compiler. A workaround: Use only complete directories in the environment variables.

我们使用这种方法,因为在所有开发人员机器和构建服务器上都可以找到文件,我们只需点$(来源)到正确的地方。

We use this approach because on all developer machines and the build servers the files can be found and we only have to point $(Sources) to the right place.

我们的全局库路径中没有任何东西(Delphi默认值除外),因为它不会在版本控制中,并没有反映在其他开发人员或构建机器。

We don't have anything in our global library path (except the Delphi defaults), because that wouldn't be in the version control and isn't reflected on other developers or build machines.

一个问题是:如果$(OurLib)中的一个单元决定添加另一个新单元,则可能在新路径中,所有项目都会因为找不到这个新单位。那么我们必须经过所有的项目并添加搜索路径。 (BTW:我真的讨厌搜索路径编辑器...这不是一个简单的备忘录字段比这个替换/添加/删除逻辑更好编辑)。

One problem is: If one unit in $(OurLib) decides to include another new unit maybe in a new path, all projects break because they don't find this new unit. Then we have to go through all projects and add the search path. (BTW: I really hate the search path editor...wouldn't be a simple memo field much better to edit than this replace/add/delete logic?)

我们做的另一件事就是在我们的项目中增加许多单位。特别是从$(OurLib)的所有东西,但是我们经常有像插件这样的单元,只能通过包含它们来添加功能。对于不同版本的产品,我们希望包含不同的单位。由于Delphi总是在.dpr中的uses子句中混淆$ IFDEF,所以我们帮助我们,包括名为IncludePlugins的单元,然后包含单位取决于IFDEF。
但不包括项目中的单位导致痛苦。单位不出现在项目中,它们没有被Ctrl + 12(显示单位)找到,它们没有在代码完成等中显示。

Another thing we do is not adding many units to our project. Especially everything from $(OurLib), but we often have units like plugins which add functionality only by including them. For different editions of our products, we want to include different units. As Delphi always messes up $IFDEFs in the uses clause in the .dpr we help us by including units named like "IncludePlugins" which then include the units depending on IFDEFs. But not including units in the project makes navigating to a pain. The units don't appear in the project, they are not found by Ctrl+12 (Show Units), they are not shown in code completion etc.

有人更好的方式来应对这些问题?

Has anybody a better way to cope with these problems?

推荐答案

我们只使用相对路径,任何库总是在libs子目录下,而项目源代码驻留在src子目录中。所以我们的搜索路径总是如下所示:

We use only relative paths, any libraries are always below the libs subdirectory while the project source code resides in the src subdir. So our search paths always look like:

.. \libs\library1; .. \libs\library2\common;

..\libs\library1;..\libs\library2\common;

等。

所有库都添加为每个项目的svn:external,因此检出项目将自动检出库好的,搜索路径将始终指向该项目的正确版本的库。

All libraries are added as svn:external to each project, so checking out the project will automatically check out the libraries as well and the search path will always point to the correct version of the library for that project.

不完美,但大部分时间都可以工作。

Not perfect, but it works most of the time.

我必须同意搜索路径编辑器,因为相对路径更糟糕,因为您不能使用...按钮,否则Delphi将插入绝对路径。

I have to agree about the search path editor, it is even worse for relative paths because you must not use the "..." buttons otherwise Delphi will insert an absolute path.

这篇关于组织搜索路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆