【问题标题】:SCons does not find header files when using variant_dirSCons 在使用 variant_dir 时找不到头文件
【发布时间】:2019-10-16 02:16:48
【问题描述】:

您好,我在使用相对路径和 variant_dir 中的更改时遇到问题 我有一个分层的 SCons 结构。从主 SConstruct 我调用子 SConcripts 代表层 我的项目:

mcal_build_dir              = os.path.join(env.subst('$OUTPUT_DIR'), 'objs', 'MCAL')
infra_build_dir             = os.path.join(env.subst('$OUTPUT_DIR'), 'objs', 'INFRA')

mcal_path             = os.path.join('../../Targets/TC275/MCAL/SConscript')
infra_path            = os.path.join('../../INFRA/SConscript')


mcal_objs = SConscript(mcal_path, exports='env env_base', variant_dir=mcal_build_dir, duplicate=0)
infra_objs = SConscript(infra_path, exports='env env_base', variant_dir=infra_build_dir, duplicate=0)

INFRA/Sconscript 内部

includes = [
  '../MCAL/api',
  ........
  ........
]
# SOURCE FILES
sources = [
    'src/ECU_StartupTask.c',
  ....
]
for include in includes:
    own_env.Append(CPPPATH=[Dir(include).abspath])

编译时会找到 MCAL/api 中的头文件:

gcc ....... -fno-peephole2 -D_GNU_C_TRICORE_=1 -Ioutput\objs\MCAL\api -IC:\Repositories\fcm3_ssb_sk\Targets\TC275\MCAL\api -Ioutput\objs\ASW\swc_PyroControl\code\api .....

现在我需要为 mcal 提供 2 种不同的构建风格,所以我尝试在同一代码中执行 2 次编译 不同的构建目录

mcal_build_dir              = os.path.join(env.subst('$OUTPUT_DIR'), 'objs', 'MCAL/hw_3x')
mcal_build_dir2                 = os.path.join(env.subst('$OUTPUT_DIR'), 'objs', 'MCAL/hw_4x')

The point is that only changing this the INFRA SConscript does not compile, the headers MCAL/api are not found. 

gcc ....... -fno-peephole2 -D_GNU_C_TRICORE_=1 -Ioutput\objs\MCAL\api -Ioutput\objs\ASW\swc_PyroControl\code\api .....

"""注意编译行"""中没有添加MCAL\api的绝对路径

所以似乎由于某种原因找不到 -IC:\Repositories\fcm3_ssb_sk\Targets\TC275\MCAL\api 的绝对路径。 我不明白 INFRA/SConstruct 与 mcal_build_dir 更改的关系。不应该是 独立的?我的意思是当我构建 INFRA 层时,我使用包含作为 INFRA/SConscript 的相对路径。 我认为当您更改 build_dir 时,SConscript 目录将 复制 到 build_dir 并在那里编译,但是 INFRA 层本身的头文件呢?他们被复制了吗? INFRA/SConscript 如何知道 第一次而不是第二次指向 MCAL/api 的绝对路径。

【问题讨论】:

    标签: scons


    【解决方案1】:

    这并没有解决您的主要问题,但是您有很多不正确的 SCons 用法,我在这里发表评论并展示更好的方法。

    这里有一些令人困惑的代码:参见 cmets

    # No need to use env.subst or os.path.join here.
    mcal_build_dir              = os.path.join(env.subst('$OUTPUT_DIR'), 'objs', 'MCAL')
    infra_build_dir             = os.path.join(env.subst('$OUTPUT_DIR'), 'objs', 'INFRA')
    # should be 
    mcal_build_dir              = '$OUTPUT_DIR/objs/MCAL'
    infra_build_dir             = '$OUTPUT_DIR/objs/INFRA'
    
    # These os.path.join's do nothing
    mcal_path             = os.path.join('../../Targets/TC275/MCAL/SConscript')
    infra_path            = os.path.join('../../INFRA/SConscript')
    # So change to this
    mcal_path             = '../../Targets/TC275/MCAL/SConscript'
    infra_path            = '../../INFRA/SConscript'
    
    # don't see any issues with this so far..
    mcal_objs = SConscript(mcal_path, exports='env env_base', variant_dir=mcal_build_dir, duplicate=0)
    infra_objs = SConscript(infra_path, exports='env env_base', variant_dir=infra_build_dir, duplicate=0)
    

    来自您的 INFRA/Sconscript

    includes = [
      '../MCAL/api',
      ........
      ........
    ]
    # SOURCE FILES
    sources = [
        'src/ECU_StartupTask.c',
      ....
    ]
    
    # This does nothing (adding via Dir().abspath does not cause SCons to use absolute paths.
    for include in includes:
        own_env.Append(CPPPATH=[Dir(include).abspath])
    
    # So do this instead
    own_env.Append(CPPPATH=includes)
    

    下一个有问题的代码示例:

    # The subst and os.path.join once again isn't needed.
    mcal_build_dir              = os.path.join(env.subst('$OUTPUT_DIR'), 'objs', 'MCAL/hw_3x')
    mcal_build_dir2             = os.path.join(env.subst('$OUTPUT_DIR'), 'objs', 'MCAL/hw_4x')
    # Do this instead (no need to pre-substitute and SCons will convert the /'s to \'s if necessary
    mcal_build_dir              = '$OUTPUT_DIR/objs/MCAL/hw_3x'
    mcal_build_dir2             = '$OUTPUT_DIR/objs/MCAL/hw_4x'
    

    所有文件/目录引用都相对于 SConstruct 或 SConscript 所在的目录(和/或 variant_dir)

    我注意到您在很多地方都使用 ../.. 作为起始路径。为什么不在那里找到您的 SConstruct?这将形成一个更典型的布局/SConstruct 位置。

    【讨论】:

    • 感谢 cmets,实际上这是从另一家公司继承的大型项目,构建了初始骨架。我正在尝试将此适应 multitarget builder project_
    • @AlbertoRiera 来到 scons 讨论频道寻求帮助/建议。您还阅读了用户手册。关于变体目录的大节。 discord.gg/bXVpWAy
    猜你喜欢
    • 2014-08-09
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 2014-05-14
    • 1970-01-01
    相关资源
    最近更新 更多