CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
113 lines
3.5 KiB
Python
113 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
|
|
# Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
"""
|
|
Script to copy external header files with nested headers inlined. Since this is
|
|
intended for run time compilation, HIP headers are skipped entirely.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import re
|
|
from pathlib import Path
|
|
|
|
|
|
def inline_includes(filepath, root_dir, processed=None, depth=0, max_depth=100):
|
|
"""Recursively inline #include directives."""
|
|
if processed is None:
|
|
processed = set()
|
|
|
|
# Prevent infinite recursion
|
|
if depth > max_depth:
|
|
raise RuntimeError(f"Include depth exceeded {max_depth}")
|
|
|
|
# Normalize path
|
|
filepath = os.path.normpath(filepath)
|
|
|
|
if filepath in processed:
|
|
return []
|
|
processed.add(filepath)
|
|
|
|
result = []
|
|
try:
|
|
with open(filepath, "r", encoding="utf-8", errors="ignore") as f:
|
|
for line in f:
|
|
# Check for #include directives
|
|
match = re.match(r'^\s*#include\s+[<"]([^>"]+)[>"]', line)
|
|
if match:
|
|
include_file = match.group(1)
|
|
|
|
# Skip HIP headers entirely - do not include them at all
|
|
if include_file.startswith("hip/"):
|
|
continue
|
|
|
|
# Try to find the included file relative to root
|
|
include_path = os.path.join(root_dir, include_file)
|
|
|
|
if os.path.exists(include_path):
|
|
# Add comment showing what's being inlined
|
|
result.append(f"// BEGIN INLINED: {include_file}")
|
|
# Recursively inline
|
|
inlined_content = inline_includes(
|
|
include_path, root_dir, processed, depth + 1, max_depth
|
|
)
|
|
result.extend(inlined_content)
|
|
result.append(f"// END INLINED: {include_file}")
|
|
else:
|
|
# Keep the include if file not found (might be a system header)
|
|
result.append(line.rstrip())
|
|
else:
|
|
# Keep non-include lines as-is
|
|
result.append(line.rstrip())
|
|
except Exception as e:
|
|
print(f"Error processing {filepath}: {e}", file=sys.stderr)
|
|
raise
|
|
|
|
return result
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) != 4:
|
|
print(
|
|
"Usage: InlineHeader.py <source_header> <root_include_dir> <output_file>",
|
|
file=sys.stderr,
|
|
)
|
|
sys.exit(1)
|
|
|
|
source_file = sys.argv[1]
|
|
root_dir = sys.argv[2]
|
|
output_file = sys.argv[3]
|
|
|
|
if not os.path.exists(source_file):
|
|
print(f"Error: Source file not found: {source_file}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
if not os.path.exists(root_dir):
|
|
print(f"Error: Root directory not found: {root_dir}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
# Generate guard name from output filename
|
|
guard_name = Path(output_file).stem.upper().replace(".", "_") + "_H"
|
|
|
|
try:
|
|
content_lines = inline_includes(source_file, root_dir)
|
|
|
|
# Write output with header guards
|
|
with open(output_file, "w", encoding="utf-8") as f:
|
|
f.write(f"#ifndef {guard_name}\n")
|
|
f.write(f"#define {guard_name}\n\n")
|
|
f.write("\n".join(content_lines))
|
|
f.write(f"\n\n#endif // {guard_name}\n")
|
|
|
|
print(f"Successfully created {output_file}")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|