代码之家  ›  专栏  ›  技术社区  ›  ereOn

SCons配置文件和默认值

  •  5
  • ereOn  · 技术社区  · 15 年前

    我有一个使用SCons(以及MinGW/gcc,具体取决于平台)构建的项目。这个项目依赖于其他几个库(我们称之为 libfoo libbar

    目前,我的 SConstruct C:\libfoo ).

    现在,我想在我的 S结构 利福 C:\custom_path\libfoo

    > scons --configure --libfoo-prefix=C:\custom_path\libfoo
    

    或:

    > scons --configure
    scons: Reading SConscript files ...
    scons: done reading SConscript files.
    ### Environment configuration ###
    Please enter location of 'libfoo' ("C:\libfoo"): C:\custom_path\libfoo
    Please enter location of 'libbar' ("C:\libfoo"): C:\custom_path\libbar
    ### Configuration over ###
    

    一旦选择,这些配置选项应该写入到某个文件中,并且每次都会自动重新读取 scons 跑。

    提供这样的机制?我如何实现这种行为?我并不完全精通Python,所以即使是显而易见的(但完整的)解决方案也很受欢迎。

    1 回复  |  直到 15 年前
        1
  •  5
  •   Community Mohan Dere    9 年前

    烤饼有一个功能叫做“ Variables ". 您可以对它进行设置,以便它非常容易地读取命令行参数变量。因此,在您的情况下,您可以从命令行执行以下操作:

    scons LIBFOO=C:\custom_path\libfoo
    

    ... 变量会在两次运行之间被记住。所以下次你跑的时候 scons

    # read variables from the cache, a user's custom.py file or command line
    # arguments
    var = Variables(['variables.cache', 'custom.py'], ARGUMENTS)
    # add a path variable
    var.AddVariables(PathVariable('LIBFOO',
            'where the foo library is installed',
            r'C:\default\libfoo', PathVariable.PathIsDir))
    
    env = Environment(variables=var)
    env.Program('test', 'main.c', LIBPATH='$LIBFOO')
    
    # save variables to a file
    var.Save('variables.cache', env)
    

    如果您真的想使用“-”样式选项,那么您可以将上面的选项与 AddOption 功能,但它更复杂。

    This SO question