spaceblog

<strike>archie</strike>barry the archive browser

Peter messaged me and said “pybaz is easy, I’ll send you the script I wrote to crawl an archive.”

He was right, and amidst claims of slacking off from my boss, I hacked up archie:

jaq@spacepants.org--2004/archie--main--0

I couldn’t think of a better name; Archie is what they used to call the FTP search engines of antiquity. Actually there was a commandline tool called veronica IIRC, but betty was never used, so perhaps… naw.

Don’t expect it to do much atm, and it’s pretty slow :-) Punch in your archive name in the box and twiddle your thumbs.

Update: It’s now called barry, given that “baz” is clearly his nickname. No relation to Sydney Swans star forward :-) Find him at:

jaq@spacepants.org--2004/barry--main--0

gtk arch browser

I would really love a dinky little app that I could point at an arch repository and then it could tell me the relationship that its component branches had to each other, and maybe one hop outside of the repository.

I remember James Blackwell (I think it was he) posted to the gnu-arch-users list once with some code that walked the supermirror and generated a graphviz file of the tla branches. That was cool, but it got pretty large; too large to take in in one sitting.

Basically I have several branches of some code and I haven’t touched this code for something like 6 months so of course I don’t remember where I was up to nor which branch I was in. I’d like to see the relationship between them. Extra points if I can click on a branch and have it checked out somewhere.

Double-extra points if it also copes with the couple of “config-only” branches I have and reads the build-config information, and groups the sub-branches together under the config-only branch.

I think I’m motivated enough to write one… the hard part is going to be working out how to use pybaz :-)

unit testing in SCons

The scons-users mailing list has a few references to how people have implemented unit tests in their build, very few of those are accompanied by code examples. The SCons wiki has a page on unit tests, which sucks to say the least.

What I want is what Greg Ward wants:

  • all the tests should run when one types scons check.

  • if SCons builds nothing, the unit tests should also not run

  • if the unit test source changes, the unit test should be built and run

  • if code that the test links or includes changes, the test should be rebuilt and run

The second part is pretty easy, actually. SCons’ dependency handling is so awesome it just works. You can ensure that a program is run after it is built by using AddPostAction:

1
2
test = env.Program('test.c')
env.AddPostAction(test, test[0].abspath)

and as long as your test program is self contained (i.e. it’s a real unit test and not a subsystem test framework, i.e. testing various inputs as they go through your parser, say) then it just works.

You can build the first rule with an Alias – SCons will let you append targets to an Alias to accumulate what that alias does:

1
env.Alias('check', test)

and you can make sure that the test is always “run” (i.e. built) by using AlwaysBuild:

1
env.AlwaysBuild(test)

(In the latest version of SCons, the soon to be 0.97 that is currently still in CVS, you can call AlwaysBuild on an alias, making this last line look instead like:

1
env.AlwaysBuild('check')

and then you only need it once.)

The problem with this approach is that you really want to alias the post action, not the build of the test. Consider this:

% scons check
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o input/filtergen/t/scan input/filtergen/t/scan.o
/home/jaq/src/filtergen/filtergen--unittests/input/filtergen/t/scan
scons: done building targets.

Notice how scan is relinked before execution? That’s because we told SCons to AlwaysBuild the test program. But when we’re running the test, we only want to relink the program iff its source or dependencies have changed. I haven’t yet found a way to make this work the “right” way – I’ve tried to use Command in place of the post action with no success.

Anyway, you can bundle this all together with a new Tool like so:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from SCons.Script.SConscript import SConsEnvironment

def UnitTest(env, source, **kwargs):
    test = env.Program(source, **kwargs)
    env.AddPostAction(test, test[0].abspath)
    env.Alias('check', test)
    env.AlwaysBuild(test)
    return test

SConsEnvironment.UnitTest = UnitTest

Then use it in your code like so:

1
2
3
4
5
scan = env.UnitTest('scan.c',
                    CPPPATH=testcpppath,
                    LIBPATH=testlibpath,
                    LIBS=testlibs,
                    CPPFLAGS=testcppflags)

python mind maps

So, a while ago, I started hacking on a mind mapping tool, in Python, to collect ideas about a sekrit project that was rapidly spawning ideas. I got far enough to remember I hated gnomecanvas, and chucked it in arch:

jaq@spacepants.org--2004/mindmap--main--0

I was thinking of calling it butchers-paper, in honour of the old-skool mindmapping tool.

I was thinking about it on the way home from work tonight. I think my subconscious checked out my RSS feeds before liferea did…

So, it turns out that Hanna started writing one, and this one looks more feature complete, though I like my ellipses better :-)

change compile-command depending on the build system in use

After last week rediscovering emacs’ M-x compile, and using it almost non-stop whilst hacking on filtergen, I got frustrated each time I used a fresh emacs and had to tell it to use scons -D instead of make (I’ve bound F7 to compile, which doesn’t prompt for the invocation command).

So here’s a bit of emacs lisp for your ~/.xemacs/init.el (or .emacs if you so desire) that alters compile-command for each buffer based on the existence of build system files:

1
2
3
4
5
6
7
8
;; If we're in a SCons build tree, set the compile-command correctly.
;; The cond can be extended for other build system files, too.
(add-hook 'c-mode-common-hook
      (lambda ()
        (cond ((or (file-exists-p "SConstruct")
                   (file-exists-p "SConscript"))
               (set (make-local-variable 'compile-command)
                    "scons -D")))))

Share and enjoy!