Determine list of source files (*.[ch]) for a complex build with scons

青春壹個敷衍的年華 提交于 2019-12-07 02:00:59

问题


Suppose you have a complex source tree for a C project, lots of directories with lots of files. The scons build supports multiple targets (i386, sparc, powerpc) and multiple variants (debug, release). There's an sconstruct at the root (referencing various sconscripts) that does the right thing for all of these, when called with arguments specifying target and variant, e.g. scons target=i386 variant=release.

Is there an easy way to determine which source files (*.c and *.h) each of these builds will use (they are all slightly different)? My theory is that scons needs to compute this file set anyway to know which files to compile and when to recompile. Can it provide this information?

What I do not want to do:

  • Log a verbose build and postprocess it (probably wouldn't tell *.h files anyway)
  • find . -name '*.[ch]' also prints unwanted files for unit testing and other cruft and is not target specific

Ideally I would like to do scons target=i386 variant=release printfileset and see the proper list of *.[ch] files. This list could then serve as input for further source file munging tools like doxygen.


回答1:


There are a few questions all squashed together here:

  • You can prevent SCons from running the compiler using the --dry-run flag
  • You can get a dependency tree from SCons by using --debug=tree, or --tree=all flags, depending on which version you are running
  • Given a list of files, one per line, you can use grep to filter out only the things that are interesting for you.

When you put all of that together you end up with something like:

scons target=i386 variant=release printfileset -n --tree=all | egrep -i '^ .*\.(c|h|cpp|cxx|hpp|inl)$'


来源:https://stackoverflow.com/questions/7283452/determine-list-of-source-files-ch-for-a-complex-build-with-scons

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