[scons在使用variant_dir时找不到头文件

问题描述 投票:0回答:1

您好,我在使用相对路径和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 /应征者内部

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目录copied到build_dir并在那里编译,但是INFRA层本身之外的头文件呢?他们被复制了吗? INFRA / SConscript如何知道第一次而非第二次访问MCAL / api的绝对路径。

scons
1个回答
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 /应征者

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

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.