我什么时候应该使用 scons 扫描仪与 parseDepends 和 Depends

When should I use scons scanner vs parseDepends and Depends

对于这么长的问题,我深表歉意。

下面是我想用scons做的

目前的工作:

  • 我们 95% 的 c++ 代码都是用 scons -j4 完美构建的。依赖关系树已正确创建
  • 我们的自定义 python 生成器使用 ant
  • 从 java 组件生成 .jar

什么不起作用:

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

下面是生成sideLibrary.jar的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: A list of Node objects representing the sources to be used by this builder function to build the targets.

这让我想到 Scanner, ParseDepens and Depends(我已经阅读了关于它们的 scons 文档)。

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

有人可以点我的灯笼吗?

谢谢

编辑 (添加依赖树)

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:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcp100d.dll", "C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcr100d.dll", "C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100d.dll", "C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100ud.dll", "C:\svnrdParty\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:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcp100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcr100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100ud.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\RemoteDebugger\rdbgsetup_x86.exe
  | |   +-LINK\bin\win32\mfc100ud.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcp100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcr100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100ud.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\RemoteDebugger\rdbgsetup_x86.exe
  | |   +-LINK\bin\win32\msvcp100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcp100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcr100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100ud.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\RemoteDebugger\rdbgsetup_x86.exe
  | |   +-LINK\bin\win32\msvcr100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcp100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcr100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100ud.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\RemoteDebugger\rdbgsetup_x86.exe
  | |   +-LINK\bin\win32\rdbgsetup_x86.exe
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcp100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugCRT\msvcr100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100d.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC100.DebugMFC\mfc100ud.dll
  | |   | +-C:\svnrdParty\devTool\Microsoft_Visual_Studio_10.0\RemoteDebugger\rdbgsetup_x86.exe
  | |   +-LINK\bin\win32\sideLibrary.jar
  | |     +-sr\side\build.xml
  | |     +-C:\svnrdParty\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:\svnrdParty\devTool\apache-ant-1.9.2\bin\ant.BAT
    | +-sr\side\dist
    | | +-sr\side\build.xml
    | | +-C:\svnrdParty\devTool\apache-ant-1.9.2\bin\ant.BAT
    | +-sr\side\doc
    | | +-sr\side\doc\sdtk
    | |   +-sr\side\build.xml
    | |   +-C:\svnrdParty\devTool\apache-ant-1.9.2\bin\ant.BAT
    | +-sr\side\obj
    | | +-sr\side\build.xml
    | | +-C:\svnrdParty\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 添加了构建语法

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

您可能不需要 ScannerParseDependsDepends。请查看我们的 ToolsForFools Guide 并了解如何为您的生成器提供 Emitter

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

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

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

,那么你需要为这种构建定义一个特殊的Emitter,这样SCons就可以同时看到构建other.jar和创建sideLibrary.jar之间的联系。

我希望这能让你更清楚。如果您仍然难以让它正常工作,请访问我们的 UserMailing 列表(scons-users@scons.org,另请参阅 http://scons.org/lists.html),我们可以在其中更详细地讨论您的问题,您可能会得到更多帮助我们文档的参考指针。

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

因此,对于所有开始使用 scons 的人,请始终使用 "source=" 作为函数参数。我所有的问题(-j4 不工作),完全与我调用我的自定义构建器时的事实有关 "buildGrammar(src="blabla")" .这是错误的。必须是 "buildGrammar(source="blabla")