Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get scons to treat a directory itself as a target?

Tags:

scons

doxygen

I'm trying to set up a build involving an external tool which produces a directory as output (doxyindexer for the curious). So far, I've essentially got these commands:

target = "doxysearch.db/iamchert"
doxygen.Doxyindexer(target,["project1.xml","project2.xml","project3.xml"])
Default([target])
Default(Install(ARGUMENTS["cgibin"],"doxysearch.db"))

The problem that I'm having is that I think I'd like target to be the directory itself, not some random file inside the directory. There's nothing I can glob because the target doesn't exist until I build it and I don't want to presume anything that Dimitri might change! When I use the directory as the target, I get this error:

TypeError: Tried to lookup Dir 'doxysearch.db' as a File.:

which is why I picked iamchert to be the target. Those lines all seem to work as expected, even if my approach is a hack. However, I can't get that last line to work. I need to copy the directory doxysearch.db into the cgi-bin directory, which is specified on the command line by the user. Maybe someone can explain how to do this step properly? I'm a newb when it comes to scons!

I'm having trouble googling the answer because all the search words involved are too common to find me specific help!

like image 413
amos Avatar asked Oct 11 '25 15:10

amos


2 Answers

SCons does in fact treat all the files in a dir as dependencies of that dir. There are some dark corners that need work, but it should work in a simple case like this.

What you need is the undocumented target_factory builder flag. When you define Doxyindexer do it like this:

doxyindexer = Builder(..., target_factory=env.fs.Dir)

and have your builder return the dir itself. That should avoid the TypeError you were getting.

like image 151
GaryO Avatar answered Oct 16 '25 13:10

GaryO


Im not sure how well SCons will work with the target being a directory. The issue is: How should SCons determine if the directory has changed or not to know if it should be built? The obvious answer would be that a directory is considered to be changed if it has more or less files therein, but I dont think SCons currently does this check and you might have to make your own builder to get it.

I did the following example to test this, and it never builds:

env = Environment()
env.Command(target = 'targetDir',
            source = 'srcTextFile',
            action = Copy("$TARGET", "$SOURCE"))

When I execute SCons, I always get the same result:

scons: '.' is up to date

Regarding your SCons code, I think it would work better as follows:

targetDir = "doxysearch.db/iamchert"
srcFiles = ["project1.xml","project2.xml","project3.xml"]

doxygenTarget = doxygen.Doxyindexer(targetDir, srcFiles)

    # This may need to be called via the Command() builder like this:
    # cmd = "doxygen.Doxyindexer("$TARGET", "$SOURCE")
    # doxygenTarget = env.Command(target=targetDir, source=srcFiles, action=cmd)

# This call to Default isnt really necessary
Default(doxygenTarget)
Install(ARGUMENTS["cgibin"], doxygenTarget)
like image 34
Brady Avatar answered Oct 16 '25 13:10

Brady