22

I am looking to implement a continuous unit test running system, something I have heard called a "smoketest" or "tinderbox", (a build server that does clean version control check-outs and full system builds of everything in a given source repository or project), and something like "continuous integration" for small teams, with Delphi.

I am loathe to commit to a commercial "build server" product and am hoping I can do a lot of this just with MS-Build support that is built into delphi.

I am looking for resources, ideas, and a place to get started. I do not know how to use MS Build for this purpose. Steve Trevethen has a blog post that leads to a little discussion on the old dcc32 command line build, and some comments mention ms-build which has been here since delphi 2007. I am using Delphi 2010. I am looking for guidance and insight, and experiences, that will tell me, is this a reasonable path to go down, and if not, what way should I go instead?

I found you can override the Unit (DCU) and EXE Output Directory from the msbuild command line with /p:DCU_DcuOutput=. Note that I looked at the XML inside my DPROJ files to figure out how to override stuff.

However, it only does a make, not a build, and /t:rebuild does not work (edit: yes it does. it works fine on DPROJ files, but not on GroupProjects.)

I wish there was more MSBuild-with-Delphi documentation out there anywhere? The MS-Build help in "Rad Studio 2010" product documentation shows one or two things about MS-Build but is really sketchy and incomplete.

Related questions:

MSBuild command lines

Community
  • 1
  • 1
Warren P
  • 65,725
  • 40
  • 181
  • 316
  • Offtopic, but we use Cygwin makefiles and dcc32 for stuff like this. The reason is most of our projects have roots in the Delphi 5 and earlier world, so we just stick to what we know... but it works fine and is free. – Paul-Jan Feb 22 '10 at 19:16
  • `/t:rebuild` does a full build for me, with Delphi 2009 on dproj files, have you tried running msbuild on the dproj instead of the groupproj? http://stackoverflow.com/questions/1773546/how-can-i-get-msbuild-to-do-a-full-build-of-a-delphi-project-equivalent-to-dcc32/1774169#1774169 – jasonpenny Feb 22 '10 at 19:18
  • Try mingw's tools, it saves you a lot of path trouble compared to cygwin/ msys. Unfortunately mingw seems to have ceased coreutils builds – Marco van de Voort Feb 23 '10 at 08:34
  • In recent years I have taken to using "want" on top of msbuild, which gives java-style "build.xml" (ant) tooling to Delphi. wantnext project page: https://bitbucket.org/wpostma/wantnext – Warren P Sep 21 '16 at 11:28

3 Answers3

17

Delphi 2010 uses MSBuild as it's main build engine. That means that the IDE and the command line both do exactly the same thing. It also means that you can easily build existing projects with the command line. In fact, we on the Delphi team do this exact thing all the time. You need not worry about switches for the compiler itself -- the DProj file created by the IDE will

On the Start Menu is a command line for using MSBuild with an existing Delphi project. It sets up the environment correctly so that you can simply call:

msbuild myproject.dproj

You can also call specific build configurations from the command line, using the IDE to easily create said configurations using command line parameters for MSBuild.

If you want to create the environment yourself, you can run the rsvars.bat batch file to set things up. That file can be found in your \bin directory, and should be available from a default command line.

The file contains the following:

@SET BDS=<your BDS directory>
@SET BDSCOMMONDIR=C:\Users\Public\Documents\RAD Studio\7.0
@SET FrameworkDir=C:\Windows\Microsoft.NET\Framework\v2.0.50727
@SET FrameworkVersion=v2.0.50727
@SET FrameworkSDKDir=
@SET PATH=%FrameworkDir%;%FrameworkSDKDir%;%PATH%
@SET LANGDIR=EN

Thus, if you want to create your own continuous integration build, you can easily manage your Delphi build using MSBuild.

