我什么时候应该使用scons scanner vs parseDepends取决于

时间:2016-09-28 13:17:17

标签: scons

我对这个长期问题道歉。

以下是我想用scons

做的事情
  • 构建一个java组件之前一个语法文件组件(它是一个语音识别项目)。我的语法文件组件需要java组件进行自己的编译。
  • 使用多处理(-j)

到目前为止工作的是什么:

  • 95%的c ++代码与scons -j4完美搭配。正确创建了Dependcies树
  • 我们的自定义python构建器使用ant
  • 从java组件生成.jar

什么不起作用:

  • 使用-j4时,在java编译之前调用我们用于从语法文件组件生成二进制文件的自定义python构建器。

以下是生成sideLibrary.jar(使用Command)

的scons脚本文件
Import('common_env')
#Grab a copy of the top environment (the one sent by the SConstruct file)
common_env = common_env.Clone()
#Current working directory.
currentDir = common_env['ENV']['LOCALROOT'] + '/' + common_env.sconsGetCWD()
#Launches ant -q
tgts = common_env.Command(target = [currentDir + '/dist', currentDir + '/dialogeditor/lib', currentDir + '/doc/sdtk', currentDir + '/obj', common_env['ENV']['LOCALROOT'] + '/LINK/bin/win32/sideLibrary.jar'], source = 'build.xml', action = 'ant -q -f $SOURCE')
#Cleans the generated folders
common_env.Clean(tgts, '')

以下是用于生成语法二进制文件的scons脚本文件(使用自定义构建器):

Import('common_env')
#Creates a copy of the build environment sent from the SConstruct file.
common_env = common_env.Clone()
#Because this component is only compiled in win32
if (common_env['ENV']['CONFIG'] == "win32"):
    #Language of the grammar.
    common_env['ENV']['LANGUAGE'] = 'en'
    #Language pack.
    common_env['ENV']['LANGUAGE_PACK'] = 'English.America.3.3.0'
    #Grammar name
    common_env['ENV']['GRAMMAR_NAME'] = 'faa'
    #Compiles the grammar using a custom builder.
    common_env.buildGrammar(src = common_env['ENV']['LOCALROOT'] + '/LINK/bin/win32/sideLibrary.jar')

有人告诉我将 src = common_env ['ENV'] ['LOCALROOT'] +'/ LINK / bin / win32 / sideLibrary.jar'传递给我们的自定义构建器告诉scons他必须在调用buildGrammar之前自动等待sideLibrary.jar。我真的有疑问,因为doc只说:

  

source:表示要使用的源的Node对象列表   这个构建器函数用于构建目标。

这会带我到ScannerParseDepensDepends(我已经阅读了scons关于它们的文档)。

我不清楚我应该用哪一个来完成我想做的事情:强制编译java组件之前使用-j4编译另一个组件。

有人可以点亮我的灯笼吗?

谢谢

