Scons - 如何停止清洁依赖 targets/files 清洁最终目标?

Scons - How to stop cleaning dependent targets/files on cleaning final target?

我有两个目标A和B。 B 依赖于 A,因此如果我们构建 B,也会构建 A。 现在如果 B 被清理了,A 也被清理了。 A 是 .obj 文件和生成的库的集合。 请求:清洗B时,目标A没有touched/removed 这是我的代码:

    {env = Environment()
     src1 = ['tridip.c', 'tridip1.c', 'tridip2.c']
     obj1 = [ env.StaticObject(sf) for sf in src1 ]
     lib = env.Library('tridip', obj1)
     Alias('library', lib)
     src2 = ['tridip3.c']
     obj2 = [ env.StaticObject(sf) for sf in src2 ]
     exe = Program(obj2, LIBS=lib, LIBPATH='.')
     Alias('exe', exe)
}

目标 A 是 tridip.lib tridip.obj tridip1.obj tridip2.obj 目标 B 是:tridip3.exe /LIBPATH:。 tridip.libtridip3.obj

请求:如何在清理目标B上停止清理目标A。

您需要 NoClean 函数。这是更新 SConstruct 的方法。

env = Environment()
src1 = ['tridip.c', 'tridip1.c', 'tridip2.c']
obj1 = [ env.StaticObject(sf) for sf in src1 ]
lib = env.Library('tridip', obj1)
if 'library' not in COMMAND_LINE_TARGETS:
    env.NoClean([obj1, lib])
Alias('library', lib)
src2 = ['tridip3.c']
obj2 = [ env.StaticObject(sf) for sf in src2 ]
exe = Program(obj2, LIBS=lib, LIBPATH='.')
Alias('exe', exe)

当 运行 产生以下...

>> scons --version
SCons by Steven Knight et al.:
    script: v2.3.4, 2014/09/27 12:51:43, by garyo on lubuntu
    engine: v2.3.4, 2014/09/27 12:51:43, by garyo on lubuntu
    engine path: ['/usr/lib/scons/SCons']
Copyright (c) 2001 - 2014 The SCons Foundation

>> tree
.
├── SConstruct
├── tridip1.c
├── tridip1.h
├── tridip2.c
├── tridip2.h
├── tridip3.c
├── tridip.c
└── tridip.h

0 directories, 8 files

>> scons library
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o tridip.o -c tridip.c
gcc -o tridip1.o -c tridip1.c
gcc -o tridip2.o -c tridip2.c
ar rc libtridip.a tridip.o tridip1.o tridip2.o
ranlib libtridip.a
scons: done building targets.

>> tree
.
├── libtridip.a
├── SConstruct
├── tridip1.c
├── tridip1.h
├── tridip1.o
├── tridip2.c
├── tridip2.h
├── tridip2.o
├── tridip3.c
├── tridip.c
├── tridip.h
└── tridip.o

0 directories, 12 files

>> scons library -c
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
Removed tridip.o
Removed tridip1.o
Removed tridip2.o
Removed libtridip.a
scons: done cleaning targets.

>> tree
.
├── SConstruct
├── tridip1.c
├── tridip1.h
├── tridip2.c
├── tridip2.h
├── tridip3.c
├── tridip.c
└── tridip.h

0 directories, 8 files

>> scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o tridip.o -c tridip.c
gcc -o tridip1.o -c tridip1.c
gcc -o tridip2.o -c tridip2.c
ar rc libtridip.a tridip.o tridip1.o tridip2.o
ranlib libtridip.a
gcc -o tridip3.o -c tridip3.c
gcc -o tridip3 tridip3.o -L. libtridip.a
scons: done building targets.

>> scons -c
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
Removed tridip3.o
Removed tridip3
scons: done cleaning targets.

>> tree
.
├── libtridip.a
├── SConstruct
├── tridip1.c
├── tridip1.h
├── tridip1.o
├── tridip2.c
├── tridip2.h
├── tridip2.o
├── tridip3.c
├── tridip.c
├── tridip.h
└── tridip.o

0 directories, 12 files