Keeping SConstruct Files Easy to Read
One drawback to the use of a Python list
for source files is that
each file name must be enclosed in quotes
(either single quotes or double quotes).
This can get cumbersome and difficult to read
when the list of file names is long.
Fortunately, SCons and Python provide a number of ways
to make sure that
the SConstruct file stays easy to read.
To make long lists of file names
easier to deal with, SCons provides a
Split function
that takes a quoted list of file names,
with the names separated by spaces or other white-space characters,
and turns it into a list of separate file names.
Using the Split function turns the
previous example into:
env = Environment()
env.Program('program', Split('main.c file1.c file2.'))
|
Putting the call to the Split function
inside the env.Program call
can also be a little unwieldy.
A more readable alternative is to
assign the output from the Split call
to a variable name,
and then use the variable when calling the
env.Program function:
env = Environment()
list = Split('main.c file1.c file2.')
env.Program('program', list)
|
Lastly, the Split function
doesn't care how much white space separates
the file names in the quoted string.
This allows you to create lists of file
names that span multiple lines,
which often makes for easier editing:
env = Environment()
list = Split('main.c
file1.c
file2.c')
env.Program('program', list)
|