【问题标题】:scons sequential commands not as expected in dependency treescons 顺序命令与依赖树中的预期不同
【发布时间】:2013-08-14 11:52:37
【问题描述】:

我正在运行一个由 SConstruct 调用的 SConscript,它除了设置环境和 Export('env') 之外什么都不做。 SConscript 应该遍历文件名如 mod_abc.c 的文件,并为每个文件 - 首先创建一个 xml 目录,生成一个 structdoc,创建一个文件 mod_abc_post.c,然后创建一个目标文件和一个“.so”文件。之后,它应该删除 xml 文件并重新启动下一个 mod_*.c 文件的过程。 脚本如下:

import os
Import('env')

my_libs = 'jansson'
postc_files = Glob('mod_*_post.c')
all_mods = Glob('mod_*.c')

mods = set(all_mods) - set(postc_files)
mods = list(mods)

env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME']=1

xml_cmd_str = '(cat ../Doxyfile.configxml; echo "INPUT=%s";) | doxygen - > xml%s'
structdoc_cmd_str = 'python ../prep_structdoc.py xml mod_config mod_mtx update_mtx serialize_mtx "mod_evt_" > %s'
preprocess_cmd_str = 'python ../preprocess_mod.py xml %s %s > %s'


for mod in mods:
    #create doxy file
    xml_dir = env.Command('xml%s' % mod.name, mod, xml_cmd_str % (mod.name, mod.name))

    mod_name = mod.name[:-2]
    struct_doc = '%s.structdoc' % mod_name

    #using Command instead of os.popen as clean can take care of structdoc
    sdoc = env.Command(struct_doc, xml_dir, structdoc_cmd_str % struct_doc)

    processed_file= '%s_post.c' % mod_name
    pfile = env.Command(processed_file, sdoc, preprocess_cmd_str % (mod_name, struct_doc, processed_file))

    obj_file = env.Object(target='%s.o' % mod_name, source=pfile)

    shared_target = '%s.so' % mod_name
    env.SharedLibrary(target=shared_target, source=obj_file, LIBS=my_libs)

    py_wrapper = env.Command('%s.py' % mod_name, pfile, 'ctypesgen.py %s %s -o %s' % (processed_file, mod.name, '%s.py' % mod_name))

    # remove xml once done
    remove_xml = env.Command('dummy%s' %mod.name, py_wrapper, 'rm -rf xml')

我已经注意到 xml_dir 目标获得了一个特定的名称,因为该 xml 命令应该只针对该 mod_name 运行。问题是依赖关系树不像预期的那样。 我希望每个文件都有这样的树

-remove xml  
--create py_wrapper  
---create so file  
----create o file  
-----create _post.c file  
------create .structdoc file  
-------create xml directory  

但我通过 scons --tree=ALL 得到的只是其中之一 mod_serialize_example.c 是:

不按顺序排列,中间还有其他mod_*.c文件的东西。

[Some other things before this]
 +-dummymod_serialize_example.c
  | +-mod_serialize_example.py
  | | +-mod_serialize_example_post.c
  | | | +-mod_serialize_example.structdoc
  | | | | +-xmlmod_serialize_example.c
  | | | | | +-mod_serialize_example.c
  | | | | +-/usr/bin/python
  | | | +-/usr/bin/python
  | | +-/usr/local/bin/ctypesgen.py
  | +-/bin/rm
