SCons:获取原始文件的abspath(好像我没有设置variant_dir)

mcc*_*ean 8 scons

我可以File('foo.bar').abspath用来获取文件的位置,但是如果我设置了variant_dir,那么返回的路径将在variant_dir而不是它的原始位置.如果我已duplicate=0设置,则返回的文件实际上不存在.

显然,SCons知道原始文件的位置,因为它在文件实际构建时作为参数传递(例如gcc -c -o variant/foo.o orig/foo.c).

有什么File('foo.bar').origpath我可以使用的吗?

如果它来了我可以使用,os.path.join(Dir('#').abspath, 'orig')但这需要SConscript知道它在哪个目录,这是凌乱的.

ric*_*chq 8

你可以用srcnode().引用手册页:

srcnode()方法返回另一个表示给定File或Dir的源路径的File或Dir对象.

这将为您提供源目录中的绝对路径:

File('foo.bar').srcnode().abspath
Run Code Online (Sandbox Code Playgroud)