summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZiqiang Zhang <[email protected]>2026-12-01 10:17:58 +0800
committerGitHub <[email protected]>2026-12-01 10:17:58 +0800
commit284b510dda03949cfd6236e09eea58846c3ec7e7 (patch)
tree837b3e560370e5530cc91f14cf80fd6ca3545232
parent332ac026959dab0c489ab7d8ac305f78f5559398 (diff)
[tools] apply local compilation flags to group libraries (#12070)
* [tools] apply local compilation flags to group libraries Signed-off-by: Daiyuanranfeng <[email protected]> * tools: avoid empty entries in group-local SCons flags * Defer local library objects until global flags are collected --------- Signed-off-by: Daiyuanranfeng <[email protected]>
-rw-r--r--tools/building.py61
1 files changed, 40 insertions, 21 deletions
diff --git a/tools/building.py b/tools/building.py
index 7abedd4f27..72f318986c 100644
--- a/tools/building.py
+++ b/tools/building.py
@@ -37,6 +37,7 @@ import rtconfig
import platform
import logging
from SCons.Script import *
+from SCons.Util import adjustixes
from utils import _make_path_relative
from mkdist import do_copy_file
from options import AddOptions
@@ -682,6 +683,26 @@ def _PretreatListParameters(target_list):
return True # permit to add this list to the parameter
+_LOCAL_GROUP_FLAG_KEYS = ('CFLAGS', 'CCFLAGS', 'CXXFLAGS', 'ASFLAGS', 'CPPPATH', 'CPPDEFINES')
+
+
+def _local_group_objects(group, objects):
+ if not any('LOCAL_' + key in group for key in _LOCAL_GROUP_FLAG_KEYS):
+ return False
+
+ flags = {}
+ for key in _LOCAL_GROUP_FLAG_KEYS:
+ local_key = 'LOCAL_' + key
+ if key in ('CPPPATH', 'CPPDEFINES'):
+ flags[key] = list(Env.get(key, [])) + group.get(local_key, [])
+ else:
+ flags[key] = Env.get(key, '') + group.get(local_key, '')
+
+ for source in group['src']:
+ objects.append(Env.Object(source, **flags))
+ return True
+
+
def DefineGroup(name, src, depend, **parameters):
global Env
if not GetDepend(depend):
@@ -776,7 +797,20 @@ def DefineGroup(name, src, depend, **parameters):
# check whether to build group library
if 'LIBRARY' in group:
- objs = Env.Library(name, group['src'])
+ if any('LOCAL_' + key in group for key in _LOCAL_GROUP_FLAG_KEYS):
+ # Keep the target in this SConscript directory. Build it after all
+ # SConscript files have added their global flags to the environment.
+ library = Env.File(adjustixes(name, Env.subst('$LIBPREFIX'), Env.subst('$LIBSUFFIX')))
+
+ def build_library():
+ sources = []
+ _local_group_objects(group, sources)
+ Env.Library(library, sources)
+
+ RegisterPreBuildingAction(build_library)
+ objs = [library]
+ else:
+ objs = Env.Library(name, group['src'])
else:
# only add source
objs = group['src']
@@ -853,24 +887,6 @@ def DoBuilding(target, objects):
lst.append(item)
return lst
- # handle local group
- def local_group(group, objects):
- if 'LOCAL_CFLAGS' in group or 'LOCAL_CXXFLAGS' in group or 'LOCAL_CCFLAGS' in group or 'LOCAL_CPPPATH' in group or 'LOCAL_CPPDEFINES' in group or 'LOCAL_ASFLAGS' in group:
- CFLAGS = Env.get('CFLAGS', '') + group.get('LOCAL_CFLAGS', '')
- CCFLAGS = Env.get('CCFLAGS', '') + group.get('LOCAL_CCFLAGS', '')
- CXXFLAGS = Env.get('CXXFLAGS', '') + group.get('LOCAL_CXXFLAGS', '')
- CPPPATH = list(Env.get('CPPPATH', [''])) + group.get('LOCAL_CPPPATH', [''])
- CPPDEFINES = list(Env.get('CPPDEFINES', [''])) + group.get('LOCAL_CPPDEFINES', [''])
- ASFLAGS = Env.get('ASFLAGS', '') + group.get('LOCAL_ASFLAGS', '')
-
- for source in group['src']:
- objects.append(Env.Object(source, CFLAGS = CFLAGS, CCFLAGS = CCFLAGS, CXXFLAGS = CXXFLAGS, ASFLAGS = ASFLAGS,
- CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES))
-
- return True
-
- return False
-
PreBuilding()
objects = one_list(objects)
@@ -883,7 +899,7 @@ def DoBuilding(target, objects):
for Group in Projects:
if Group['name'] == lib_name:
lib_name = GroupLibName(Group['name'], Env)
- if not local_group(Group, objects):
+ if not _local_group_objects(Group, objects):
objects = Env.Object(Group['src'])
program = Env.Library(lib_name, objects)
@@ -900,6 +916,8 @@ def DoBuilding(target, objects):
# remove source files with local flags setting
for group in Projects:
+ if 'LIBRARY' in group:
+ continue
if 'LOCAL_CFLAGS' in group or 'LOCAL_CXXFLAGS' in group or 'LOCAL_CCFLAGS' in group or 'LOCAL_CPPPATH' in group or 'LOCAL_CPPDEFINES' in group:
for source in group['src']:
for obj in objects:
@@ -910,7 +928,8 @@ def DoBuilding(target, objects):
objects_in_group = []
for group in Projects:
- local_group(group, objects_in_group)
+ if 'LIBRARY' not in group:
+ _local_group_objects(group, objects_in_group)
# sort separately, because the data type of
# the members of the two lists are different