修改 (添加了依赖树)

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
copyAction(["LINK\bin\win32\msvcp100d.dll", "LINK\bin\win32\msvcr100d.dll", "LINK\bin\win32\mfc100d.dll", "LINK\bin\win32\mfc100ud.dll", "LINK\bin\win32\rdbgsetup_x86.exe"], ["C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcp100d.dll", "C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcr100d.dll", "C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100d.dll", "C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100ud.dll", "C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\RemoteDebugger\rdbgsetup_x86.exe"])
ant -q -f sr\side\build.xml
buildGrammar(["LINK\data\Grammars\src\grammars\AvailableCommand.xml", "sr\sra\src\grammars\en\faa\faa.autopron", "sr\sra\src\grammars\en\faa\faa.missing", "sr\sra\src\grammars\en\faa\faa.functions"], [])
+-.
  +-build
  | +-build\debug
  |   +-build\debug\sr
  |     +-build\debug\sr\side
  |     | +-build\debug\sr\side\win32
  |     |   +-sr\side\build.xml
  |     |   +-sr\side\side.sc
  |     +-build\debug\sr\sra
  |       +-build\debug\sr\sra\src
  |         +-build\debug\sr\sra\src\grammars
  |           +-build\debug\sr\sra\src\grammars\win32
  |             +-sr\sra\src\grammars\src_grammars.sc
  +-c
  +-cm
  | +-cm\sconsUtilities
  +-LINK
  | +-LINK\bin
  | | +-LINK\bin\win32
  | |   +-LINK\bin\win32\mfc100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcp100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcr100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100ud.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\RemoteDebugger\rdbgsetup_x86.exe
  | |   +-LINK\bin\win32\mfc100ud.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcp100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcr100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100ud.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\RemoteDebugger\rdbgsetup_x86.exe
  | |   +-LINK\bin\win32\msvcp100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcp100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcr100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100ud.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\RemoteDebugger\rdbgsetup_x86.exe
  | |   +-LINK\bin\win32\msvcr100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcp100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcr100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100ud.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\RemoteDebugger\rdbgsetup_x86.exe
  | |   +-LINK\bin\win32\rdbgsetup_x86.exe
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcp100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcr100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100d.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100ud.dll
  | |   | +-C:\svn\3rdParty\devTool\Microsoft_Visual_Studio_10.0\RemoteDebugger\rdbgsetup_x86.exe
  | |   +-LINK\bin\win32\sideLibrary.jar
  | |     +-sr\side\build.xml
  | |     +-C:\svn\3rdParty\devTool\apache-ant-1.9.2\bin\ant.BAT
  | +-LINK\data
  |   +-LINK\data\Grammars
  |     +-LINK\data\Grammars\src
  |       +-LINK\data\Grammars\src\grammars
  |         +-LINK\data\Grammars\src\grammars\AvailableCommand.xml
  +-SConstruct
  +-sr
    +-sr\side
    | +-sr\side\build.xml
    | +-sr\side\dialogeditor
    | | +-sr\side\dialogeditor\lib
    | |   +-sr\side\build.xml
    | |   +-C:\svn\3rdParty\devTool\apache-ant-1.9.2\bin\ant.BAT
    | +-sr\side\dist
    | | +-sr\side\build.xml
    | | +-C:\svn\3rdParty\devTool\apache-ant-1.9.2\bin\ant.BAT
    | +-sr\side\doc
    | | +-sr\side\doc\sdtk
    | |   +-sr\side\build.xml
    | |   +-C:\svn\3rdParty\devTool\apache-ant-1.9.2\bin\ant.BAT
    | +-sr\side\obj
    | | +-sr\side\build.xml
    | | +-C:\svn\3rdParty\devTool\apache-ant-1.9.2\bin\ant.BAT
    | +-sr\side\side.sc
    +-sr\sra
      +-sr\sra\src
        +-sr\sra\src\grammars
          +-sr\sra\src\grammars\en
          | +-sr\sra\src\grammars\en\faa
          |   +-sr\sra\src\grammars\en\faa\faa.autopron
          |   +-sr\sra\src\grammars\en\faa\faa.functions
          |   +-sr\sra\src\grammars\en\faa\faa.missing
          +-sr\sra\src\grammars\src_grammars.sc
scons: done building targets.

编辑2 添加了buildGrammar

