views:

1037

answers:

12

Currently I'm using a Windows batch file to build my software. It does things like running MSBuild, copying files, creating a ZIP file, running some tests, including the subversion revision number, etc.

But the problem is, batch files are evil. So I would like to change to something better. I was planning to recreate my build script in Python. Is that a smart choice? What about all those build systems, like Ant, SCons, Maven, Rake, etc. Would using any of those be a better choice?

Note: I'm not planning to replace my Visual Studio solution/project files. I only want to script everything else that's required to create a release of my software.

Edit: I have good reasons to move away from batch, that's not what my question is about. I would like to know (for example) what SCons gives me, over a normal Python script.

+3  A: 

I've seen python scripts used for building releases elsewhere so it can't be bad. Actually, I've personally used perl scripts to automate release building. I guess any scripting language could easily automate that procedure. If it's gonna be easy to do (and probably better than batch scripts), why not try it?

alkar
+6  A: 

As you're mentioning Python and SCons, I'd say go for SCons. It is Python after all. And yes, any of the above would be a better choice than hand-rolled build scripts.

+1  A: 

Personally I would use scripting as a last resort given that

  • With a bit of work you can get MSBuild to do all those things for you by extending it with additional components
  • There are third party equivalents to MSBuild like NANT that can do the same thing
  • There are entire tools like FinalBuilder that also do the same thing, and are easier to configure and extend

However, if I had to go the scripting route I would use Powershell for a couple of reasons:

  • Complete access to file system
  • You can easily access .NET objects
  • You can easily access COM objects
Conrad
None of his requirements need access to .NET or COM. File system access is basic enough that anything has that.
Joey
My point was its pretty easy to write .NET or COM classes to do things like run tasks, zip files, ftp, etc, or better yet reuse existing ones. If you have classes that do this manipulating them would be easier using a technology that natively supports .NET
Conrad
Where can I find these 'additional MSBuild components'?
compie
Have a look at this http://www.codeplex.com/MSBuildExtensionPack/
Conrad
+8  A: 

For a tool that is scripted with Python, I happen to think Paver is a more easily-managed and more flexible build automator than SCons. Unlike SCons, Paver is designed for the plethora of not-compiling-programs tasks that go along with managing and distributing a software project.

bignose
+1 -> This looks really interesting - thanks!
Jon Cage
although paver is quite nice for automation, and may well be sufficient for the OP, paver does not really do any kind of elaborate dependency management.I use paver myself for cross platform "driver" scripts (which may well call scons underhood). What scons gives you is a top notch dependency system, at the cost of a much greater complexity.
David Cournapeau
+4  A: 

Batch files aren't evil - they've actually come quite a long way from the brain-dead days of command.com. The command language can be pretty expressive nowadays, it just requires a bit of effort on your part to learn it.

Unless there's an actual problem with your build script that you can't fix (and, if that's the case, that's the question you should be asking rather than some wishy-washy "What's the best replacement?" :-), my approach would be to stick with what you've got.

A vague feeling of evilness would not be reason for me to waste effort 'fixing' something that isn't broken. And it would be wasted effort unless there's a clear advantage to changing ("less evil" is not something I'd consider a clear advantage).

paxdiablo
+1 for "if it ain't broke don't fix it"
Jon Cage
+1 for the "if it ain't broke don't fix it", -1 for "it just requires a bit of effort on your part to learn it". Writing something which goes beyond calling a program in Batch files is still many times more complicated than in anything else :(
Aaron Digulla
I was just about to ask why batch files are evil.. +1
rpr
+1: Batch files are a huge pain in the neck because the decision-making and looping are so primitive. Exception handling is virtually non-existent -- except via GOTO's.
S.Lott
+1  A: 

You can create custom makefiles for Microsoft nmake tool which you already have installed. Using a tool like that (SCons, Maven, etc. fall into the same category) gives you much more than regular scripts.

The main benefit is that dependencies between files are tracked and also the timestamps of changes. For example, you can make your .zip file depend on some other files, so .zip only gets repacked if some of those files have changed in the meantime. Just like with source code and its compiled form.

Milan Babuškov
+1  A: 

Python is very portable. SCons is field tested and reliable. Given what you know (from what you explained), why even ask the question?

If your maintaining something, its not just about getting it to build, its also about explaining to the user why it can NOT build, which saves you a ton of very frustrating questions while helping users to help themselves.

I can not think of a modern, production operating system that lacks Python, unless you get into the embedded / research arena.

So, I'm answering to say, you answered your own question :)

Tim Post
+2  A: 

I would suggest using NAnt for your build script instead of python. My reasons for this are:

  • It has the tasks defined already, all you need to do is write the XML and point it to the right places. If you are working with people who do not know python, XML may be a little less scary than learning a new language.
  • NAnt is designed to work in the windows .Net environment, so it can already do MSBuild and NUnit tasks.
  • If you are already writing in C#, if you need to extend NAnt to do new tasks you are not adding another language to the mix of your project.
  • You can hook into Cruise Control .Net (for continuous builds). Which I think is the main reason why you would use NAnt.
Andrew Cox
"If you are working with people who do not know python, XML may be a little less scary" - On the other hand, if you're working with people who DO know python, python is a LOT less scary than XML.
Jason Baker
A: 

It depends on what technology your software uses. If you're building C++ programs, I'd probably say go for scons without question (unless you have weird requirements scons can't meet). On the other hand, consider the instructions for building C#: CSharpBuilder.

I would like to know (for example) what SCons gives me, over a normal Python script.

Think of scons as being more of a library than a program. It provides you with code that will prevent a lot of tedium that you will have to deal with without it. In my opinion, vanilla Python isn't the best option for any kind of shell scripting stuff (not that it can't do it).

But the problem is, batch files are evil.

Lastly, batch files are evil if they're used for a project they're not suited to handle. For the one or two file project, batch files do just fine.

Jason Baker
+1  A: 

Why should you use python? If your build script isn't broke don't fix it. If your having issues updating it to deal with new aditions to the project then you may want to look at rewriting it. I wouldn't use Python though tools like NANT or MSBuild do the job. I don't see the point in using a general purpis programming language to do something that tools have already been written to do unless you have a lot of obscure requirements existing tools can't deal with. Second what happens if you get hit by a bus or win the lotto? If you are determined to script everything I'd use powershell or some other Microsoft specific technology since your already wedded to Microsoft. If you leave will there be enough Python programmers to maintain the build scripts?

Jared
+2  A: 

I would strongly suggest to take a look at waf. It's kind of what you want: "a Python-based framework for configuring, compiling and installing applications"

A: 

It does things like running MSBuild, copying files, creating a ZIP file, running some tests, including the subversion revision number, etc.

MSBuild and PowerShell can easily do all of this with reasonably clean succinct code. You're then sticking to purely M$ products which managers tend to like. Otherwise I would suggest you could look into Rake if not only for its large community. It has a nice syntax and iron ruby support (irake).

To be honest all but the last task you have mentioned are easily done in MSBuild alone. I would suggest learning the tools you have before going elsewhere.

Check out http://msbuildtasks.tigris.org/ for some good add ons to MSBuild

RhysC