Nick Hodges
  • 16,902
  • 11
  • 68
  • 130
  • 1
    SO far so good, but somewhere it is documented that to do a build instead of a recompile, I should use /t:rebuild. Any idea what the flag is to force a build instead of a dependency-check (aka, make)? – Warren P Feb 22 '10 at 19:17
  • Looks like /t:rebuild works, but only with .dproj passed to msbuild, not project groups. Which is fine. Just a little more cutting and pasting for me. – Warren P Feb 22 '10 at 19:26
  • Lars has noted that /t:Build works for .GroupProj whereas its /t:Rebuild for .dproj files. Eccentric, but workable. – Warren P Feb 22 '10 at 19:51
  • 1
    Actually, Build is a target in both and does what you want: Build. ReBuild is an extra target .dproj has and it does a Clean before Build. – Lars Truijens Feb 22 '10 at 20:10
  • 4
    Be aware there are some issues when using msbuild outside the IDE: 1) Build number is increased by the IDE, not the compiler, and there's no easy way to set it outside the IDE 2) Prebuild/Postbuild vars may not be set to the correct value –  Feb 22 '10 at 22:20
  • I think I will need to write some code to do things like that. (1) Increment build numbers, set versioninfo strings to "tinderbox build svn rev ABC, date YYYY-MM-DD HH:NN:SS, machine {MACHINENAME}" – Warren P Feb 25 '10 at 14:01
  • `'msbuild' is not recognized as an internal or external command, operable program or batch file.` I think something is missing from the answer. – Ian Boyd Apr 07 '21 at 16:17
11

The dproj and groupproj are msbuild files and you can have a look inside them. The other parts of the information are to be find in the msbuild installation path (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727). There you will find several Borland.*.targets files.

Inside the msbuild scripts you can see the different targets named with . For example the groupfile contains Make, Clean and Build targets which you can specify with the /t parameter. The same goes for the dproj files. dproj files also have a ReBuild target. It does a Clean and then a Build. If you want to have the same effect for groupfile you could specify two targets: /t:Clean;Build

You will also find lots of parameters in you can set with /p. Like for example Configuration to specify the configuration or DCC_Quiet to instruct dcc32 to stop outputting useless whitespaces.

So the doing a build with Release configuration from the command line is this command:

msbuild mygroup.groupproj /p:Configuration=Release /t:Build

disclaimer: I have looked at Delphi 2007's msbuild files. Later Delphi versions might have changed the name of the targets or parameters. Just have a look inside the msbuild scripts to find out which is which.

Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
  • 1
    It is very helpful to know you can do /t:Build on a groupproj – Warren P Feb 22 '10 at 19:50
  • 1
    @ldsandon: Microsoft is responsible for documenting MSBuild; after all, it is their product. Perhaps you should check their website - [MSDN](http://msdn.microsoft.com) for the [MSBuild reference](http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx)? – Ken White May 16 '11 at 20:42
  • 1
    @Ken White: MS documents MSBUild, and BorCodeDero should document its *.targets files... or does it expect MS will document them also? –  May 16 '11 at 21:40
4

I'm not sure if this is what you need, but I have CruiseControl.NET setup for doing continuous integration - and DUnit tests - for Delphi 2009. CCNET has a specific set of tasks for MSBuild, and other than a few setup issues, it works perfectly for me.

I can let you know what I had to do get ths working if you need.

Mark

mmmm
  • 2,431
  • 2
  • 35
  • 56
  • Have you tried TeamCity too? It has a free 'Professional' license. – mjn Feb 23 '10 at 07:53
  • I am interested in CruiseControl.NET. Please post a link to any "Delphi with CruiseControl.NET" info you have. – Warren P Feb 23 '10 at 14:36
  • You could look on my Blog, I think there is something there. If not I can certainly add something, as I have just upgraded to the latest version. – mmmm Feb 23 '10 at 17:30
  • 2
    See whether this link helps - http://inpwtepydjuf.blogspot.com/2010/02/delphisurroundcruisecontrolnet-howto.html – mmmm Feb 27 '10 at 22:06
  • +1 for TeamCity as a build server. We use it for Java and Delphi builds and find it very flexible. Hudson is nice too, but requires more work to get up and running. – David Taylor Mar 08 '10 at 18:21