添加scons构建测试

This commit is contained in:
HEYAHONG 2024-02-03 17:04:51 +08:00
parent 8de91c04eb
commit 2d758e781a
No known key found for this signature in database
GPG Key ID: BD5679034F83A8A9
9 changed files with 229 additions and 0 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
*.o
build
.scon*
__pycache__

23
hbox/cpp/SConscript Normal file
View File

@ -0,0 +1,23 @@
from building import *
import os
import sys
if Env["Enable_HBox_CPP"] is None:
group = []
Return('group')
cwd = GetCurrentDir()
src = Glob('*.c')
src += Glob('*.cpp')
CPPPATH = [
cwd
]
group = DefineGroup('HBox_CPP', src, depend = [''], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
group = group + SConscript(os.path.join(item, 'SConscript'))
Return('group')

24
hcppbox/SConscript Normal file
View File

@ -0,0 +1,24 @@
from building import *
import os
import sys
if Env["Enable_HCPPBox"] is None:
group = []
Return('group')
cwd = GetCurrentDir()
src = Glob('*.c')
src += Glob('*.cpp')
CPPPATH = [
cwd,
]
group = DefineGroup('HCPPBox', src, depend = [''], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
group = group + SConscript(os.path.join(item, 'SConscript'))
Return('group')

23
test/HBoxTest/SConscript Normal file
View File

@ -0,0 +1,23 @@
from building import *
import os
import sys
cwd = GetCurrentDir()
src = Glob('*.c')
src += Glob('*.cpp')
CPPPATH = [cwd]
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
group = group + SConscript(os.path.join(item, 'SConscript'))
if os.path.isfile(os.path.join(cwd+"/../../", 'SConscript')):
group = group + SConscript(os.path.join(cwd+"/../../", 'SConscript'))
Return('group')

View File

@ -0,0 +1,23 @@
from building import *
import os
import sys
cwd = GetCurrentDir()
src = Glob('*.c')
src += Glob('*.cpp')
CPPPATH = [cwd]
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
group = group + SConscript(os.path.join(item, 'SConscript'))
if os.path.isfile(os.path.join(cwd+"/../../", 'SConscript')):
group = group + SConscript(os.path.join(cwd+"/../../", 'SConscript'))
Return('group')

23
test/HRCTest/SConscript Normal file
View File

@ -0,0 +1,23 @@
from building import *
import os
import sys
cwd = GetCurrentDir()
src = Glob('*.c')
src += Glob('*.cpp')
CPPPATH = [cwd]
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
group = group + SConscript(os.path.join(item, 'SConscript'))
if os.path.isfile(os.path.join(cwd+"/../../", 'SConscript')):
group = group + SConscript(os.path.join(cwd+"/../../", 'SConscript'))
Return('group')

View File

@ -22,3 +22,9 @@ cmake --build .
#编译完成后即可在子目录中找到每个测试程序的可执行文件
```
# scons
在当前目录执行`scons`可通过[scons](https://scons.org)编译。
注意:scons构建并非主要构建一般是为了测试[RT-Thread](https://www.rt-thread.org/)的scons构建。

24
test/SConstruct Normal file
View File

@ -0,0 +1,24 @@
import os
import sys
#采用默认环境由于未设置相关C/C++参数,均采用编译器默认参数,因此请使用最新版编译器
env = Environment()
#添加标志
env["Enable_HBox_CPP"]=True
env["Enable_HCPPBox"]=True
cwd = str(Dir('#'))
objs = []
from building import *
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
target_env=env.Clone()
SetEnv(target_env)
target_env["OBJPREFIX"]="build/"+d+"/"
target_env["SHOBJPREFIX"]="build/"+d+"/"
objs = SConscript(os.path.join(path, 'SConscript'))
target_env.Program(target="build/"+d,source=objs)

80
test/building.py Normal file
View File

@ -0,0 +1,80 @@
#模拟环境
Env = None
from SCons.Script import *
def SetEnv(target_env):
global Env
Env = target_env
def GetCurrentDir():
conscript = File('SConscript')
fn = conscript.rfile()
name = fn.name
path = os.path.dirname(fn.abspath)
return path
def _PretreatListParameters(target_list):
while '' in target_list: # remove null strings
target_list.remove('')
while ' ' in target_list: # remove ' '
target_list.remove(' ')
if(len(target_list) == 0):
return False # ignore this list, don't add this list to the parameter
return True # permit to add this list to the parameter
def DefineGroup(name, src, depend, **parameters):
global Env
group = parameters
group['name'] = name
if type(src) == type([]):
# remove duplicate elements from list
src = list(set(src))
group['src'] = File(src)
else:
group['src'] = src
if 'CFLAGS' in group:
target = group['CFLAGS']
if len(target) > 0:
Env.AppendUnique(CFLAGS = target)
if 'CCFLAGS' in group:
target = group['CCFLAGS']
if len(target) > 0:
Env.AppendUnique(CCFLAGS = target)
if 'CXXFLAGS' in group:
target = group['CXXFLAGS']
if len(target) > 0:
Env.AppendUnique(CXXFLAGS = target)
if 'CPPPATH' in group:
target = group['CPPPATH']
if _PretreatListParameters(target) == True:
paths = []
for item in target:
paths.append(os.path.abspath(item))
target = paths
Env.AppendUnique(CPPPATH = target)
if 'CPPDEFINES' in group:
target = group['CPPDEFINES']
if _PretreatListParameters(target) == True:
Env.AppendUnique(CPPDEFINES = target)
if 'LIBS' in group:
target = group['LIBS']
if _PretreatListParameters(target) == True:
Env.AppendUnique(LIBS = target)
if 'LIBPATH' in group:
target = group['LIBPATH']
if _PretreatListParameters(target) == True:
Env.AppendUnique(LIBPATH = target)
# check whether to build group library
if 'LIBRARY' in group:
objs = Env.Library(name, group['src'])
else:
# only add source
objs = group['src']
return objs