Skip to content

Commit 36e192e

Browse files
committed
WIP
1 parent 9cbb758 commit 36e192e

3 files changed

Lines changed: 205 additions & 11 deletions

File tree

test/CompileStubsSummary.cmake

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# CMake script to compile stubs individually and provide a summary
2+
# Usage: cmake -P CompileStubsSummary.cmake
3+
4+
cmake_minimum_required(VERSION 3.22)
5+
6+
# Get parameters from environment or command line
7+
if(NOT DEFINED STUB_FILES)
8+
message(FATAL_ERROR "STUB_FILES must be defined")
9+
endif()
10+
11+
if(NOT DEFINED OUTPUT_DIR)
12+
message(FATAL_ERROR "OUTPUT_DIR must be defined")
13+
endif()
14+
15+
if(NOT DEFINED INCLUDE_DIRS)
16+
message(FATAL_ERROR "INCLUDE_DIRS must be defined")
17+
endif()
18+
19+
if(NOT DEFINED CXX_COMPILER)
20+
message(FATAL_ERROR "CXX_COMPILER must be defined")
21+
endif()
22+
23+
if(NOT DEFINED CXX_FLAGS)
24+
set(CXX_FLAGS "")
25+
endif()
26+
27+
# Parse the semicolon-separated lists
28+
string(REPLACE ";" " " STUB_FILES_LIST "${STUB_FILES}")
29+
string(REPLACE ";" " -I" INCLUDE_DIRS_LIST "${INCLUDE_DIRS}")
30+
set(INCLUDE_DIRS_LIST "-I${INCLUDE_DIRS_LIST}")
31+
32+
# Split stub files into a list
33+
string(REPLACE " " ";" FILE_LIST "${STUB_FILES_LIST}")
34+
35+
set(SUCCESS_COUNT 0)
36+
set(FAILURE_COUNT 0)
37+
set(FAILED_FILES "")
38+
39+
message("================================================================================")
40+
message("Compiling Generated Stubs - Individual File Validation")
41+
message("================================================================================")
42+
message("")
43+
44+
# Try to compile each file individually
45+
foreach(stub_file ${FILE_LIST})
46+
get_filename_component(stub_name "${stub_file}" NAME_WE)
47+
48+
# Try to compile
49+
execute_process(
50+
COMMAND ${CXX_COMPILER} ${CXX_FLAGS} ${INCLUDE_DIRS_LIST} -c "${stub_file}" -o "${OUTPUT_DIR}/${stub_name}.o"
51+
RESULT_VARIABLE compile_result
52+
OUTPUT_VARIABLE compile_output
53+
ERROR_VARIABLE compile_error
54+
WORKING_DIRECTORY ${OUTPUT_DIR}
55+
)
56+
57+
if(compile_result EQUAL 0)
58+
message("[✓] ${stub_name}")
59+
math(EXPR SUCCESS_COUNT "${SUCCESS_COUNT} + 1")
60+
else()
61+
message("[✗] ${stub_name}")
62+
math(EXPR FAILURE_COUNT "${FAILURE_COUNT} + 1")
63+
list(APPEND FAILED_FILES "${stub_name}")
64+
endif()
65+
endforeach()
66+
67+
# Print summary
68+
message("")
69+
message("================================================================================")
70+
message("Compilation Summary")
71+
message("================================================================================")
72+
message("Total files: ${CMAKE_CURRENT_LIST_LENGTH}")
73+
message("Successful: ${SUCCESS_COUNT}")
74+
message("Failed: ${FAILURE_COUNT}")
75+
76+
if(FAILURE_COUNT GREATER 0)
77+
message("")
78+
message("Failed files:")
79+
foreach(failed_file ${FAILED_FILES})
80+
message(" - ${failed_file}")
81+
endforeach()
82+
message("")
83+
message("To see detailed errors for a specific file, run:")
84+
message(" ninja test/CMakeFiles/test-stubs-compiled.dir/generated_stubs/<filename>_wamr.cpp.o")
85+
endif()
86+
87+
message("================================================================================")
88+
message("")
89+
90+
# Return non-zero if any failed
91+
if(FAILURE_COUNT GREATER 0)
92+
message(FATAL_ERROR "Some stub files failed to compile")
93+
endif()

