How can I force the SConscript constructor to change the directory?

I'm currently trying to transfer a legacy project with a million sloc from boring .cmd scripts to SCons. Its parts are VC ++, others are Delphi. Creating SConscripts for pieces of C ++ was easy.

To create the delphi part, I wrote a very simple builder that determines if this is a program or library project. Calling the builder after chaining through SConscript causes scons to call dcc32 $ subdir / project.dpr, which confuses dcc32 to search for units in the current directory instead of $ subdir.

Is there a way to tell scons to enter $ subdir before executing the commands in sconscript, or should I fix it inside the builder?

Thank you in advance

+5
source share
1 answer

Schoolchildren already change SConscripts to a directory of subdirectories when reading them, so it seems that the problem should be fixed in the actual builder.

After the scripts are parsed and SCons runs the build commands, it remains in the top-level directory. Commands are then issued using path names relative to this top-level directory. A way to change this behavior is to use a keyword chdirin your Builder.

An example from the man scons page is as follows:

b = Builder(action='build < ${SOURCE.file} > ${TARGET.file}',
            chdir=1)
env = Environment(BUILDERS = {'MyBuild' : b})
env.MyBuild('sub/dir/foo.out', 'sub/dir/foo.in')

You need to specify the component .file, since use chdirdoes not change the names passed to the builder, i.e. they still belong to the top-level directory.

+5
source

All Articles