SCons不会忽略依赖项

时间:2016-06-08 11:55:18

标签: dependencies scons ignore

我有以下文件系统结构

+-sources+-A
|          + source files 
|        +-B
|          + source files 
|        +-C
|          + source files 
|
sharedLib
     +-libA.so
     +-libB.so
     +-libC.so

libB.so依赖于libC.so. libA.so依赖于libB.so

默认情况下,如果sources / C目录下的文件发生更改,SCons将重建所有三个库。我只需要重建 libC.so 共享库,而不是触及另外两个。 我尝试添加environment.Ignore('sharedLib/libB.so', 'sharedLib/libC.so'),但没有帮助。请指教。

1 个答案:

答案 0 :(得分:0)

您需要的是Requires功能......

这似乎在一个最小的例子中工作得很好,我把它放在一起演示你的用例......

>> scons --version
SCons by Steven Knight et al.:
    script: v2.3.6.rel_2.3.5:3347:d31d5a4e74b6[MODIFIED], 2015/07/31 14:36:10, by bdbaddog on hpmicrodog
    engine: v2.3.6.rel_2.3.5:3347:d31d5a4e74b6[MODIFIED], 2015/07/31 14:36:10, by bdbaddog on hpmicrodog
    engine path: ['/usr/lib/scons/SCons']
Copyright (c) 2001 - 2015 The SCons Foundation

>> tree  
.
├── SConstruct
├── sharedLib
└── sources
    ├── A
    │   └── libA.cpp
    ├── B
    │   └── libB.cpp
    └── C
        └── libC.cpp

5 directories, 4 files

>> cat SConstruct 
import os
env = Environment()
libC = env.SharedLibrary('sharedLib/libC.so', 'sources/C/libC.cpp')
envAB = env.Clone()
envAB.Append(LINKFLAGS=['-lC'],
             LIBPATH=['sharedLib'])
libA = envAB.SharedLibrary('sharedLib/libA.so', 'sources/A/libA.cpp')
envAB.Requires(libA, libC)
libB = envAB.SharedLibrary('sharedLib/libB.so', 'sources/B/libB.cpp')
envAB.Requires(libB, libC)

>> cat sources/A/libA.cpp 
#include <iostream>
void A(void) {std::cout << "A" << std::endl;}

>> cat sources/B/libB.cpp
#include <iostream>
void B(void) {std::cout << "B" << std::endl;}

>> cat sources/C/libC.cpp
#include <iostream>
void C(void) {std::cout << "C" << std::endl;}

>> scons                 
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o sources/C/libC.os -c -fPIC sources/C/libC.cpp
g++ -o sharedLib/libC.so -shared sources/C/libC.os
g++ -o sources/A/libA.os -c -fPIC sources/A/libA.cpp
g++ -o sharedLib/libA.so -lC -shared sources/A/libA.os -LsharedLib
g++ -o sources/B/libB.os -c -fPIC sources/B/libB.cpp
g++ -o sharedLib/libB.so -lC -shared sources/B/libB.os -LsharedLib
scons: done building targets.

>> tree
.
├── SConstruct
├── sharedLib
│   ├── libA.so
│   ├── libB.so
│   └── libC.so
└── sources
    ├── A
    │   ├── libA.cpp
    │   └── libA.os
    ├── B
    │   ├── libB.cpp
    │   └── libB.os
    └── C
        ├── libC.cpp
        └── libC.os

5 directories, 10 files

>> echo "void E(void){}" >> sources/C/libC.cpp

>> cat sources/C/libC.cpp 
#include <iostream>
void C(void) {std::cout << "C" << std::endl;}
void E(void){}

>> scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o sources/C/libC.os -c -fPIC sources/C/libC.cpp
g++ -o sharedLib/libC.so -shared sources/C/libC.os
scons: done building targets.

>> tree
.
├── SConstruct
├── sharedLib
│   ├── libA.so
│   ├── libB.so
│   └── libC.so
└── sources
    ├── A
    │   ├── libA.cpp
    │   └── libA.os
    ├── B
    │   ├── libB.cpp
    │   └── libB.os
    └── C
        ├── libC.cpp
        └── libC.os

5 directories, 10 files