test/StubGenerationTests.cmake

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ set(TEST_STUBS_TO_COMPILE
102102
futures
103103
)
104104

105-
# Remove the helper function - we want to try compiling even if files might not exist
106-
# The build will fail if they don't, which tells us generation failed
107-
108105
# Collect source files that should exist after generation
109106
set(STUB_SOURCES "")
110107
set(STUB_HEADERS "")
@@ -130,6 +127,9 @@ add_library(test-stubs-compiled STATIC EXCLUDE_FROM_ALL
130127
${STUB_SOURCES}
131128
)
132129

130+
# This library depends on stub generation
131+
add_dependencies(test-stubs-compiled generate-test-stubs)
132+
133133
# Link against cmcpp
134134
target_link_libraries(test-stubs-compiled
135135
PRIVATE cmcpp
@@ -162,18 +162,20 @@ elseif(MSVC)
162162
)
163163
endif()
164164

165-
# This library depends on stub generation
166-
add_dependencies(test-stubs-compiled generate-test-stubs)
167-
168165
# ===== Target: validate-test-stubs =====
169166
# Validates stub generation by attempting to compile them
167+
# Uses ninja's parallel compilation (determined by CMAKE_BUILD_PARALLEL_LEVEL or -j flag)
170168
add_custom_target(validate-test-stubs
171-
COMMAND ${CMAKE_COMMAND} -E echo "Validating generated stubs by compilation..."
172-
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target test-stubs-compiled
173-
COMMENT "Compiling generated stubs to validate code generation"
169+
COMMAND ${CMAKE_COMMAND} -E echo "Validating generated stubs by compilation (parallel build)..."
170+
COMMAND ${CMAKE_COMMAND} -E echo "Note: Using system default parallelism. Set CMAKE_BUILD_PARALLEL_LEVEL to override."
171+
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target test-stubs-compiled --parallel > ${CMAKE_BINARY_DIR}/stub_compilation.log 2>&1 || ${CMAKE_COMMAND} -E true
172+
COMMAND ${Python3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/summarize_stub_compilation.py"
173+
--log-file "${CMAKE_BINARY_DIR}/stub_compilation.log" || ${CMAKE_COMMAND} -E true
174+
COMMENT "Compiling generated stubs in parallel to validate code generation"
175+
BYPRODUCTS ${CMAKE_BINARY_DIR}/stub_compilation.log
174176
VERBATIM
175177
)
176-
add_dependencies(validate-test-stubs test-stubs-compiled)
178+
add_dependencies(validate-test-stubs generate-test-stubs)
177179

178180
# ===== Target: validate-test-stubs-basic =====
179181
# Validate only basic types (should always pass)
@@ -262,7 +264,7 @@ add_custom_target(clean-test-stubs
262264
# ===== Summary =====
263265
message(STATUS "Stub generation test targets configured:")
264266
message(STATUS " generate-test-stubs - Generate C++ stubs from WIT test files")
265-
message(STATUS " validate-test-stubs - Compile ALL stubs (full validation)")
267+
message(STATUS " validate-test-stubs - Compile ALL stubs (full validation, parallel)")
266268
message(STATUS " validate-test-stubs-basic - Compile only basic types (should pass)")
267269
message(STATUS " validate-test-stubs-composite - Compile only composite types")
268270
message(STATUS " validate-test-stubs-async - Compile only async types (likely fails)")
@@ -275,6 +277,7 @@ message(STATUS " WIT test directory: ${WIT_TEST_DIR}")
275277
message(STATUS " Output directory: ${STUB_OUTPUT_DIR}")
276278
message(STATUS " Python interpreter: ${Python3_EXECUTABLE}")
277279
message(STATUS " Test samples: ${CMAKE_CURRENT_LIST_LENGTH} test files")
280+
message(STATUS " Parallel build: Enabled (use CMAKE_BUILD_PARALLEL_LEVEL or -j to control)")
278281
message(STATUS "")
279282
message(STATUS "IMPORTANT: Compilation failures are EXPECTED and USEFUL!")
280283
message(STATUS " They indicate bugs in wit-codegen that need to be fixed.")
@@ -287,3 +290,7 @@ message(STATUS " 3. Fix any issues found")
287290
message(STATUS " 4. cmake --build build --target validate-test-stubs-async")
288291
message(STATUS " 5. Fix async issues")
289292
message(STATUS " 6. cmake --build build --target validate-test-stubs (full test)")
293+
message(STATUS "")
294+
message(STATUS "To control parallelism:")
295+
message(STATUS " CMAKE_BUILD_PARALLEL_LEVEL=8 cmake --build build --target validate-test-stubs")
296+
message(STATUS " or: ninja -j8 validate-test-stubs")

test/summarize_stub_compilation.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Summarize stub compilation results from build log.
4+
"""
5+
6+
import argparse
7+
import re
8+
import sys
9+
from pathlib import Path
10+
11+
def parse_compilation_log(log_file):
12+
"""Parse the build log and extract compilation results."""
13+
14+
if not log_file.exists():
15+
print(f"Error: Log file not found: {log_file}")
16+
return [], []
17+
18+
successful = set()
19+
failed = set()
20+
21+
with open(log_file, 'r', encoding='utf-8', errors='ignore') as f:
22+
content = f.read()
23+
24+
# Pattern for successful compilation
25+
# [XX/YY] Building CXX object test/CMakeFiles/test-stubs-compiled.dir/generated_stubs/NAME_wamr.cpp.o
26+
success_pattern = r'\[\d+/\d+\] Building CXX object test/CMakeFiles/test-stubs-compiled\.dir/generated_stubs/(\w+)_wamr\.cpp\.o'
27+
28+
# Pattern for failed compilation
29+
# FAILED: test/CMakeFiles/test-stubs-compiled.dir/generated_stubs/NAME_wamr.cpp.o
30+
failed_pattern = r'FAILED: test/CMakeFiles/test-stubs-compiled\.dir/generated_stubs/(\w+)_wamr\.cpp\.o'
31+
32+
# Find all successful compilations
33+
for match in re.finditer(success_pattern, content):
34+
stub_name = match.group(1)
35+
successful.add(stub_name)
36+
37+
# Find all failed compilations
38+
for match in re.finditer(failed_pattern, content):
39+
stub_name = match.group(1)
40+
failed.add(stub_name)
41+
# Remove from successful if it was there (shouldn't happen but be safe)
42+
successful.discard(stub_name)
43+
44+
return sorted(successful), sorted(failed)
45+
46+
def main():
47+
parser = argparse.ArgumentParser(description='Summarize stub compilation results')
48+
parser.add_argument('--log-file', required=True, help='Path to compilation log file')
49+
parser.add_argument('--stub-list', help='Path to file listing expected stubs (optional)')
50+
51+
args = parser.parse_args()
52+
53+
log_file = Path(args.log_file)
54+
55+
successful, failed = parse_compilation_log(log_file)
56+
57+
total = len(successful) + len(failed)
58+
59+
# Print summary
60+
print()
61+
print("=" * 80)
62+
print("Stub Compilation Summary")
63+
print("=" * 80)
64+
print()
65+
print(f"Total stubs attempted: {total}")
66+
print(f"Successful: {len(successful)} ({100*len(successful)//total if total > 0 else 0}%)")
67+
print(f"Failed: {len(failed)} ({100*len(failed)//total if total > 0 else 0}%)")
68+
print()
69+
70+
if successful:
71+
print("Successfully compiled stubs:")
72+
for stub in successful:
73+
print(f" ✓ {stub}")
74+
print()
75+
76+
if failed:
77+
print("Failed stubs:")
78+
for stub in failed:
79+
print(f" ✗ {stub}")
80+
print()
81+
print("To see detailed errors for a specific stub, run:")
82+
print(" ninja test/CMakeFiles/test-stubs-compiled.dir/generated_stubs/<stub-name>_wamr.cpp.o")
83+
else:
84+
print("All stubs compiled successfully! ✓")
85+
86+
print()
87+
print("=" * 80)
88+
print()
89+
90+
# Return non-zero if any failed
91+
return 1 if failed else 0
92+
93+
if __name__ == '__main__':
94+
sys.exit(main())

0 commit comments

Comments
 (0)