Skip to content

Commit b971e94

Browse files
Improve tooling compatibility for alternative configurations []
1 parent 7a0533d commit b971e94

3 files changed

Lines changed: 89 additions & 2 deletions

File tree

‎dev_tools/pylibs/edgtest/exec/__init__.py‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from edgtest import runtest
3232
from edgtest.filter import (
3333
BuildConstants,
34+
GNU_MODE,
35+
MICROSOFT_MODE,
3436
Normalizer as OutputNormalizer
3537
)
3638

@@ -46,6 +48,19 @@
4648
r'(?:^|(?<=\s))--target(?:=|\s+)(\S+)'
4749
)
4850

51+
# Match, per target mode, the options that are only accepted by front ends
52+
# built to support that mode (including abbreviations and --no_ forms) in
53+
# joined option strings. The Microsoft options are --microsoft...; the GNU
54+
# options are --gnu..., --g++, --gcc..., and --clang....
55+
_MODE_OPTION_REGEXES = {
56+
MICROSOFT_MODE: re.compile(
57+
r'(^|(?<=\s))--(no_)?microsoft\w*'
58+
),
59+
GNU_MODE: re.compile(
60+
r'(^|(?<=\s))--(no_)?(gnu\w*|g\+\+|gcc\w*|clang\w*)'
61+
)
62+
}
63+
4964
def get_output_filename(env: Dict[str, str],
5065
case_number: int,
5166
command_number: int) -> str:
@@ -993,6 +1008,18 @@ def _case_requests_unsupported_target(
9931008
return True
9941009
return False
9951010

1011+
def _case_requests_unsupported_mode(
1012+
cmd_opts: List[str],
1013+
cmd_case_opts: List[str],
1014+
target_modes: FrozenSet[str]
1015+
) -> bool:
1016+
'''True if any base/case option needs a target mode the build lacks.'''
1017+
options_str = ' '.join([*cmd_opts, *cmd_case_opts])
1018+
for mode, option_regex in _MODE_OPTION_REGEXES.items():
1019+
if mode not in target_modes and option_regex.search(options_str):
1020+
return True
1021+
return False
1022+
9961023
async def run_test(test_path: Path, *, top_dir: Path, output_dir: Path,
9971024
env: Dict[str, str], build_constants: BuildConstants,
9981025
faster_mode: bool, update_recording: bool, debug_mode: bool,
@@ -1120,6 +1147,21 @@ async def run_test(test_path: Path, *, top_dir: Path, output_dir: Path,
11201147
))
11211148
continue
11221149

1150+
if _case_requests_unsupported_mode(
1151+
cmd_opts,
1152+
cmd_case_opts,
1153+
build_constants.target_modes
1154+
):
1155+
# Case requests a Microsoft or GNU mode that this front end was not
1156+
# built to support.
1157+
test_results.append(make_requirements_not_met_status(
1158+
test_path,
1159+
mode,
1160+
test_descript.remark,
1161+
_case_options_tag(case_number, cmd_case_opts)
1162+
))
1163+
continue
1164+
11231165
case_artifact_dir = tmp_dir / str(case_number)
11241166
case_artifact_dir.mkdir()
11251167

‎dev_tools/pylibs/edgtest/filter/__init__.py‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,33 @@
2424
re.MULTILINE
2525
)
2626

27+
def _check_config_enables_macro(config_dump: str, macro: str) -> bool:
28+
'''True if the dumped configuration defines macro as enabled (1 or TRUE).
29+
30+
A macro that the dump reports as "not defined" is treated as disabled.
31+
'''
32+
return re.search(
33+
rf'#define[ \t]+{re.escape(macro)}[ \t]+(1|TRUE)\s',
34+
config_dump
35+
) is not None
36+
37+
# Target modes whose command-line options are only accepted by front ends
38+
# built with the corresponding configuration macro.
39+
MICROSOFT_MODE = 'microsoft'
40+
GNU_MODE = 'gnu'
41+
42+
_TARGET_MODE_CONFIG_MACROS = {
43+
MICROSOFT_MODE: 'MICROSOFT_EXTENSIONS_ALLOWED',
44+
GNU_MODE: 'GNU_EXTENSIONS_ALLOWED'
45+
}
46+
47+
def _parse_target_modes(config_dump: str) -> FrozenSet[str]:
48+
'''Collect the target modes (e.g., MICROSOFT_MODE) this build supports.'''
49+
return frozenset(
50+
mode for mode, macro in _TARGET_MODE_CONFIG_MACROS.items()
51+
if _check_config_enables_macro(config_dump, macro)
52+
)
53+
2754
def _parse_target_configurations(config_dump: str) -> FrozenSet[str]:
2855
'''Collect --target names supported by this front-end build.'''
2956
targets: Set[str] = set(
@@ -37,11 +64,13 @@ def _parse_target_configurations(config_dump: str) -> FrozenSet[str]:
3764
class BuildConstants:
3865
def __init__(self, version: str, build_timestamp: str,
3966
config_dump: str,
40-
target_configurations: FrozenSet[str]) -> None:
67+
target_configurations: FrozenSet[str],
68+
target_modes: FrozenSet[str]) -> None:
4169
self.version = version
4270
self.build_timestamp = build_timestamp
4371
self.config_dump = config_dump
4472
self.target_configurations = target_configurations
73+
self.target_modes = target_modes
4574

4675
async def load_build_constants(compiler_bin: Path) -> BuildConstants:
4776
config_dump_proc = await asyncio.create_subprocess_exec(
@@ -71,7 +100,8 @@ async def load_build_constants(compiler_bin: Path) -> BuildConstants:
71100
version_number,
72101
build_date,
73102
config_dump,
74-
_parse_target_configurations(config_dump)
103+
_parse_target_configurations(config_dump),
104+
_parse_target_modes(config_dump)
75105
)
76106

77107
_REGEX_REPLACEMENTS = {

‎util/eccp.sh‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ std_incl=1
404404
#
405405
instantiation_mode_specified=0
406406
#
407+
# Flag indicating that the --building_runtime option was specified (i.e., the
408+
# runtime library is being built).
409+
#
410+
building_runtime=0
411+
#
407412
# Remove #line directives from the generated C
408413
#
409414
strip_line_dirs=0
@@ -1934,6 +1939,9 @@ process_option()
19341939
--no_auto_instantiation)
19351940
automatic_instantiation=0
19361941
;;
1942+
--building_runtime)
1943+
building_runtime=1
1944+
;;
19371945
-m | --c | --c89 | --c99 | --no_c99 | --c11 | --c18 | --c17 | --c23 | \
19381946
--ms_c11 | --ms_c17 | --ms_c23 | -K | --old_c | --svr4 | --no_svr4 | \
19391947
--gcc | --no_gcc | --upc | --no_upc)
@@ -2541,6 +2549,13 @@ if [ $c_mode -eq 1 ] ; then
25412549
automatic_instantiation=0
25422550
fi
25432551

2552+
# The runtime library is built without automatic instantiation. (Front ends
2553+
# configured without AUTOMATIC_TEMPLATE_INSTANTIATION do not accept the
2554+
# options the driver would otherwise pass to support it, e.g., --ii_file.)
2555+
if [ $building_runtime -eq 1 ] ; then
2556+
automatic_instantiation=0
2557+
fi
2558+
25442559
# Put the command name on the beginning of the instantiation command line.
25452560
# This is done here because a different name can be supplied on the
25462561
# command line. This is useful when the compile command is a script that

0 commit comments

Comments
 (0)