Make target depend on future unknown target

I want my target to depend on another target which I do not know the name or path of at the time I specify my depending target. I cannot use Depends at a later time when the second target is known for some reasons.

Is it possible to make some kind of placeholder which I can later set? I imagine something like

target1 = <placeholder_of_some_sort>
target2 = Program(files + [target1])

# Set target1 later
target1 = Object(...)

This does not work, however, because scons looks for the placeholder dependency.

EDIT:

The example shows the essence of problem I'm trying to solve. In reality I have a large and complex build system with dozens of SConscript files calling other SConscript files in a hierarchical fashion. I generate one or more targets depending on some user input:

for x in user_input:
    targets.append(env.SConscript(daughter_sconscript))

The targets generated are independent of each other ... except for an ugly edge case, where, depending on some user input, one of the calls to one of the daughter SConscript files generates an extra object file, which later is used in another call to the same daughter SConscript file.

The order in which the targets are generated depends on user input (user types scons 1 2 3 vs scons 3 2 1 ), so it is not guaranteed that the extra object is described to SCons, while the call to the SConscript which needs that object is executed. So I want to tell Scons "Hey, I know this target is going to need an object file, but it has not been described yet".

I could hardcode a name for the extra object file in the SConstruct file:

extra_object = File("path")

for x in user_input:
    targets.append(env.SConscript(daughter_sconscript, exports = {"extras": extra_object}))

But this clutters my SConstruct with details. I want to keep it as focused as possible, and let the daughter sconscript take care of the naming and path.

Thanks!


First I wouldn't use the DefaultEnvironment (What you get when you use Program and not for example env.Program())

env=Environment()
env.Program('program_name',files + env['SOME_TARGET_NAME'])

.... later assuming shared env

env['SOME_TARGETNAME'] = env.SharedObject('fun_source.c')

Does this solve it for you? Or did you have a different use model.

A more common workflow would be to create a library (assuming this would be in a different directory) and then link that (by name) with the program

Top Level SConstruct:

env=Environment()
env.SConscript('program/SConscript', exports='env')
env.SConscript('other_dir/SConscript', exports='env')

program/SConscript:

Import('env')
env.Program('program_name',files+env['SOME_TARGET_NAME'])
or
env.Program('program_name',files,LIBPATH='#/other_dir',LIBS=['otherlib'])

other_dir/SConscript

Import('env')
env['SOME_TARGETNAME'] = env.SharedObject('fun_source.c')
or
env.StaticLibrary('otherlib',['fun_source.c'])
链接地址: http://www.djcxy.com/p/67924.html

上一篇: SCons未能找到生成的文件

下一篇: 目标取决于未来的未知目标