[Scons-users] How to build only a subset of targets under a directory

Mats Wichmann mats at wichmann.us
Fri Apr 1 19:23:46 EDT 2022


On 4/1/22 14:51, Jay West wrote:
> Using a target file is good when you want to compile only one target. 
> In this case, there may be a lot of targets within a subdirectory, so
> naming every target associated with, say "test" within a subdirectory is
> not practical.  In general, you don't know the specific names of all the
> "test" targets within a subdirectory.

So pretty much "no", though there may well be ways to fiddle it.

SCons either does automatic target selection, or you select targets
manually.  The automatic selection takes "all within the scope", where
the default scope is the project root.  If you give a directory in place
of a command-line target, that changes the scope, so you can do:

scons top/aa

and you'll only get targets under that dir - but you'll get all of
those. So if you wanted, say, just the tests in that directory tree,
that doesn't do the "subset of targets under a directory" bit from the
subject line.

>         Is there a way to build only a subset of targets under a
>         directory, instead of all targets under that directory?
> 
>         For example:
> 
>         top/aa
>           Alias('bin', bin_a)
>           Alias ('test', test_a)
>         top/bb
>           Alias('bin', bin_b)
>           Alias ('test', test_b)
> 
>         scons top/aa # builds bin_a and test_a
>         scons bin # builds bin_a and bin_b
> 
>         I want to do something like:
>         cd top/aa; scons bin # build only bin_a
Alternatively, you can do manual target selection by either using
Default(), or by giving targets on the command line.  That turns off
automatic selection, so you need to give all the targets you want
(excepting dependencies, which will be built if they have to).  Aliases
are a convenient way to (a) name things in an easier way and (b) group
several targets into a single name.   Once you give a target on the cli,
it will be built, and that turns off the automatic selection, so as
you've seen a global "test" Alias can't be limited down to a single
directory.  I suppose some sort of fliter function could have been
defined to work in conjunction with aliases, but that isn't the case.

>         I want to do something like:
>         cd top/aa; scons bin # build only bin_a

Have you tried a combination of -C and -u options?  I'm not sure they
get you any closer, but they seem to be defined for fiddling of this
nature.  I don't have any personal experience with those so I'll just
stop here...



More information about the Scons-users mailing list