gpt4 book ai didi

dependencies - SCons 依赖于编译时生成的文件

转载 作者:行者123 更新时间:2023-12-02 21:51:48 25 4
gpt4 key购买 nike

我正在尝试设置 SCons 以遵循构建过程中自动生成的文件的依赖关系,并在多线程构建中正常工作。

我正在构建的项目是一个 CIM 提供程序,由定义数据结构的 MOF 文件、来自 MOF 文件的自动生成的源文件和头文件以及引用自动生成的文件的手写源文件和头文件组成。为了使构建成功,自动生成步骤必须在编译任何手写文件之前运行完成,否则手写文件所依赖的 header 将不存在并且会失败。自动生成步骤创建的 .cpp 文件还必须添加到源列表中并在最终构建中进行编译。

运行单线程构建时,一切正常,因为自动生成步骤始终在编译步骤之前完成,因此生成的 header 已就位。但是,当以多线程方式运行构建时,它会尝试在自动生成步骤完成之前编译手写文件,并且构建失败。我已指定显式依赖项,但 SCons 未遵循它。

这是我的 SConscript 文件的相关部分,我从 cim_targets[] 中删除了各个文件名,因为该列表非常长,但总而言之,cim_targets[] 是自动生成步骤的目标输出文件的列表,provider_sources[]是自动生成步骤完成后返回的源列表,sources[] 是手写源文件的列表,GenProvider() 是外部定义的命令生成器,用于执行自动生成步骤,SharedLibrary() 是外部定义的生成器,执行以下操作听起来像是使用带有一些扩展的 SCons 库构建器

# Define directory paths for the CIM schema
cim_dir = 'cim-schema-2.26.0'

var_smis_dir = Dir('.').abspath # src/lib/XXX in variant

cim_sources = [
Glob(os.path.join(cim_dir, '*qualifiers*.mof')),
Glob(os.path.join(cim_dir, 'Core') + '/CIM_*.mof'),
Glob(os.path.join(cim_dir, 'Device') + '/CIM_*.mof'),
Glob(os.path.join(cim_dir, 'Event') + '/CIM_*.mof'),
Glob(os.path.join(cim_dir, 'XXXXXX') + '/XXX_*.mof'),
Glob(os.path.join(cim_dir, 'Interop') + '/CIM_*.mof'),
Glob(os.path.join(cim_dir, 'Physical') + '/CIM_*.mof'),
Glob(os.path.join(cim_dir, 'System') + '/CIM_*.mof'),
]

cim_sources_flat = []
for cim in cim_sources:
for src in cim:
cim_sources_flat.append(src)

cim_targets = [
......
]

sources = [
'driver.cpp',
'device.cpp',
'cim_static_data.cpp',
'module.cpp',
'diag_log.cpp',
'profile_element.cpp',
]

staticlibs = [
......
]


dynamiclibs = [
.....
]

var_cim_sources = this_env.Install(var_smis_dir, cim_sources_flat)

cim_mof = 'cimv226.mof'

cim_linux_mof = os.path.join(cim_dir, 'cimv226-gen-flat.mof')

var_cim_sources.extend(this_env.Command(cim_mof, cim_linux_mof, Copy('$TARGET', '$SOURCE')))

# first generate the provider infrastructure using cimple
provider_sources = this_env.GenProvider(cim_targets, var_cim_sources, name, var_smis_dir)

# make sure these files don't build until AFTER the provider files have been created
this_env.Depends(sources, provider_sources)

sources_full = provider_sources + sources

# now we can compile the provider
this_env.SharedLibrary(libname, source=sources_full, staticlibs=staticlibs, dynamiclibs=dynamiclibs, installpath=install_dir)

我尝试设置显式依赖关系,以便在创建所有生成的源代码 (this_env.Depends(sources,provider_sources)) 之前,手写源代码不会编译,但是在运行多线程时,SCons 会忽略此依赖关系并尝试编译手写源代码自动生成步骤完成之前的文件。

最佳答案

您是否尝试过使用此处定义的 SideEffect() 函数:

SCons Wiki: SideEffect

我不确定它是否是完全根据您的需要创建的,但可能会有所帮助。

关于dependencies - SCons 依赖于编译时生成的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10092931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com