[Some other things after this]

 +-libmod_serialize_example.so
  | +-mod_serialize_example.o
  | | +-mod_serialize_example_post.c
  | | | +-mod_serialize_example.structdoc
  | | | | +-xmlmod_serialize_example.c
  | | | | | +-mod_serialize_example.c
  | | | | +-/usr/bin/python
  | | | +-/usr/bin/python
  | | +-mod_serialize_example.c
  | | +-/path/to/header files included
  | | +-/usr/bin/gcc
  | +-/usr/bin/gcc
 +-mod_addition.c [ Some other module ]

 +-mod_serialize_example.c
  +-mod_serialize_example.o
  | +-mod_serialize_example_post.c
  | | +-mod_serialize_example.structdoc
  | | | +-xmlmod_serialize_example.c
  | | | | +-mod_serialize_example.c
  | | | +-/usr/bin/python
  | | +-/usr/bin/python
  | +-mod_serialize_example.c
  | +-/path/to/header files included...
  | +-/usr/bin/gcc
 +-mod_serialize_example.py
  | +-mod_serialize_example_post.c
  | | +-mod_serialize_example.structdoc
  | | | +-xmlmod_serialize_example.c
  | | | | +-mod_serialize_example.c
  | | | +-/usr/bin/python
  | | +-/usr/bin/python
  | +-/usr/local/bin/ctypesgen.py
  +-mod_serialize_example.structdoc
  | +-xmlmod_serialize_example.c
  | | +-mod_serialize_example.c
  | +-/usr/bin/python
  +-mod_serialize_example_post.c
  | +-mod_serialize_example.structdoc
  | | +-xmlmod_serialize_example.c
  | | | +-mod_serialize_example.c
  | | +-/usr/bin/python
  | +-/usr/bin/python
  +-pfile
  +-xml
[some other stuff]
 +-xmlmod_serialize_example.c
    +-mod_serialize_example.c

我对 mod_serialize_example.c 的期望是

+-rm xml
 |+-libmod_serialize_example.so
      | +-mod_serialize_example.o
      | | +-mod_serialize_example_post.c
      | | | +-mod_serialize_example.structdoc
      | | | | +-xmlmod_serialize_example.c
      | | | | | +-mod_serialize_example.c
      | | | | +-/usr/bin/python
      | | | +-/usr/bin/python
      | | +-mod_serialize_example.c
      | | +-/path/to/header files included
      | | +-/usr/bin/gcc
      | +-/usr/bin/gcc

但是,我看到了这一点,而且远远超出了要求。 (上面的也是手动完成的,以了解该过程,请原谅使用 + 和 | 的缩进)
他们不应该聚在一起吗? (如预期的树所示,并像循环一样重复不同的文件名)。
另外,我刚开始使用 scons,任何有助于使这个设计更简洁的帮助都会有所帮助。
1.我想知道如何得到期望的树
2. 我怎样才能让这个脚本取一个模块名并只在那个上面运行 for 循环代码。
例如: scons mod_abc.c 应该只为此创建 .so 文件。 截至目前,如果我这样做,这不会产生任何结果。

【问题讨论】:

    标签: python command dependencies scons


    【解决方案1】:

    你为什么会期待这样的树?例如,您的共享库上没有任何(显式或隐式)依赖。所以它将作为图表顶部的目标之一。

    【讨论】:

    • 是的,预期的图表本身就位于顶部。我的问题是,为什么在实际输出中有这么多其他东西显示为依赖项,(在实际输出中,这个 .so 文件是第二部分)
    • 顶部的图表显示 .so 作为 remove xml 的依赖项。您或许应该尝试 --tree=all,prune。默认情况下,如果 A 依赖于 B,而 B 又依赖于 C,而 D 也依赖于 B,那么 C 会显示两次。此外:remove_xml = env.Command('dummy%s' %mod.name, py_wrapper, 'rm -rf xml') 不依赖于您的共享库。这取决于其他东西。
    • 哦,好吧,所以当两个事物具有相同的依赖关系时,依赖关系会出现两次。那么预期的树是错误的,我不应该期望它会像编写的代码那样。保持原样是否足够,因为它正在工作或重新组织代码以生成预期的树?
    • 你需要考虑你想要的依赖关系。这棵树没有错——它试图用 ascii 艺术在二维中显示不一定是二维的东西。但是,正如我所说,我认为您对树外观的期望与您的代码不匹配。此外,在我看来,1)您正在删除中间构建目标,这将导致 scons 必须重新生成它们;2)这不会在并行构建中起作用,因为您正在删除包含构建目标的目录t 属于当前规则
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多