【问题标题】:SCons: Get abspath of original file (as though I hadn't set variant_dir)SCons:获取原始文件的绝对路径(好像我没有设置variant_dir)
【发布时间】:2011-05-20 01:18:44
【问题描述】:

我可以使用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 知道它在哪个目录中,这很混乱。

【问题讨论】:

    标签: scons


    【解决方案1】:

    您可以使用srcnode()。引用man page

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

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

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

    【讨论】:

    • 啊,漂亮!我知道一定有这样的事情。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    • 2010-09-18
    • 1970-01-01
    • 2016-11-19
    • 1970-01-01
    相关资源
    最近更新 更多