From 0ac6fdae941ef03dcaf419171e39080feb9060f1 Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Wed, 15 Nov 2023 12:16:55 -0600 Subject: [PATCH] scripts: Add include-what-you-use (iwyu) related scripts and configs --- scripts/cppwinrt.imp | 7 + scripts/eigen.imp | 20 +++ scripts/generate_iwyu_mapping.py | 153 ++++++++++++++++++++++ scripts/generate_iwyu_mapping_cppwinrt.py | 65 +++++++++ scripts/generate_iwyu_mapping_msvc.py | 57 ++++++++ scripts/generate_iwyu_mapping_windows.py | 32 +++++ scripts/mapping.imp | 103 +++++++++++++++ scripts/msvc.imp | 28 ++++ scripts/opencv.imp | 9 ++ scripts/run_iwyu.ps1 | 82 ++++++++++++ scripts/run_iwyu.sh | 13 ++ scripts/windows.imp | 7 + src/xrt/.clang-format | 20 ++- 13 files changed, 594 insertions(+), 2 deletions(-) create mode 100644 scripts/cppwinrt.imp create mode 100644 scripts/eigen.imp create mode 100755 scripts/generate_iwyu_mapping.py create mode 100644 scripts/generate_iwyu_mapping_cppwinrt.py create mode 100644 scripts/generate_iwyu_mapping_msvc.py create mode 100644 scripts/generate_iwyu_mapping_windows.py create mode 100644 scripts/mapping.imp create mode 100644 scripts/msvc.imp create mode 100644 scripts/opencv.imp create mode 100644 scripts/run_iwyu.ps1 create mode 100755 scripts/run_iwyu.sh create mode 100644 scripts/windows.imp diff --git a/scripts/cppwinrt.imp b/scripts/cppwinrt.imp new file mode 100644 index 000000000..d5dcd46fa --- /dev/null +++ b/scripts/cppwinrt.imp @@ -0,0 +1,7 @@ +# Copyright 2022-2023, Collabora, Ltd. +# +# SPDX-License-Identifier: BSL-1.0 +# +# GENERATED - edit generate_iwyu_mapping_cppwinrt.py instead of this file +[ +] diff --git a/scripts/eigen.imp b/scripts/eigen.imp new file mode 100644 index 000000000..a88d89f56 --- /dev/null +++ b/scripts/eigen.imp @@ -0,0 +1,20 @@ +# Copyright 2022-2023, Collabora, Ltd. +# +# SPDX-License-Identifier: BSL-1.0 +# +# GENERATED - edit generate_iwyu_mapping.py instead of this file +[ +{ include: ["@[<\"]src/Core/ArrayBase.h[>\"]", "private", "", "public"] }, +{ include: ["@[<\"]src/Core/MatrixBase.h[>\"]", "private", "", "public"] }, +{ include: ["@[<\"]src/Core/DenseBase.h[>\"]", "private", "", "public"] }, +{ include: ["@[<\"]Eigen/src/Core/.*", "private", "", "public"] }, +{ include: ["@[<\"]src/Core/.*", "private", "", "public"] }, +{ include: ["@[<\"]Eigen/src/Geometry/.*", "private", "", "public"] }, +{ include: ["@[<\"]src/Geometry/.*", "private", "", "public"] }, +{ include: ["@[<\"]Eigen/src/LU/.*", "private", "", "public"] }, +{ include: ["@[<\"]src/LU/.*", "private", "", "public"] }, +{ include: ["@[<\"]Eigen/src/SparseCore/.*", "private", "", "public"] }, +{ include: ["@[<\"]src/SparseCore/.*", "private", "", "public"] }, +{ include: ["@[<\"]Eigen/src/Sparse/.*", "private", "", "public"] }, +{ include: ["@[<\"]src/Sparse/.*", "private", "", "public"] }, +] diff --git a/scripts/generate_iwyu_mapping.py b/scripts/generate_iwyu_mapping.py new file mode 100755 index 000000000..91c87e0b9 --- /dev/null +++ b/scripts/generate_iwyu_mapping.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python3 +# Copyright 2022-2023, Collabora, Ltd. +# +# SPDX-License-Identifier: BSL-1.0 +# +# Original author: Rylie Pavlik ", "public", "\\"math/m_mathinclude.h\\"", "public"] },""", + """{ include: ["", "public", "\\"math/m_mathinclude.h\\"", "public"] },""", + """{ symbol: ["M_PI", "public", "\\"math/m_mathinclude.h\\"", "public"] },""", + """{ symbol: ["M_PIl", "public", "\\"math/m_mathinclude.h\\"", "public"] },""", + """{ symbol: ["M_1_PI", "public", "\\"math/m_mathinclude.h\\"", "public"] },""", + """{ symbol: ["ssize_t", "public", "\\"xrt/xrt_compiler.h\\"", "public"] },""", +] + +_MISC_ERRORS = [ + """{ include: ["@[<\\"]bits/exception.h[>\\"]", "private", "", "public"] },""", + """{ include: ["@[<\\"]ext/alloc_traits.h[>\\"]", "private", "", "public"] },""", + """{ include: ["@[<\\"]bits/types/struct_iovec.h.", "private", "", "public"] },""", +] + +_MISC_DEPS = [ + """{ include: ["@[<\\"]jmoreconfig.h>\\"]", "private", "\\"jpeglib.h\\"", "public"] },""", +] + +_OPENCV_ENTRIES = [ + """{ include: ["@", "private", "", "public"] },""", + """{ include: ["@", "public"] },""", +] + + +def _generate_openxr_entries(): + for header in ("openxr_platform.h", "openxr_platform_defines.h"): + yield """{ include: ["@[<\\"]openxr/%s.*", "private", "\\"xrt/xrt_openxr_includes.h\\"", "public"] },""" % header + + +def _generate_eigen_entries(): + for stubborn_header in ("ArrayBase", "MatrixBase", "DenseBase"): + yield """{ include: ["@[<\\"]src/Core/%s.h[>\\"]", "private", "", "public"] },""" % ( + stubborn_header, + ) + for module in ("Core", "Geometry", "LU", "SparseCore", "Sparse"): + yield """{ include: ["@[<\\"]Eigen/src/%s/.*", "private", "", "public"] },""" % ( + module, + module, + ) + yield """{ include: ["@[<\\"]src/%s/.*", "private", "", "public"] },""" % ( + module, + module, + ) + + +_CONFIG_HEADERS = ( + "xrt_config_android.h", + "xrt_config_build.h", + "xrt_config_drivers.h", + "xrt_config_have.h", + "xrt_config_vulkan.h", +) + + +def _generate_config_header_defines(): + for header in _CONFIG_HEADERS: + input_filename = header + ".cmake_in" + input_file = _REPO / "src" / "xrt" / "include" / "xrt" / input_filename + with open(str(input_file), "r", encoding="utf-8") as fp: + for line in fp: + if line.startswith("#cmakedefine"): + parts = line.split(" ") + symbol = parts[1].strip() + yield """{ symbol: ["%s", "public", "\\"xrt/%s\\"", "public"] },""" % ( + symbol, + header, + ) + + +def get_all_entries(): + entries = [] + entries.extend(_WRAPPERS) + entries.extend(_MISC_ERRORS) + entries.extend(_MISC_DEPS) + # entries.extend(_OPENCV_ENTRIES) + # entries.extend(_generate_eigen_entries()) + entries.extend(_generate_openxr_entries()) + entries.extend(_generate_config_header_defines()) + return entries + + +# REUSE-IgnoreStart + + +def _find_copyright_lines(fn: Path, *args): + with open(fn, encoding="utf-8") as f: + copyright_lines = [line.strip() for line in f if line.startswith("# Copyright")] + + known_lines = set(copyright_lines) + for alt_fn in args: + with open(_SCRIPT_DIR / alt_fn, encoding="utf-8") as f: + new_lines = [line.strip() for line in f if line.startswith("# Copyright")] + copyright_lines.extend(line for line in new_lines if line not in known_lines) + known_lines.update(new_lines) + + return copyright_lines + + +def write_mapping_file(entries: List[str], output_filename: Path, script_name: str): + """Write an IWYU mapping file with the given entries.""" + # Grab all lines from this and our other script. + lines = _find_copyright_lines(_FILE, script_name) + lines += [ + """#""", + "# SPDX-License" + "-Identifier: BSL-1.0", # split to avoid breaking REUSE tool + """#""", + """# GENERATED - edit %s instead of this file""" % script_name, + "[", + ] + lines.extend(entries) + lines += "]" + content = "".join(line + "\n" for line in lines) + with open(output_filename, "w", encoding="utf-8") as fp: + fp.write(content) + + +# REUSE-IgnoreEnd + + +def write_file(): + my_script_fn = Path(__file__).resolve().name + eigen_path = _SCRIPT_DIR / "eigen.imp" + write_mapping_file(list(_generate_eigen_entries()), eigen_path, my_script_fn) + + opencv_path = _SCRIPT_DIR / "opencv.imp" + write_mapping_file(_OPENCV_ENTRIES, opencv_path, my_script_fn) + entries = get_all_entries() + for ref_path in (eigen_path, opencv_path): + entries.append("""{ ref: "%s" },""" % ref_path.name) + write_mapping_file(entries, _OUTPUT_FILENAME, my_script_fn) + + +if __name__ == "__main__": + write_file() diff --git a/scripts/generate_iwyu_mapping_cppwinrt.py b/scripts/generate_iwyu_mapping_cppwinrt.py new file mode 100644 index 000000000..6bb06ed44 --- /dev/null +++ b/scripts/generate_iwyu_mapping_cppwinrt.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +# Copyright 2022-2023, Collabora, Ltd. +# +# SPDX-License-Identifier: BSL-1.0 +# +# Original author: Rylie Pavlik str: + with open(header, "r", encoding="utf-8") as fp: + for line in fp: + result = header_guard.match(line) + if not result: + continue + define_insides = result.group(1) + return define_insides.replace("_", ".") + + raise RuntimeError("Could not figure out namespace name for " + str(header)) + + +def make_canonical_include(namespace_name: str) -> str: + return "" % namespace_name + + +def make_private_include_pattern(namespace_name: str) -> str: + def munge_character(c: str): + if c == ".": + return "[.]" + if c.isupper(): + return "[%s%s]" % (c, c.lower()) + return c + + munged_namespace = "".join(munge_character(c) for c in namespace_name) + return "@" % munged_namespace + + +def get_all_cppwinrt_entries(cppwinrt_root: str): + root = Path(cppwinrt_root) + for header in root.glob("*.h"): + namespace_name = find_namespace_name(header) + pattern = make_private_include_pattern(namespace_name) + canonical = make_canonical_include(namespace_name) + yield """{ include: ["%s", "private", "%s", "public"] },""" % ( + pattern, + canonical, + ) + + +def write_file(cppwinrt_root: str): + entries = list(get_all_cppwinrt_entries(cppwinrt_root)) + write_mapping_file(entries, _OUTPUT_FILENAME, Path(__file__).resolve().name) + + +if __name__ == "__main__": + write_file(sys.argv[1]) diff --git a/scripts/generate_iwyu_mapping_msvc.py b/scripts/generate_iwyu_mapping_msvc.py new file mode 100644 index 000000000..f1e6e3e1e --- /dev/null +++ b/scripts/generate_iwyu_mapping_msvc.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# Copyright 2022-2023, Collabora, Ltd. +# +# SPDX-License-Identifier: BSL-1.0 +# +# Original author: Rylie Pavlik ": [""], + "": [""], + "": [""], + "": [""], + "": ["", ""], + "": [""], + # This header contains common functionality used by a ton of containers + "": [ + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + ], +} + + +def get_all_stl_entries(): + for src, dests in _STL_EQUIVS.items(): + for dest in dests: + yield """{ include: ["%s", "private", "%s", "public"] },""" % ( + src, + dest, + ) + + +def write_file(): + entries = list(get_all_stl_entries()) + write_mapping_file(entries, _OUTPUT_FILENAME, Path(__file__).resolve().name) + + +if __name__ == "__main__": + write_file() diff --git a/scripts/generate_iwyu_mapping_windows.py b/scripts/generate_iwyu_mapping_windows.py new file mode 100644 index 000000000..8e2747017 --- /dev/null +++ b/scripts/generate_iwyu_mapping_windows.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +# Copyright 2022-2023, Collabora, Ltd. +# +# SPDX-License-Identifier: BSL-1.0 +# +# Original author: Rylie Pavlik "} + + +def get_all_entries(): + for sym, header in _SYMBOLS.items(): + yield """{ symbol: ["%s", "public", "%s", "public"] },""" % ( + sym, + header, + ) + + +def write_file(): + entries = list(get_all_entries()) + write_mapping_file(entries, _OUTPUT_FILENAME, Path(__file__).resolve().name) + + +if __name__ == "__main__": + write_file() diff --git a/scripts/mapping.imp b/scripts/mapping.imp new file mode 100644 index 000000000..174119559 --- /dev/null +++ b/scripts/mapping.imp @@ -0,0 +1,103 @@ +# Copyright 2022-2023, Collabora, Ltd. +# +# SPDX-License-Identifier: BSL-1.0 +# +# GENERATED - edit generate_iwyu_mapping.py instead of this file +[ +{ include: ["@[<\"]vulkan/.+", "private", "\"xrt/xrt_vulkan_includes.h\"", "public"] }, +{ include: ["\"EGL/eglplatform.h\"", "private", "\"ogl/ogl_api.h\"", "public"] }, +{ include: ["", "public", "\"math/m_mathinclude.h\"", "public"] }, +{ include: ["", "public", "\"math/m_mathinclude.h\"", "public"] }, +{ symbol: ["M_PI", "public", "\"math/m_mathinclude.h\"", "public"] }, +{ symbol: ["M_PIl", "public", "\"math/m_mathinclude.h\"", "public"] }, +{ symbol: ["M_1_PI", "public", "\"math/m_mathinclude.h\"", "public"] }, +{ symbol: ["ssize_t", "public", "\"xrt/xrt_compiler.h\"", "public"] }, +{ include: ["@[<\"]bits/exception.h[>\"]", "private", "", "public"] }, +{ include: ["@[<\"]ext/alloc_traits.h[>\"]", "private", "", "public"] }, +{ include: ["@[<\"]bits/types/struct_iovec.h.", "private", "", "public"] }, +{ include: ["@[<\"]jmoreconfig.h>\"]", "private", "\"jpeglib.h\"", "public"] }, +{ include: ["@[<\"]openxr/openxr_platform.h.*", "private", "\"xrt/xrt_openxr_includes.h\"", "public"] }, +{ include: ["@[<\"]openxr/openxr_platform_defines.h.*", "private", "\"xrt/xrt_openxr_includes.h\"", "public"] }, +{ symbol: ["XRT_ANDROID_PACKAGE", "public", "\"xrt/xrt_config_android.h\"", "public"] }, +{ symbol: ["XRT_MODULE_AUX_VIVE", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_MODULE_COMPOSITOR", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_MODULE_COMPOSITOR_MAIN", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_MODULE_COMPOSITOR_NULL", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_MODULE_MERCURY_HANDTRACKING", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_MODULE_IPC", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_MODULE_MONADO_GUI", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_MODULE_MONADO_CLI", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_CLIENT_DEBUG_GUI", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_COLOR_LOG", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_DEBUG_GUI", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_DEBUG_UTILS", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_DISPLAY_REFRESH_RATE", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_FORCE_FEEDBACK_CURL", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_HEADLESS", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_INTERACTION_EXT_EYE_GAZE", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_INTERACTION_EXT_HAND", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_INTERACTION_EXT_PALM_POSE", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_INTERACTION_ML2", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_INTERACTION_MNDX", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_INTERACTION_MSFT_HAND", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_INTERACTION_OPPO", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_INTERACTION_WINMR", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_LAYER_CUBE", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_LAYER_CYLINDER", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_LAYER_DEPTH", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_LAYER_EQUIRECT1", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_LAYER_EQUIRECT2", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_OVERLAY", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_SPACE_LOCAL_FLOOR", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_SPACE_UNBOUNDED", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_OPENXR_VISIBILITY_MASK", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_RENDERDOC", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_SERVICE", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_SERVICE_SYSTEMD", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_SLAM", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_SSE2", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_STEAMVR_PLUGIN", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_TRACING", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_FEATURE_WINDOW_PEEK", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_IPC_MSG_SOCK_FILENAME", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_IPC_SERVICE_PID_FILENAME", "public", "\"xrt/xrt_config_build.h\"", "public"] }, +{ symbol: ["XRT_HAVE_BASALT", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_BLUETOOTH", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_D3D11", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_D3D12", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_DBUS", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_DXGI", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_EGL", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_FFMPEG", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_GST", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_HIDAPI", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_JPEG", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_KIMERA", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_LIBBSD", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_LIBUDEV", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_LIBUSB", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_LIBUVC", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_OPENCV", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_OPENGL", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_OPENGLES", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_OPENVR", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_PERCETTO", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_SDL2", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_SYSTEMD", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_TRACY", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_V4L2", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_VULKAN", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_WAYLAND", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_WAYLAND_DIRECT", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_WIL", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["XRT_HAVE_WINRT", "public", "\"xrt/xrt_config_have.h\"", "public"] }, +{ symbol: ["VK_USE_PLATFORM_ANDROID_KHR", "public", "\"xrt/xrt_config_vulkan.h\"", "public"] }, +{ symbol: ["VK_USE_PLATFORM_WAYLAND_KHR", "public", "\"xrt/xrt_config_vulkan.h\"", "public"] }, +{ symbol: ["VK_USE_PLATFORM_XCB_KHR", "public", "\"xrt/xrt_config_vulkan.h\"", "public"] }, +{ symbol: ["VK_USE_PLATFORM_XLIB_XRANDR_EXT", "public", "\"xrt/xrt_config_vulkan.h\"", "public"] }, +{ symbol: ["VK_USE_PLATFORM_WIN32_KHR", "public", "\"xrt/xrt_config_vulkan.h\"", "public"] }, +{ symbol: ["VK_USE_PLATFORM_DISPLAY_KHR", "public", "\"xrt/xrt_config_vulkan.h\"", "public"] }, +{ ref: "eigen.imp" }, +{ ref: "opencv.imp" }, +] diff --git a/scripts/msvc.imp b/scripts/msvc.imp new file mode 100644 index 000000000..61478d05c --- /dev/null +++ b/scripts/msvc.imp @@ -0,0 +1,28 @@ +# Copyright 2022, Collabora, Ltd. +# SPDX-License-Identifier: BSL-1.0 +# +# GENERATED - edit generate_iwyu_mapping_msvc.py instead of this file +[ +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +{ include: ["", "private", "", "public"] }, +] diff --git a/scripts/opencv.imp b/scripts/opencv.imp new file mode 100644 index 000000000..fd502f853 --- /dev/null +++ b/scripts/opencv.imp @@ -0,0 +1,9 @@ +# Copyright 2022-2023, Collabora, Ltd. +# +# SPDX-License-Identifier: BSL-1.0 +# +# GENERATED - edit generate_iwyu_mapping.py instead of this file +[ +{ include: ["@", "private", "", "public"] }, +{ include: ["@", "public"] }, +] diff --git a/scripts/run_iwyu.ps1 b/scripts/run_iwyu.ps1 new file mode 100644 index 000000000..7e78229fa --- /dev/null +++ b/scripts/run_iwyu.ps1 @@ -0,0 +1,82 @@ +# Copyright 2022, Collabora, Ltd. +# SPDX-License-Identifier: BSL-1.0 +[CmdletBinding()] +param ( + [Parameter()] + [string] + $IwyuBinDir, + + [Parameter()] + [string] + $Python +) + +$ErrorActionPreference = 'Stop' +Push-Location $PSScriptRoot/.. + +if (!$IwyuBinDir) { + $cmd = Get-Command "iwyu" -ErrorAction SilentlyContinue + if ($cmd) { + $IwyuBinDir = $cmd.Source + } +} +if (!$IwyuBinDir) { + Write-Error "Please specify IwyuBinDir - could not find on path" + return -1 +} + +if (!$Python) { + $cmd = Get-Command "python3" -ErrorAction SilentlyContinue + if ($cmd) { + $Python = $cmd.Source + } +} +if (!$Python) { + $cmd = Get-Command "python" -ErrorAction SilentlyContinue + if ($cmd) { + $Python = $cmd.Source + } +} +if (!$Python) { + Write-Error "Please specify Python - could not find on path" + return -1 +} + +$iwyuShareDir = Get-Item -Path $IwyuBinDir/../share/include-what-you-use + +function Create-Args { + + [CmdletBinding()] + Param( + + [Parameter(ValueFromPipeline)] + $FullName + ) + + process { + $item = Get-Item $FullName + Write-Output '-Xiwyu' + Write-Output ("--mapping_file=" + $item.FullName) + } +} + +$python_args = @( + (Join-Path $IwyuBinDir "iwyu_tool.py") + "-p" + "build" + "src/xrt" + "--" +) +$python_args = $python_args + (Join-Path $iwyuShareDir 'iwyu.gcc.imp' | Create-Args) +$python_args = $python_args + (Get-ChildItem -Path $iwyuShareDir -Filter "*intrinsics.imp" | Create-Args) +$python_args = $python_args + (Get-ChildItem -Path $iwyuShareDir -Filter "libcxx.imp" | Create-Args) +Write-Host $python_args +$our_mapping_file = Join-Path (Get-Location) scripts/mapping.imp + +$python_args = $python_args + @("-Xiwyu", "--mapping_file=$our_mapping_file") +# & $Python (Join-Path $IwyuBinDir "iwyu_tool.py") -p build src/xrt -- -Xiwyu "--mapping_file=$our_mapping_file" @python_args | Tee-Object -FilePath iwyu.txt -Encoding utf8 + +Start-Process -FilePath $Python -ArgumentList $python_args -PassThru -Wait -NoNewWindow + +Pop-Location + diff --git a/scripts/run_iwyu.sh b/scripts/run_iwyu.sh new file mode 100755 index 000000000..c2b538096 --- /dev/null +++ b/scripts/run_iwyu.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# Copyright 2022, Collabora, Ltd. +# SPDX-License-Identifier: BSL-1.0 + +( + set -e + cd "$(dirname $0)" && cd .. + extra_args="" + for fn in /usr/share/include-what-you-use/iwyu.gcc.imp /usr/share/include-what-you-use/*intrinsics.imp /usr/share/include-what-you-use/libcxx*.imp; do + extra_args="${extra_args} -Xiwyu --mapping_file=$fn" + done + iwyu_tool -p build src/xrt/ "$@" -- -Xiwyu "--mapping_file=$(pwd)/scripts/mapping.imp" ${extra_args} | tee iwyu.txt +) diff --git a/scripts/windows.imp b/scripts/windows.imp new file mode 100644 index 000000000..e77f9501e --- /dev/null +++ b/scripts/windows.imp @@ -0,0 +1,7 @@ +# Copyright 2022, Collabora, Ltd. +# SPDX-License-Identifier: BSL-1.0 +# +# GENERATED - edit generate_iwyu_mapping_windows.py instead of this file +[ +{ symbol: ["IUnknown", "public", "", "public"] }, +] diff --git a/src/xrt/.clang-format b/src/xrt/.clang-format index 8c6a083a2..f55e41fc9 100644 --- a/src/xrt/.clang-format +++ b/src/xrt/.clang-format @@ -1,12 +1,28 @@ --- # SPDX-License-Identifier: CC0-1.0 -# SPDX-FileCopyrightText: 2020, Collabora, Ltd. +# SPDX-FileCopyrightText: 2020-2022, Collabora, Ltd. Language: Cpp BasedOnStyle: LLVM Standard: Auto # Includes -SortIncludes: false +SortIncludes: false +# SortIncludes: true +# IncludeBlocks: Regroup +# # IncludeBlocks: Preserve +# IncludeCategories: +# # xrt includes first, they set up defines, clean up after messy headers, etc. +# - Regex: "^[<\"](xrt)/" +# Priority: 2 +# # Then, any other internal library +# - Regex: "^[<\"](util|vk|os|math|render|multi)/" +# Priority: 3 +# # system includes +# - Regex: "<([[:alnum:].]+|type_traits)>" +# Priority: 5 +# # Everything else (local includes) +# - Regex: ".*" +# Priority: 2 # Spacing and Blank Lines DerivePointerAlignment: false