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-4.8-x64-15Sep2020,官网下载了老半天,下载进度经常性卡死,不容易不容易
poj 1240 Pre-Post-erous!.md
内含LS-PrePost-4.7.20-x64-24Aug2020_setup.zip安装包,有需要的可以下载
HCS-Pre-sales-数通安全-华为园区交换机产品介绍
ANSYS LS-DYNA后处理软件的4.3版本,通过LS-DYNA运行以后可以通过这个软件进行一系列结果数据的读取工作。
clibwrapper_jiio-1.2-pre-dr-b04.jar jar包,好不容易才找到的,需要的话请下载。
软件介绍: LS-PrePost-3.2-Win32是一款先进的前置后置处理器,直观有效的用户界面界面,可运行在WIN/LINUX系统上,利用OpenGL图形实现快速绘制和XY绘图UNIX,是anasys、lsdyna装机必备工具。
2020-Rethinking Pre-training and Self-training.pdf
HCS-Pre-sales-IP 华为数通安全售前专家认证 H19-366题库
华为HCS-Pre-Sales-Bidding H19-365(含参考答案).pdf
售前H19-369 HCS-Pre-sales-IT
Basic Math and Pre-Algebra For Dummies(2nd) 英文无水印原版pdf 第2版 pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn...
.archanyconnect-win-3.1.00495-pre-deploy-k9.msi
HCS-Pre-sales-IP-2022.pdf
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 ...
32位windows操作新系统 anasys、lsdyna装机必备,亲测
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 ...
华为TaiShan产品及解决方案,
目前网站上关于prelayout与postlayout介绍太少,这篇pdf文档详细对比了两者,方便各位学者学习。