def buildGrammar(target, source, env):
    LANGUAGE = env['ENV']['LANGUAGE']
    LANGUAGE_PACK = env['ENV']['LANGUAGE_PACK']
    GRAMMAR_NAME = env['ENV']['GRAMMAR_NAME']
    LINKD = env['ENV']['LINKD']
    SIDE_BINARY_DIR = LINKD + '/bin/win32'
    DATAPACK_OUT_UDIR = DATAPACK_OUT_DIR = LINKD
    GRAMMAR_SRC_DIR = env['ENV']['LOCALROOT'] + '/sr/sra/src/grammars/' + LANGUAGE + '/' + GRAMMAR_NAME
    GRAMMAR_SRC_FILES = glob.glob(GRAMMAR_SRC_DIR + '/*.grammar') + glob.glob(GRAMMAR_SRC_DIR + '/*.dictionary')
    CUSTOM_NL_FUNCTIONS_FILE = GRAMMAR_SRC_DIR + '/' + GRAMMAR_NAME + '.functions'
    PBS_FILE = env['ENV']['LOCALROOT'] + '/fwk/systemInterface/simnet/src/pbs_api.h'
    SIDE_LIBRARY_PATH = SIDE_BINARY_DIR + '/sideLibrary.jar'
    SRROOT = env['ENV']['LOCALROOT'] + '/sr'
    GRM_PROJECT = 'faa'
    UTIL_DIR = env['ENV']['LOCALROOT'] + '/sr/sra/utils/build'
    #CUSTOM_NL_FUNCTIONS_FILE
    print "(+) Generating " + CUSTOM_NL_FUNCTIONS_FILE
    customNlFunctionsFile = open(CUSTOM_NL_FUNCTIONS_FILE, "w")
    call("perl " + UTIL_DIR + '/header2Nuance ' + PBS_FILE, stdout = customNlFunctionsFile) 
    customNlFunctionsFile.close()
    print "Done."
    #dataPackBuild
    print "(+) Building lexix datapack... (no find and no chmod) - Grammar"
    if os.path.exists(DATAPACK_OUT_UDIR + '/data/Grammars/abnf/bin/' + GRAMMAR_NAME):
        shutil.rmtree(DATAPACK_OUT_UDIR + '/data/Grammars/abnf/bin/' + GRAMMAR_NAME)
    if os.path.exists(DATAPACK_OUT_UDIR + '/data/SOURCES'):
        shutil.rmtree(DATAPACK_OUT_UDIR + '/data/SOURCES')
    linkToWD = env['ENV']['LOCALROOT'] + '/sr/sra/src/grammars'
    os.chdir(linkToWD)
    call('java -jar ' + SIDE_LIBRARY_PATH + ' --verbyx -l ' + SIDE_BINARY_DIR + '/plugin.properties ' + '--deploy . ' + DATAPACK_OUT_DIR + ' > /dev/nul')
    if not os.path.exists(DATAPACK_OUT_UDIR + '/data/Grammars/src/grammars/en/faa'):
        os.makedirs(DATAPACK_OUT_UDIR + '/data/Grammars/src/grammars/en/faa')
    for file in GRAMMAR_SRC_FILES:
        shutil.copy(file, DATAPACK_OUT_UDIR + '/data/Grammars/src/grammars/en/faa')
    for file in glob.glob('*.xml'):
        shutil.copy(file, DATAPACK_OUT_UDIR + '/data/Grammars/src/grammars')
    shutil.copy('.project', DATAPACK_OUT_UDIR + '/data/Grammars/src/grammars')
    copytree('./project', DATAPACK_OUT_UDIR + '/data/Grammars/src/grammars/project')
    copytree('./.settings', DATAPACK_OUT_UDIR + '/data/Grammars/src/grammars/.settings')
    os.chdir(env['ENV']['LOCALROOT'])
    print "Done."

    #grammar.mk
    DATA_DIR = env['ENV']['LOCALROOT'] + '/LINK/data'
    GRAMMAR_SRC_DIR = SRROOT + '/sra/src/grammars'
    GRAMMAR_PROJECT_SRC_DIR = GRAMMAR_SRC_DIR + '/en/' + GRM_PROJECT
    GRAMMAR_OBJ_DIR = DATA_DIR + '/Grammars/bin'
    OUTPUT_DIR = GRAMMAR_OBJ_DIR + '/' + LANGUAGE + '/' + GRM_PROJECT
    AD_HOME = 'C:/Adacel/temp'
    PROJECT_DICTIONARY = DATA_DIR + '/Grammars/bin/dictionary'
    PROJECT_SRC_DICTIONARY = GRM_PROJECT + '.dictionary'
    PROJECT_OUT_DICTIONARY = OVERRIDE_OUT_DICTIONARY = PROJECT_DICTIONARY + '/' + LANGUAGE_PACK
    PROJECT_OUT_DIST_DICTIONARY = OVERRIDE_OUT_DIST_DICTIONARY = AD_HOME + '/nuance/dictionary/' + LANGUAGE_PACK
    PROJECT_SRC_OVR_DICTIONARY = OVR_DICTIONARY = 'override.dictionary'
    GRAMMAR_MASTER_FILE = GRM_PROJECT + '.grammar'
    COMPILE_FLAGS = LANGUAGE_PACK + ' -auto_pron -optimize_graph -dont_flatten -node_array_optimization_level FULL -override_dictionary ' + OVERRIDE_OUT_DIST_DICTIONARY + '/' + OVR_DICTIONARY + ' -merge_dictionary ' + PROJECT_OUT_DIST_DICTIONARY + '/' + PROJECT_SRC_DICTIONARY
    print "(+) Merging " + PROJECT_OUT_DICTIONARY + " and " + PROJECT_OUT_DIST_DICTIONARY
    if not os.path.exists(PROJECT_OUT_DICTIONARY):
        os.makedirs(PROJECT_OUT_DICTIONARY)
    shutil.copy(SRROOT + '/sra/src/grammars/' + LANGUAGE + '/' + GRM_PROJECT + '/' + PROJECT_SRC_DICTIONARY, PROJECT_OUT_DICTIONARY)
    if not os.path.exists(PROJECT_OUT_DIST_DICTIONARY):
        os.makedirs(PROJECT_OUT_DIST_DICTIONARY)
    shutil.copy(SRROOT + '/sra/src/grammars/' + LANGUAGE + '/' + GRM_PROJECT + '/' + PROJECT_SRC_DICTIONARY, PROJECT_OUT_DIST_DICTIONARY)
    print "Done."
    print "Copying " + OVERRIDE_OUT_DICTIONARY + " and " + OVERRIDE_OUT_DIST_DICTIONARY
    if not os.path.exists(OVERRIDE_OUT_DICTIONARY):
        os.makedirs(OVERRIDE_OUT_DICTIONARY)
    shutil.copy(SRROOT + '/sra/src/grammars/' + LANGUAGE + '/' + GRM_PROJECT + '/' + PROJECT_SRC_OVR_DICTIONARY, PROJECT_OUT_DICTIONARY)
    if not os.path.exists(OVERRIDE_OUT_DIST_DICTIONARY):
        os.makedirs(OVERRIDE_OUT_DIST_DICTIONARY)
    shutil.copy(SRROOT + '/sra/src/grammars/' + LANGUAGE + '/' + GRM_PROJECT + '/' + PROJECT_SRC_OVR_DICTIONARY, OVERRIDE_OUT_DIST_DICTIONARY)
    print "Done."
    NUANCE_COMPILER = env['ENV']['NUANCE_ROOT'] + '/bin/win32/nuance-compile '
    #Compiles Grammar.
    if not os.path.exists(OUTPUT_DIR + '/' + LANGUAGE_PACK):
        os.makedirs(OUTPUT_DIR + '/' + LANGUAGE_PACK)
    print "(+) Building " + LANGUAGE + "." + GRM_PROJECT + "." + LANGUAGE_PACK + " grammar..."
    os.chdir(env['ENV']['LOCALROOT'] + '/sr/sra/src/grammars/' + LANGUAGE + '/' + GRM_PROJECT)
    compilationCmd = NUANCE_COMPILER + GRAMMAR_MASTER_FILE + ' ' + COMPILE_FLAGS + ' -o ' + OUTPUT_DIR + '/' + LANGUAGE_PACK + ' -write_auto_pron_output ' + OUTPUT_DIR + '/' + LANGUAGE_PACK + '/.missing'
    call(compilationCmd)
    os.chdir(env['ENV']['LOCALROOT'])
    print "Done."

    #Grammar-database.mk
    print "(+) Creating dynamic grammar database (" + LANGUAGE + ")..."
    GRAMMAR_DIR = env['ENV']['LOCALROOT'] + '/LINK/data/Grammars/bin'
    GRAMMAR_DATABASE_DIR = GRAMMAR_DIR + '/' + LANGUAGE + '/dgdb-common'
    if os.path.exists(GRAMMAR_DATABASE_DIR):
        shutil.rmtree(GRAMMAR_DATABASE_DIR)
    if not os.path.exists(GRAMMAR_DIR + '/' + LANGUAGE):
        os.makedirs(GRAMMAR_DIR + '/' + LANGUAGE)
    NUANCE_DATABASE = env['ENV']['NUANCE_ROOT'] + '/bin/win32/nuance-database-admin '
    DB_FLAGS = '-dboperation create -dbname common -dbprovider fs -dbclass dgdb -dbroot ' + GRAMMAR_DIR + '/' + LANGUAGE
    call(NUANCE_DATABASE + DB_FLAGS)
    print "Done."
    return None

