Pre and Post-Build Automation in Delphi
Extend the BDS IDE so that Pre-Build and Post-Build tasks can be automated
(http://delphi.about.com/od/devutilities/a/pre_post_build.htm)
Article submitted by Fernando Madruga
This article describes a simple way to extend the BDS IDE so that Pre-Build and Post-Build tasks can be automated without a single line of code.
Why Pre or Post-Build?
I’m trying to create my first shareware program in my free time. With that comes adding some security measures and so I chose Armadillo (now SoftwarePassport). The way this protection works is by wrapping the program’s EXE which means it has to be done after building the main program.
This protective wrapper needs to be in place even for development work, be that to test settings related to the protection itself or simply to avoid a large number of conditional defines to block code out.
For the last few days I’ve been trying to automate the process which involves running a windows application with certain parameters. Because there is not much information on how to successfully accomplish this, I decided to write this article to share the workaround that I found to be very good, at least until Delphi gains a more customizable builder.
The solution to Pre-Build and Post-Build in the BDS IDE
The whole idea works around 2 concepts applied together: using Build Tools and Project Groups.
I’ll describe the process for the Post-Build situation in my particular case, but, by playing around with the build order, this can easily be adapted to Pre-Build too and you can even have several Pre and Post-Build tools being executed.
Step-by-step instructions
Let’s start by opening your project.
Right-click on the Project Group and select "Add New Project…".
Any type of project will do, I selected a console application and named it PostBuild, but again, any name will do. You can keep your project the Active one.
Save all that and choose a proper name for the .bdsgroup file.
Right-click on the PostBuild project in the project explorer and select "Dependencies": this is one of the most important steps because in here you can say that this project (PostBuild) depends on another one (your main project), so that it will always be built after your main one.
Now for the tool configuration. In my particular case, I need to run the following command line:
"C:\Program Files\SoftwarePassport\Armadillo.exe" "D:\Dev\My Prog\Prot.arm" /P
So, let’s do two things here: add the Prot.arm file to the Post-Build project and create a Build Tool to handle .arm files.
The Build Tools dialog, or more specifically, the "Add…" sub-dialog, could use a bit more explanation in the help file but eventually I got it working as you might have guessed or I would not be writing this article!
The key points in this dialog are:
Title: Anything will do but using a descriptive title always helps
Default Extensions: *.arm (this is for my case for the example command-line above)
Command Line: This is the trickiest of them all, but after you get one working, they’re all easy. The trick here is not to use quotes on the program’s name but instead use the windows SFN (Short File Name). The reason is that, should you need to use quotes to enclose the path of your file, the IDE gets confused with too many quotes. So, these are the wrong ways of adding that command line above:
C:\Program Files\SoftwarePassport\Armadillo.exe D:\Dev\My Prog\Prot.arm /P
"C:\Program Files\SoftwarePassport\Armadillo.exe" D:\Dev\My Prog\Prot.arm /P
C:\Program Files\SoftwarePassport\Armadillo.exe "D:\Dev\My Prog\Prot.arm" /P
"C:\Program Files\SoftwarePassport\Armadillo.exe" "D:\Dev\My Prog\Prot.arm" /P
This last one should work, if it were not for the IDE to be confused with it. So, what does work is either of these:
C:\Progra~1\Softwa~1\Armadillo.exe "D:\Dev\My Prog\Prot.arm" /P
C:\Progra~1\SoftwarePassport\Armadillo.exe "D:\Dev\My Prog\Prot.arm" /P
The 1st one is a "true" SFN (if in doubt, run CMD.exe and do a dir /X "C:\"; it's not critical that you use a "true SFN", the important thing is that no part of the full path + program name has spaces in it as you can see in the 2nd example, thus leaving the quotes available for use on the file name. Of course, we don’t want this exactly as it is as it would be hard coded. We can use some Macros to make it more generic, so here are the Add Build Tool contents for my case:
Title: ArmProtect
Default Extensions: *.arm
Command Line: C:\Progra~1\SoftwarePassport\Armadillo.exe "$PATH$NAME" /P
Using these Macros is also the reason why I used SFN on the program and not on the filename! In this case, "$PATH$NAME" gets expanded to "D:\Dev\My Prog\Prot.arm".
Don't forget that this tool will only be used on the extensions indicated in this dialog.
You can also, at any point in time, manually run this command by right-clicking any *.arm file on your project and selecting the tool from the menu.
The final step to remember is to Build All Projects (you can give it a keyboard shortcut to make it easier to use and/or put it on your toolbar).
Pre and Post-Build in Short
Add a Post-Build "void" project to your project group;
Right click that project, select Dependencies and make it depend on your main project
Add the file you want to be processed after building your program to the PostBuild project
Create a Build Tool to run the proper command-line and associate it with that file’s extension (don't forget about using SFN for the program name)
Always load the .bdsgroup instead of the .bdsproj and use Project -> Build All Projects whenever you want the Pre/Post-Build to work.
Final Notes
You may need to exit and re-open the IDE for it to acknowledge changes to Build Tools, especially when you just added a new one.
Adding a Pre-Build is also easy to achieve playing with the project’s dependencies: you will need to make your main project dependent on the PreBuild one.
If you need to add some step that does not depend on any type of file, simply make up some extension (use 4 or more characters to avoid conflicts with existing extensions) and create a void file of that extension to associate with the Build Tool, for instance, "nothing.step1".
If you want to customize the Build Current Project key to perform Build All Projects instead, take a look at the free GExperts Add-In.
Discuss "Automating Pre and Post-Build Events"
Share your thoughts, questions, comments ...
Suggested Reading
Understand Delphi Versions and Pick your Delphi of Choice
Protect your Delphi Software
Developing Shareware with Delphi
Related Articles
Two Applications In One Delphi Program - Part 2 / 5
BuildMate Simplifies REALbasic Projects
Build Configurations in VB.NET
Stay Organized - How to Organize Your Business
kdevelop - What is kdevelop
分享到:
相关推荐
LS-PrePost是一款强大的有限元前处理和后处理软件,主要应用于工程力学、机械设计、航空航天、汽车工业等领域。这款软件以其用户友好的界面和强大的几何建模、网格划分、结果可视化功能而闻名。"LS-PrePost-4.8-x64-...
LS-PrePost是一款由ANSYS公司开发的专业有限元前处理器,它主要用于创建、编辑和预处理复杂的几何模型,以及对模型进行网格划分。在这款软件的4.7.20-x64-24Aug2020版本中,我们看到了64位系统的支持,这表明它可以...
这篇文章《2020-Rethinking Pre-training and Self-training.pdf》针对这两种方法进行了重新思考,并提出了新的见解和实验结果。 首先,我们需要理解预训练的概念。预训练指的是在一个大型和多样化的数据集上训练...
poj 1240 Pre-Post-erous!.md
clibwrapper_jiio-1.2-pre-dr-b04.jar jar包,好不容易才找到的,需要的话请下载。
软件介绍: LS-PrePost-3.2-Win32是一款先进的前置后置处理器,直观有效的用户界面界面,可运行在WIN/LINUX系统上,利用OpenGL图形实现快速绘制和XY绘图UNIX,是anasys、lsdyna装机必备工具。
ANSYS LS-DYNA后处理软件的4.3版本,通过LS-DYNA运行以后可以通过这个软件进行一系列结果数据的读取工作。
HCS-Pre-sales-IP 华为数通安全售前专家认证 H19-366题库
华为HCS-Pre-Sales-Bidding H19-365(含参考答案).pdf
System, method, and apparatus for digital pre-emphasis in low power serdes systems Method, digital signal processing module and system for efficiently selecting a pre-emphasis filter during line ...
.archanyconnect-win-3.1.00495-pre-deploy-k9.msi
最新版dyna前处理,后处理软件,ansys-dyna必备,好用!
在Subversion(简称SVN)中,`pre-revprop-change` 是一个钩子脚本,用于在修改版本库中的修订版本属性之前执行特定的检查和操作。在Windows环境下,通常使用`.bat`批处理文件作为`pre-revprop-change`的实现。此...
HCS-Pre-sales-IP
no swt-mozilla-gtk-4335 in java.library.path no swt-mozilla-gtk in java.library.path /root/.swt/lib/linux/x86_64/libswt-mozilla-gtk-4335.so: libxpcom.so: cannot open shared object file: No such file ...
HCS-Pre-sales-IP-2022.pdf 摘要信息中,我们可以了解到HCS-Pre-sales-IP 2021的考试大纲和考试题目,涵盖了TCP/IP网络协议、网络HCS-Pre-sales等知识点。 知识点1: 交换机的包转发率/转发能力 交换机的包转发率/...
最新版dyna前处理,后处理软件LS-PrePost,ansys-dyna必备,好用!
标题中的"jogl-1.1.2-pre-20080523-windows-i586.zip"是指JOGL的一个特定版本,即1.1.2预发布版,发布日期为2008年5月23日,适用于Windows操作系统和i586(Intel Pentium 4或更早的32位CPU)架构。这个压缩包包含...