SCons: Get abspath of original file (as though I hadn't set variant_dir)

旧巷老猫 提交于 2019-12-22 04:18:20

问题


I can use File('foo.bar').abspath to get the location of a file, but if I've got variant_dir set then the returned path will be in variant_dir rather than it's original location. If I have duplicate=0 set, then the file returned won't actually exist.

Obviously SCons knows where the original file is, as it's passed as an argument when the file's actually built (eg gcc -c -o variant/foo.o orig/foo.c).

Is there some sort of File('foo.bar').origpath that I can use?

If it came to it I could use os.path.join(Dir('#').abspath, 'orig') but that requires the SConscript to know which directory it's in, which is messy.


回答1:


You can use srcnode(). To quote the man page:

The srcnode() method returns another File or Dir object representing the source path of the given File or Dir.

This will give you the absolute path in the source directory:

File('foo.bar').srcnode().abspath


来源:https://stackoverflow.com/questions/6066545/scons-get-abspath-of-original-file-as-though-i-hadnt-set-variant-dir

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!