2 个答案:

答案 0 :(得分:1)

您可能既不需要ScannerParseDependsDepends。请查看我们的ToolsForFools Guide并查看如何为您的构建器提供Emitter

SCons需要知道的是,文件sideLibrary.jar是由系统中的另一个Builder(整个构建描述)创建的。如果您已经明确指定sideLibrary.jar作为创建构建器的目标,那么这应该是开箱即用的。 SCons然后知道sideLibrary.jar是两个,一个Builder的目标和另一个的源文件。因此,它可以正确安排单个构建步骤...

但是,如果您的sideLibrary.jar只是另一个构建命令的副产品:

env.YourBuilder('other.jar', Glob('*.java'))

,然后你需要为这种类型的构建定义一个特殊的发射器,这样SCons可以看到构建other.jar和创建sideLibrary.jar之间的连接。

我希望这会让事情更加清晰。如果您仍然难以让它发挥作用,请访问我们的UserMailing列表(scons-users@scons.org,另请参阅http://scons.org/lists.html),我们可以更详细地讨论您的问题,您可能会获得更多帮助参考我们文档中的指针。

答案 1 :(得分:0)

嗯,我不确定这个问题会对某人有所帮助,但我觉得至少回答我的问题很重要。

所以,对于每个以scons开头的人,总是使用“source =”作为函数参数。我的所有问题(-j4都不能正常工作)与我调用自定义构建器时的情况完全相关,我使用的就是“buildGrammar(src =”blabla“)”。这是错误的。必须是“buildGrammar(source =”blabla“)