SCons:获取原始文件的绝对路径(好像我没有设置变体目录) [英] SCons: Get abspath of original file (as though I hadn't set variant_dir)

查看:15
本文介绍了SCons:获取原始文件的绝对路径(好像我没有设置变体目录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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).

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

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

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

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.

推荐答案

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

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

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

这篇关于SCons:获取原始文件的绝对路径(好像我没有设置变体目录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