使用 scons 运行 perl 脚本(自动生成一系列文件),然后编译这些文件并创建静态库
我正在将我们的项目从 make 移植到 scons,但遇到了一些问题。 我们有许多 Perl 脚本,通过 make 运行,生成一系列 C++ 源文件。 然后这些文件被编译成静态库。
目前,我可以通过 scons 运行 perl 脚本,并使用一些额外的 python 脚本编译文件,但是,似乎应该有一种更简单的方法来做到这一点。
我还发现 scons 脚本似乎不是线性执行的。脚本的某些部分正在无序执行。
这是我的新兵;
// SConscript file
import platform
import os
import glob
import time
Import('directEnv')
cohEnv = directEnv.Clone()
includePath = Split("""
#Direct/include
#Direct/libsrc/liblog
#Direct/libsrc/libtime
#tools/include
#Direct/include
#Direct/engine
""")
if platform.machine() == 'i686':
includePath = includePath + ['#tools/coh-cpp-v3.6-linux-x32/coherence-cpp/include']
else:
includePath = includePath + ['#tools/cohe-cpp-v3.5.3b465-linux-x64/coherence cpp/include']
cohFiles = Split("""
#Direct/include/IntApi.h
#Direct/include/MessagingApiRisk.h
#Direct/include/MessagingApiCommon.h
""")
cohEnv.Append(CPPPATH = includePath)
cohEnv.Append(CCFLAGS = '-D_FILE_OFFSET_BITS=64 -DUTPBRIDGE -Wno-unused-variable')
cohEnv.Append(LIBS = Split('nsl m rt'))
#
# Run Perl script - this generates approx 30 c++ source files
#
Clean('.', '#Direct/coh/cpp/CohMsgObj_0.cc')
temp1 = cohEnv.RunPerl('#Direct/coh/cpp/CohMsgObj_0.cc', '#Direct/coh/BuildCohObjs.pl')
Depends(temp1, '#Direct/coh/BuildCoherenceObjs.pl')
Depends(temp1, '#Direct/include/IntApi.h')
#
# Run Perl script - this generates 3 c++ source files
#
Clean('.', '#Direct/coh/cpp/Print_BinV4.cc')
temp2 = cohEnv.RunPerl('#Direct/coh/cpp/Print_BinV4.cc', '#Direct/coh/BuildCohObjsRisk.pl')
Depends(temp2, '#Direct/coh/BuildCohObjsRisk.pl')
#
# Build the object and library
#
print os.getcwd()
os.chdir('../../cpp')
path = os.getcwd()
print path
#
# get all the c++ source files that we need to compile
#
List = []
for infile in glob.glob(os.path.join(path, '*.cc')):
List.append(infile)
count = 0
suffix = ".cc"
ObjectList = []
#
# create objects for each source file
# I'm trying to create variables dynamically - incase the files which generates the
# source files change - I don;t want to manually list everything that needs to be compiled
for item in List:
locals()['obj%s' % count] = coherenceEnv.Object(item[:-len(suffix)] + '.o' , item)
print "obj%s" % count
ObjectList.append(coherenceEnv.Object(item[:-len(suffix)] + '.o' , item))
count = count + 1
#
# create a static library using the newly created objects
#
cohLib = cohEnv.StaticLibrary(target = 'riskpo', source = [cohFiles, ObjectList])
cohEnv.Install('#/lib', [cohLib])
目前这可行,但远非理想。 有没有更好更直接的方法来使用基本的 scons 命令来做到这一点, 另外,如何使用 scons 对执行流程强制执行顺序。 谢谢 D
I'm porting our project from make to scons and I'm encountering a few issues.
We have a number of perl scripts that we run through make which generate a series of C++ source files.
These files are then compiled into a static library.
At present I can run the perl scripts through scons and compile the files with a bit of additional python scripting, however, it seems like there should be an easier way to do this.
Also I'm finding that the scons script doesn't seem to be executed linearly. Parts of the script are being executed out of order.
Here is my sconscript;
// SConscript file
import platform
import os
import glob
import time
Import('directEnv')
cohEnv = directEnv.Clone()
includePath = Split("""
#Direct/include
#Direct/libsrc/liblog
#Direct/libsrc/libtime
#tools/include
#Direct/include
#Direct/engine
""")
if platform.machine() == 'i686':
includePath = includePath + ['#tools/coh-cpp-v3.6-linux-x32/coherence-cpp/include']
else:
includePath = includePath + ['#tools/cohe-cpp-v3.5.3b465-linux-x64/coherence cpp/include']
cohFiles = Split("""
#Direct/include/IntApi.h
#Direct/include/MessagingApiRisk.h
#Direct/include/MessagingApiCommon.h
""")
cohEnv.Append(CPPPATH = includePath)
cohEnv.Append(CCFLAGS = '-D_FILE_OFFSET_BITS=64 -DUTPBRIDGE -Wno-unused-variable')
cohEnv.Append(LIBS = Split('nsl m rt'))
#
# Run Perl script - this generates approx 30 c++ source files
#
Clean('.', '#Direct/coh/cpp/CohMsgObj_0.cc')
temp1 = cohEnv.RunPerl('#Direct/coh/cpp/CohMsgObj_0.cc', '#Direct/coh/BuildCohObjs.pl')
Depends(temp1, '#Direct/coh/BuildCoherenceObjs.pl')
Depends(temp1, '#Direct/include/IntApi.h')
#
# Run Perl script - this generates 3 c++ source files
#
Clean('.', '#Direct/coh/cpp/Print_BinV4.cc')
temp2 = cohEnv.RunPerl('#Direct/coh/cpp/Print_BinV4.cc', '#Direct/coh/BuildCohObjsRisk.pl')
Depends(temp2, '#Direct/coh/BuildCohObjsRisk.pl')
#
# Build the object and library
#
print os.getcwd()
os.chdir('../../cpp')
path = os.getcwd()
print path
#
# get all the c++ source files that we need to compile
#
List = []
for infile in glob.glob(os.path.join(path, '*.cc')):
List.append(infile)
count = 0
suffix = ".cc"
ObjectList = []
#
# create objects for each source file
# I'm trying to create variables dynamically - incase the files which generates the
# source files change - I don;t want to manually list everything that needs to be compiled
for item in List:
locals()['obj%s' % count] = coherenceEnv.Object(item[:-len(suffix)] + '.o' , item)
print "obj%s" % count
ObjectList.append(coherenceEnv.Object(item[:-len(suffix)] + '.o' , item))
count = count + 1
#
# create a static library using the newly created objects
#
cohLib = cohEnv.StaticLibrary(target = 'riskpo', source = [cohFiles, ObjectList])
cohEnv.Install('#/lib', [cohLib])
At the moment this works, however its far from ideal.
Is there a better more straighforward way to do this using basic scons commands,
Also how can I enforce order on the flow of execution using scons.
thanks
D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当从 Make 迁移到 SCons 时,人们通常遇到的问题之一是理解,对于 SCons,您不指定顺序,您告诉 SCons 什么构建什么,然后 SCons 将(通常)连接这些点并找出顺序。
对于生成许多 .c 文件的 perl 脚本,问题是 SCons 不知道这些生成的文件,因此不会找到它们,这意味着 SCons 不知道在任何步骤之前运行 perl 脚本使用它的输出。
您应该查看用户指南,尤其是有关此问题的发射器的部分:
http://scons.org/doc/product/HTML/scons-user /x3689.html
wiki 是示例的另一个来源。
http://scons.org/wiki/DynamicSourceGenerator
和
http://scons.org/wiki/ToolsForFools
可能适用。
生成的 C 文件列表是静态的和/还是可以由另一个文件的内容确定?
When migrating from Make to SCons one of the issues people usually run into is understanding that with SCons you don't specify the order, you tell SCons what builds what and then SCons will (usually) connect the dots and figure out the order.
With your perl scripts which generate many .c files, the problem is that SCons doesn't know about those generated files, and so they won't be found, which means that SCons won't know to run the perl script before any steps which use it's outputs.
You should take a look at the user guide, especially the section on emitters for this issue:
http://scons.org/doc/production/HTML/scons-user/x3689.html
The wiki is another source for examples.
http://scons.org/wiki/DynamicSourceGenerator
and
http://scons.org/wiki/ToolsForFools
May apply.
Is the list of generated C files static and/or can it be determined by the contents of another file?