在 SCons 中,我的命令生成器创建了非常长的命令行。我希望能够将这些命令拆分为多行,以便在构建日志中阅读。
例如,我有一个 SConscipt,例如:
import os
# create dependency
def my_cmd_generator(source, target, env, for_signature):
return r'''echo its a small world after all \
its a small world after all'''
my_cmd_builder = Builder(generator=my_cmd_generator, suffix = '.foo')
env = Environment()
env.Append( BUILDERS = {'MyCmd' : my_cmd_builder } )
my_cmd = env.MyCmd('foo.foo',os.popen('which bash').read().strip())
AlwaysBuild(my_cmd)
当它执行时,我得到:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
echo its a small world after all \
its a small world after all
its a small world after all
sh: line 1: its: command not found
scons: *** [foo.foo] Error 127
scons: building terminated because of errors.
在带有 os.system 和 os.popen 的 python shell 中执行此操作——我得到一个可读的命令字符串,并且子 shell 进程将所有行解释为一个命令。
>>> import os
>>> cmd = r'''echo its a small world after all \
... its a small world after all'''
>>> print cmd
echo its a small world after all \
its a small world after all
>>> os.system( cmd)
its a small world after all its a small world after all
0
当我在 SCons 中执行此操作时,它一次执行每一行,这不是我想要的。
我还想避免将我的命令构建到 shell 脚本中,然后执行 shell 脚本,因为这会造成字符串转义的疯狂。
这可能吗?
更新:
cournape,
感谢您提供有关 $CCCOMSTR 的线索。不幸的是,我没有使用 SCons 开箱即用支持的任何语言,所以我正在创建自己的命令生成器。使用生成器,我怎样才能让 SCons 去做:
echo its a small world after all its a small world after all'
但打印
echo its a small world after all \
its a small world after all
?