使用variant_dir时,SCons找不到头文件

时间:2019-10-15 09:54:28

标签: scons

您好,我在使用相对路径和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层时,我正在使用include作为INFRA / SConscript的相对路径。 我认为,当您更改build_dir时,会将SConscript目录复制到build_dir并在那里编译,但是 INFRA层本身之外的头文件呢?他们被复制了吗? INFRA / SConscript如何知道 第一次而不是第二次访问MCAL / api的绝对路径。

1 个答案:

答案 0 :(得分:1)

这不能解决您的主要问题,但是您对SCons的使用方式有很多不正确,我正在对此进行评论并在此处显示一种更好的方法。

在此处哇一些令人困惑的代码:查看评论

# 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的位置更为典型。