From 515f632cb59b459d53abc06972f9c0c7ebf67318 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 6 Oct 2023 23:10:40 -0400 Subject: [PATCH 01/30] initial commit (kitbashed from kalman project) --- CMakeLists.txt | 50 +++++++++++++++++++++++++++++ README.md | 26 ++++++++++++++++ cmake/xo_pyreflectConfig.cmake.in | 4 +++ src/pyreflect/CMakeLists.txt | 11 +++++++ src/pyreflect/pyreflect.cpp | 52 +++++++++++++++++++++++++++++++ src/pyreflect/pyreflect.hpp.in | 25 +++++++++++++++ 6 files changed, 168 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 cmake/xo_pyreflectConfig.cmake.in create mode 100644 src/pyreflect/CMakeLists.txt create mode 100644 src/pyreflect/pyreflect.cpp create mode 100644 src/pyreflect/pyreflect.hpp.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..9c372fd5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,50 @@ +# xo-pyreflect/CMakeLists.txt + +cmake_minimum_required(VERSION 3.10) + +project(xo_pyreflect VERSION 0.1) +enable_language(CXX) + +# common XO cmake macros (see github.com:Rconybea/xo-cmake) +include(xo_macros/xo_cxx) +include(xo_macros/code-coverage) + +# ---------------------------------------------------------------- +# unit test setup + +enable_testing() +# activate code coverage for all executables + libraries (when configured with -DCODE_COVERAGE=ON) +add_code_coverage() +# 1. assuming that /nix/store/ prefixes .hpp files belonging to gcc, catch2 etc. +# we're not interested in code coverage for these sources. +# 2. exclude the utest/ subdir, we don't need coverage on the unit tests themselves; +# rather, want coverage on the code that the unit tests exercise. +# +# NOTE: this seems to work only with the 'ccov-all' target. In particular, doesn't seem to do anything with the 'ccov' target +# +add_code_coverage_all_targets(EXCLUDE /nix/store/* ${PROJECT_SOURCE_DIR}/utest/* ${PROJECT_BINARY_DIR}/local/* ${PROJECT_SOURCE_DIR}/repo/*) + +# ---------------------------------------------------------------- +# c++ settings (usually temporary) + +set(PROJECT_CXX_FLAGS "") +add_definitions(${PROJECT_CXX_FLAGS}) + +xo_toplevel_compile_options() + +# ---------------------------------------------------------------- +# sources + +# note: library=pyreflect (not xo_pyreflect) -> establishes pyreflectTargets +add_subdirectory(src/pyreflect) +#add_subdirectory(utest) + +# ---------------------------------------------------------------- +# provide find_package() support + +xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} pyreflectTargets) + +# ---------------------------------------------------------------- +# install .hpp files + +#xo_install_include_tree() diff --git a/README.md b/README.md new file mode 100644 index 00000000..c020ad6e --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# python bindings for c++ reflection library (xo-reflect) + +### build + install +``` +$ cd xo-pyreflect +$ mkdir build +$ cd build +$ INSTALL_PREFIX=/usr/local # or wherever you prefer, e.g. ~/local +$ cmake -DCMAKE_MODULE_PATH=${INSTALL_PREFIX}/share/cmake -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} .. +$ make +$ make install +``` + +### build for unit test coverage +``` +$ cd xo-pyreflect +$ mkdir build-ccov +$ cd build-ccov +$ cmake -DCMAKE_MODULE_PATH=${INSTALL_PREFIX}/share/cmake -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} -DCODE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug .. +``` + +### LSP support +``` +$ cd xo-pyreflect +$ ln -s build/compile_commands.json # lsp will look for compile_commands.json in the root of the source tree +``` diff --git a/cmake/xo_pyreflectConfig.cmake.in b/cmake/xo_pyreflectConfig.cmake.in new file mode 100644 index 00000000..9c15f36a --- /dev/null +++ b/cmake/xo_pyreflectConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/src/pyreflect/CMakeLists.txt b/src/pyreflect/CMakeLists.txt new file mode 100644 index 00000000..9b63978f --- /dev/null +++ b/src/pyreflect/CMakeLists.txt @@ -0,0 +1,11 @@ +# xo_pyreflect/CMakeLists.txt + +set(SELF_LIB pyreflect) +set(SELF_SRCS pyreflect.cpp) + +# ---------------------------------------------------------------- +# pybind11 dep + +xo_pybind11_library(${SELF_LIB} ${SELF_SRCS}) + +xo_dependency(${SELF_LIB} reflect) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp new file mode 100644 index 00000000..3a9f81bb --- /dev/null +++ b/src/pyreflect/pyreflect.cpp @@ -0,0 +1,52 @@ +/* @file pyreflect.cpp */ + +// note: need pyreflect/ here bc pyreflect.hpp is generated, located in build directory +#include "src/pyreflect/pyreflect.hpp" +#include "xo/reflect/TypeDescr.hpp" +#include "xo/reflect/TaggedRcptr.hpp" +#include "xo/reflect/SelfTagging.hpp" +//#include "time/Time.hpp" +//#include "xo/pyutil/pytime.hpp" +#include "xo/pyutil/pyutil.hpp" +//#include +//#include +//#include +//#include + +namespace xo { + using xo::time::utc_nanos; + using xo::ref::unowned_ptr; + using xo::ref::rp; + namespace py = pybind11; + + namespace reflect { + PYBIND11_MODULE(PYREFLECT_MODULE_NAME(), m) { + + /* note: possibly move this to pytime/ if/when we provide it */ + //py::class_(m, "utc_nanos"); + + //py::class_(m, "TypeDescr"); + py::class_>(m, "TypeDescr") + .def_static("print_reflected_types", + [](){ TypeDescrBase::print_reflected_types(std::cout); }) + .def_property_readonly("canonical_name", &TypeDescrBase::canonical_name) + .def("__repr__", &TypeDescrBase::display_string); + + /* note: this means python will use + * std::unique_ptr + * when it encounters a TaggedRcptr instance. + * Maintains refcount at cost of 2nd level of indirection. + */ + py::class_(m, "TaggedRcptr") + .def_property_readonly("td", &TaggedPtr::td) + .def("__repr__", &TaggedRcptr::display_string); + + py::class_>(m, "SelfTagging") + .def("self_tp", &SelfTagging::self_tp); + + } /*pyreflect*/ + } /*namespace reflect*/ +} /*namespace xo*/ + +/* end pyreflect.cpp */ diff --git a/src/pyreflect/pyreflect.hpp.in b/src/pyreflect/pyreflect.hpp.in new file mode 100644 index 00000000..62b64a25 --- /dev/null +++ b/src/pyreflect/pyreflect.hpp.in @@ -0,0 +1,25 @@ +/* @file pyreflect.hpp + * + * automatically generated from src/xo_pyreflect/pyreflect.hpp.in + * see src/xo_pyreflect/CMakeLists.txt + */ + +/* python requires module name = library name + * example: + * PYBIND11_MODULE(PYREFLECT_MODULE_NAME(), m) { ... } + */ +#define PYREFLECT_MODULE_NAME() @SELF_LIB@ + +/* example: + * py::module_::import(PYREFLECT_MODULE_NAME_STR) + */ +#define PYREFLECT_MODULE_NAME_STR "@SELF_LIB@" + +/* example: + * PYREFLECT_IMPORT_MODULE() + * replaces + * py::module_::import("pyreflect") + */ +#define PYREFLECT_IMPORT_MODULE() py::module_::import("@SELF_LIB@") + +/* end pyreflect.hpp */ From c12a3ec726d04a311ec39cd84bc9fd4210438f5b Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 6 Oct 2023 23:13:27 -0400 Subject: [PATCH 02/30] + .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..6abfb0de --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# lsp keeps state here +.cache +# typical build directory +build From a467f151bcaa9e6e3a1b6de1b2bbac279d9b19a6 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 6 Oct 2023 23:41:16 -0400 Subject: [PATCH 03/30] .gitignore: + compile_commands.json --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6abfb0de..f52f1311 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .cache # typical build directory build +# lsp: symlink to file in build directory (established manually) +compile_commands.json From 415c81b1814140b0cf1774a846f16f6f2cf59ed3 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 6 Oct 2023 23:41:26 -0400 Subject: [PATCH 04/30] README: formatting + example --- README.md | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c020ad6e..b0500c48 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,52 @@ # python bindings for c++ reflection library (xo-reflect) -### build + install +## build + install ``` $ cd xo-pyreflect $ mkdir build $ cd build $ INSTALL_PREFIX=/usr/local # or wherever you prefer, e.g. ~/local -$ cmake -DCMAKE_MODULE_PATH=${INSTALL_PREFIX}/share/cmake -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} .. +$ cmake \ + -DCMAKE_MODULE_PATH=${INSTALL_PREFIX}/share/cmake \ + -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} .. $ make $ make install ``` -### build for unit test coverage +## build for unit test coverage ``` $ cd xo-pyreflect $ mkdir build-ccov $ cd build-ccov -$ cmake -DCMAKE_MODULE_PATH=${INSTALL_PREFIX}/share/cmake -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} -DCODE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug .. +$ cmake \ + -DCMAKE_MODULE_PATH=${INSTALL_PREFIX}/share/cmake \ + -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \ + -DCODE_COVERAGE=ON \ + -DCMAKE_BUILD_TYPE=Debug .. ``` -### LSP support +## LSP (language server) support + +LSP looks for compile commands in the root of the source tree; +while Cmake creates them in the root of its build directory. + ``` $ cd xo-pyreflect -$ ln -s build/compile_commands.json # lsp will look for compile_commands.json in the root of the source tree +$ ln -s build/compile_commands.json # supply compile commands to LSP ``` + +## Examples + +Assumes `xo-pyreflect` installed to `~/local2/lib` + +``` +PYTHONPATH=~/local2/lib python +>>> import pyreflect +>>> dir(pyreflect) +['SelfTagging', 'TaggedRcptr', 'TypeDescr', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__'] +>>> pyreflect.TypeDescr.print_reflected_types() + +``` + +Not /immediately/ interesting: no reflected types in `pyreflect` itself From ac5534d8e2717e4241b9e66ba4ef42dcf373ce15 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 7 Oct 2023 16:03:39 -0400 Subject: [PATCH 05/30] build: use new xo_pybind11_dependency() --- README.md | 2 +- src/pyreflect/CMakeLists.txt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b0500c48..434a80a5 100644 --- a/README.md +++ b/README.md @@ -49,4 +49,4 @@ PYTHONPATH=~/local2/lib python ``` -Not /immediately/ interesting: no reflected types in `pyreflect` itself +Not _immediately_ interesting: no reflected types in `pyreflect` itself diff --git a/src/pyreflect/CMakeLists.txt b/src/pyreflect/CMakeLists.txt index 9b63978f..0579d761 100644 --- a/src/pyreflect/CMakeLists.txt +++ b/src/pyreflect/CMakeLists.txt @@ -8,4 +8,5 @@ set(SELF_SRCS pyreflect.cpp) xo_pybind11_library(${SELF_LIB} ${SELF_SRCS}) -xo_dependency(${SELF_LIB} reflect) +xo_pybind11_dependency(${SELF_LIB} reflect) + From 4246f336425a1730cb4bbab244594e94c1670922 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 17 Oct 2023 15:13:19 -0400 Subject: [PATCH 06/30] build: track xo-cmake streamlining --- CMakeLists.txt | 2 +- src/pyreflect/CMakeLists.txt | 4 ++-- src/pyreflect/pyreflect.cpp | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c372fd5..ccf4b129 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ add_subdirectory(src/pyreflect) # ---------------------------------------------------------------- # provide find_package() support -xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} pyreflectTargets) +xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) # ---------------------------------------------------------------- # install .hpp files diff --git a/src/pyreflect/CMakeLists.txt b/src/pyreflect/CMakeLists.txt index 0579d761..94a71814 100644 --- a/src/pyreflect/CMakeLists.txt +++ b/src/pyreflect/CMakeLists.txt @@ -1,4 +1,4 @@ -# xo_pyreflect/CMakeLists.txt +# xo_pyreflect/src/pyreflect/CMakeLists.txt set(SELF_LIB pyreflect) set(SELF_SRCS pyreflect.cpp) @@ -6,7 +6,7 @@ set(SELF_SRCS pyreflect.cpp) # ---------------------------------------------------------------- # pybind11 dep -xo_pybind11_library(${SELF_LIB} ${SELF_SRCS}) +xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS}) xo_pybind11_dependency(${SELF_LIB} reflect) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index 3a9f81bb..0b638658 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -26,7 +26,8 @@ namespace xo { //py::class_(m, "utc_nanos"); //py::class_(m, "TypeDescr"); - py::class_>(m, "TypeDescr") + py::class_>(m, "TypeDescr") .def_static("print_reflected_types", [](){ TypeDescrBase::print_reflected_types(std::cout); }) .def_property_readonly("canonical_name", &TypeDescrBase::canonical_name) From bc55885778898247204a3b2392ace02de95e24a2 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 17 Oct 2023 15:13:58 -0400 Subject: [PATCH 07/30] doc: README additions --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 434a80a5..7be07dd9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # python bindings for c++ reflection library (xo-reflect) -## build + install +## Getting Started + +### build + install dependencies + +- [github/Rconybea/xo-pyutil](https://github.com/Rconybea/xo-pyutil) +- [github/Rconybea/xo-reflect](https://github.com/Rconybea/xo-reflect) + +### build + install ``` $ cd xo-pyreflect $ mkdir build @@ -13,8 +20,9 @@ $ cmake \ $ make $ make install ``` +(also see .github/workflows/main.yml) -## build for unit test coverage +### build for unit test coverage ``` $ cd xo-pyreflect $ mkdir build-ccov @@ -26,7 +34,7 @@ $ cmake \ -DCMAKE_BUILD_TYPE=Debug .. ``` -## LSP (language server) support +### LSP (language server) support LSP looks for compile commands in the root of the source tree; while Cmake creates them in the root of its build directory. From a1f935579bf0674d974c3124ffb5d8647fbdc095 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 18 Oct 2023 12:36:12 -0400 Subject: [PATCH 08/30] github: + workflow --- .github/workflows/main.yml | 155 +++++++++++++++++++++++++++++ include/xo/pyreflect/pyreflect.hpp | 25 +++++ 2 files changed, 180 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 include/xo/pyreflect/pyreflect.hpp diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..289c7040 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,155 @@ +name: build xo-pyreflect + dependencies + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # You can convert this to a matrix build if you need cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest + + steps: + - name: checkout source + uses: actions/checkout@v3 + + - name: Install catch2 + # install catch2. see [[https://stackoverflow.com/questions/57982945/how-to-apt-get-install-in-a-github-actions-workflow]] + run: sudo apt-get install -y catch2 + + # ---------------------------------------------------------------- + + - name: Clone xo-cmake + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-cmake + path: repo/xo-cmake + + - name: Configure xo-cmake + run: cmake -B ${{github.workspace}}/build_xo-cmake -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/xo-cmake + + - name: Build xo-cmake (trivial) + run: cmake --build ${{github.workspace}}/build_xo-cmake --config ${{env.BUILD_TYPE}} + + - name: Install xo-cmake + run: cmake --install ${{github.workspace}}/build_xo-cmake + + # ---------------------------------------------------------------- + + - name: Clone indentlog + uses: actions/checkout@v3 + with: + repository: Rconybea/indentlog + path: repo/indentlog + + - name: Configure indentlog + # configure cmake for indentlog in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_indentlog -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/indentlog + + - name: Build indentlog + run: cmake --build ${{github.workspace}}/build_indentlog --config ${{env.BUILD_TYPE}} + + - name: Install indentlog + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_indentlog + + # ---------------------------------------------------------------- + + - name: Clone subsys + uses: actions/checkout@v3 + with: + repository: Rconybea/subsys + path: repo/subsys + + - name: Configure subsys + # configure cmake for subsys in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_subsys -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/subsys + + - name: Build subsys + run: cmake --build ${{github.workspace}}/build_subsys --config ${{env.BUILD_TYPE}} + + - name: Install subsys + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_subsys + + # ---------------------------------------------------------------- + + - name: Clone refcnt + uses: actions/checkout@v3 + with: + repository: Rconybea/refcnt + path: repo/refcnt + + - name: Configure refcnt + # configure cmake for refcnt in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_refcnt -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/refcnt + + - name: Build refcnt + run: cmake --build ${{github.workspace}}/build_refcnt --config ${{env.BUILD_TYPE}} + + - name: Install refcnt + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_refcnt + + # ---------------------------------------------------------------- + + - name: Clone reflect + uses: actions/checkout@v3 + with: + repository: Rconybea/reflect + path: repo/reflect + + - name: Configure reflect + # configure cmake for reflect in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_reflect -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/reflect + + - name: Build reflect + run: cmake --build ${{github.workspace}}/build_reflect --config ${{env.BUILD_TYPE}} + + - name: Install reflect + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_reflect + + # ---------------------------------------------------------------- + + - name: Clone pyutil + uses: actions/checkout@v3 + with: + repository: Rconybea/xo-pyutil + path: repo/pyutil + + - name: Configure pyutil + # configure cmake for pyutil in dedicated build directory. + run: cmake -B ${{github.workspace}}/build_pyutil -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local repo/pyutil + + - name: Build pyutil + run: cmake --build ${{github.workspace}}/build_pyutil --config ${{env.BUILD_TYPE}} + + - name: Install pyutil + # install into ${{github.workspace}}/local + run: cmake --install ${{github.workspace}}/build_pyutil + + # ---------------------------------------------------------------- + + - name: Configure self (pyreflect) + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/build_pyreflect -DCMAKE_MODULE_PATH=${{github.workspace}}/local/share/cmake -DCMAKE_PREFIX_PATH=${{github.workspace}}/local -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Build self (pyreflect) + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build_pyreflect --config ${{env.BUILD_TYPE}} + + - name: Test self (pyreflect) + working-directory: ${{github.workspace}}/build_pyreflect + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest -C ${{env.BUILD_TYPE}} diff --git a/include/xo/pyreflect/pyreflect.hpp b/include/xo/pyreflect/pyreflect.hpp new file mode 100644 index 00000000..bbaef729 --- /dev/null +++ b/include/xo/pyreflect/pyreflect.hpp @@ -0,0 +1,25 @@ +/* @file pyreflect.hpp + * + * automatically generated from src/xo_pyreflect/pyreflect.hpp.in + * see src/xo_pyreflect/CMakeLists.txt + */ + +/* python requires module name = library name + * example: + * PYBIND11_MODULE(PYREFLECT_MODULE_NAME(), m) { ... } + */ +#define PYREFLECT_MODULE_NAME() pyreflect + +/* example: + * py::module_::import(PYREFLECT_MODULE_NAME_STR) + */ +#define PYREFLECT_MODULE_NAME_STR "pyreflect" + +/* example: + * PYREFLECT_IMPORT_MODULE() + * replaces + * py::module_::import("pyreflect") + */ +#define PYREFLECT_IMPORT_MODULE() py::module_::import("pyreflect") + +/* end pyreflect.hpp */ From 758b883f0e73c257529984e679925427200b4ba4 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 18 Oct 2023 12:36:40 -0400 Subject: [PATCH 09/30] bugfix: remove generated .hpp file --- include/xo/pyreflect/pyreflect.hpp | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 include/xo/pyreflect/pyreflect.hpp diff --git a/include/xo/pyreflect/pyreflect.hpp b/include/xo/pyreflect/pyreflect.hpp deleted file mode 100644 index bbaef729..00000000 --- a/include/xo/pyreflect/pyreflect.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/* @file pyreflect.hpp - * - * automatically generated from src/xo_pyreflect/pyreflect.hpp.in - * see src/xo_pyreflect/CMakeLists.txt - */ - -/* python requires module name = library name - * example: - * PYBIND11_MODULE(PYREFLECT_MODULE_NAME(), m) { ... } - */ -#define PYREFLECT_MODULE_NAME() pyreflect - -/* example: - * py::module_::import(PYREFLECT_MODULE_NAME_STR) - */ -#define PYREFLECT_MODULE_NAME_STR "pyreflect" - -/* example: - * PYREFLECT_IMPORT_MODULE() - * replaces - * py::module_::import("pyreflect") - */ -#define PYREFLECT_IMPORT_MODULE() py::module_::import("pyreflect") - -/* end pyreflect.hpp */ From 711b0a580f74d3f69606f801a056a300b80852b8 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 18 Oct 2023 12:45:47 -0400 Subject: [PATCH 10/30] github: install pybind11-dev dep --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 289c7040..5d9c379b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,6 +25,9 @@ jobs: # install catch2. see [[https://stackoverflow.com/questions/57982945/how-to-apt-get-install-in-a-github-actions-workflow]] run: sudo apt-get install -y catch2 + - name: Install pybind11-dev + run: sudo apt-get install -y pybind11-dev + # ---------------------------------------------------------------- - name: Clone xo-cmake From 5f927717b67aa1521cd888a6d4ab391c88f6df41 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 18 Oct 2023 12:49:06 -0400 Subject: [PATCH 11/30] bugfix: compile fix to include path for generated pyreflect.hpp --- src/pyreflect/pyreflect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index 0b638658..c9b7f47a 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -1,7 +1,7 @@ /* @file pyreflect.cpp */ // note: need pyreflect/ here bc pyreflect.hpp is generated, located in build directory -#include "src/pyreflect/pyreflect.hpp" +#include "xo/pyreflect/pyreflect.hpp" #include "xo/reflect/TypeDescr.hpp" #include "xo/reflect/TaggedRcptr.hpp" #include "xo/reflect/SelfTagging.hpp" From 10856b2ed9c55633a6b28238b6490221f3cd7785 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 18 Oct 2023 13:39:08 -0400 Subject: [PATCH 12/30] bugfix: track modified path to generated include pyreflect.hpp --- src/pyreflect/pyreflect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index c9b7f47a..fc6e8fe8 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -1,7 +1,7 @@ /* @file pyreflect.cpp */ // note: need pyreflect/ here bc pyreflect.hpp is generated, located in build directory -#include "xo/pyreflect/pyreflect.hpp" +#include "pyreflect.hpp" #include "xo/reflect/TypeDescr.hpp" #include "xo/reflect/TaggedRcptr.hpp" #include "xo/reflect/SelfTagging.hpp" From 63d63f953f1cdcbb6ddab27ca181973721a953d1 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 18 Oct 2023 15:53:41 -0400 Subject: [PATCH 13/30] + include/README.md so git checkout creates dir --- include/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 include/README.md diff --git a/include/README.md b/include/README.md new file mode 100644 index 00000000..4454f162 --- /dev/null +++ b/include/README.md @@ -0,0 +1 @@ +placeholder for future pyreflect #include files From 729975b14559f8a70ac7b9cf96aa68d4d8f0a29c Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 20 Oct 2023 12:32:19 -0400 Subject: [PATCH 14/30] tidy: drop dead comments --- CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ccf4b129..b2e5ca94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,8 +43,3 @@ add_subdirectory(src/pyreflect) # provide find_package() support xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) - -# ---------------------------------------------------------------- -# install .hpp files - -#xo_install_include_tree() From 3194fb35f78c94cc825d90cc5f2c5122d9c49e2d Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 20 Oct 2023 12:34:06 -0400 Subject: [PATCH 15/30] fix include path for generated .hpp --- src/pyreflect/pyreflect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index fc6e8fe8..c9b7f47a 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -1,7 +1,7 @@ /* @file pyreflect.cpp */ // note: need pyreflect/ here bc pyreflect.hpp is generated, located in build directory -#include "pyreflect.hpp" +#include "xo/pyreflect/pyreflect.hpp" #include "xo/reflect/TypeDescr.hpp" #include "xo/reflect/TaggedRcptr.hpp" #include "xo/reflect/SelfTagging.hpp" From 74a23f1132b54155567a9629b19b17d4a9feb2d6 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 22 Oct 2023 14:55:32 -0400 Subject: [PATCH 16/30] pyreflect: + xo-pyutil dep --- src/pyreflect/CMakeLists.txt | 2 +- src/pyreflect/pyreflect.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pyreflect/CMakeLists.txt b/src/pyreflect/CMakeLists.txt index 94a71814..64be5e08 100644 --- a/src/pyreflect/CMakeLists.txt +++ b/src/pyreflect/CMakeLists.txt @@ -9,4 +9,4 @@ set(SELF_SRCS pyreflect.cpp) xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS}) xo_pybind11_dependency(${SELF_LIB} reflect) - +xo_pybind11_dependency(${SELF_LIB} xo_pyutil) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index c9b7f47a..fc6e8fe8 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -1,7 +1,7 @@ /* @file pyreflect.cpp */ // note: need pyreflect/ here bc pyreflect.hpp is generated, located in build directory -#include "xo/pyreflect/pyreflect.hpp" +#include "pyreflect.hpp" #include "xo/reflect/TypeDescr.hpp" #include "xo/reflect/TaggedRcptr.hpp" #include "xo/reflect/SelfTagging.hpp" From 098c979f2dfbc3ebce880f5ffdb874370d39dc04 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 22 Oct 2023 15:53:04 -0400 Subject: [PATCH 17/30] cmake target pyreflect -> xo_pyreflect --- src/pyreflect/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyreflect/CMakeLists.txt b/src/pyreflect/CMakeLists.txt index 64be5e08..d4acdbfa 100644 --- a/src/pyreflect/CMakeLists.txt +++ b/src/pyreflect/CMakeLists.txt @@ -1,6 +1,6 @@ # xo_pyreflect/src/pyreflect/CMakeLists.txt -set(SELF_LIB pyreflect) +set(SELF_LIB xo_pyreflect) set(SELF_SRCS pyreflect.cpp) # ---------------------------------------------------------------- From 484b2e9f0d3118dbfae826a2beaa9417b13df0c3 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 24 Oct 2023 20:36:44 -0400 Subject: [PATCH 18/30] cosmetic: drop unneeded comments --- src/pyreflect/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/pyreflect/CMakeLists.txt b/src/pyreflect/CMakeLists.txt index 94a71814..e53926d0 100644 --- a/src/pyreflect/CMakeLists.txt +++ b/src/pyreflect/CMakeLists.txt @@ -3,10 +3,5 @@ set(SELF_LIB pyreflect) set(SELF_SRCS pyreflect.cpp) -# ---------------------------------------------------------------- -# pybind11 dep - xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS}) - xo_pybind11_dependency(${SELF_LIB} reflect) - From fd279f0e38601c288451354cf5d052c7ce3d9c0f Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 15 Mar 2024 19:30:07 -0400 Subject: [PATCH 19/30] build: streamline CMAKE_MODULE_PATH interaction --- .gitignore | 2 +- CMakeLists.txt | 4 +--- README.md | 36 ++++++++++++++++++++++----------- cmake/xo-bootstrap-macros.cmake | 12 +++++++++++ 4 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 cmake/xo-bootstrap-macros.cmake diff --git a/.gitignore b/.gitignore index f52f1311..53a9c92f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # lsp keeps state here .cache # typical build directory -build +.build* # lsp: symlink to file in build directory (established manually) compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index b2e5ca94..5d84942e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,7 @@ cmake_minimum_required(VERSION 3.10) project(xo_pyreflect VERSION 0.1) enable_language(CXX) -# common XO cmake macros (see github.com:Rconybea/xo-cmake) -include(xo_macros/xo_cxx) -include(xo_macros/code-coverage) +include(cmake/xo-bootstrap-macros.cmake) # ---------------------------------------------------------------- # unit test setup diff --git a/README.md b/README.md index 7be07dd9..078e1a1b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# python bindings for c++ reflection library (xo-reflect) +# python bindings for c++ reflection library (xo-pyreflect) ## Getting Started @@ -22,6 +22,22 @@ $ make install ``` (also see .github/workflows/main.yml) +## Examples + +Assumes `xo-pyreflect` installed to `~/local2/lib` + +``` +PYTHONPATH=~/local2/lib python +>>> import xo_pyreflect +>>> dir(xo_pyreflect) +['SelfTagging', 'TaggedRcptr', 'TypeDescr', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__'] +>>> xo_pyreflect.TypeDescr.print_reflected_types() + +``` +(Not _immediately_ interesting: no reflected types in `pyreflect` itself) + +## Development + ### build for unit test coverage ``` $ cd xo-pyreflect @@ -37,24 +53,20 @@ $ cmake \ ### LSP (language server) support LSP looks for compile commands in the root of the source tree; -while Cmake creates them in the root of its build directory. +while `cmake` creates them in the root of its build directory. ``` $ cd xo-pyreflect $ ln -s build/compile_commands.json # supply compile commands to LSP ``` -## Examples +### display cmake variables -Assumes `xo-pyreflect` installed to `~/local2/lib` +- `-L` list variables +- `-A` include 'advanced' variables +- `-H` include help text ``` -PYTHONPATH=~/local2/lib python ->>> import pyreflect ->>> dir(pyreflect) -['SelfTagging', 'TaggedRcptr', 'TypeDescr', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__'] ->>> pyreflect.TypeDescr.print_reflected_types() - +$ cd xo-pyprintjson/build +$ cmake -LAH ``` - -Not _immediately_ interesting: no reflected types in `pyreflect` itself diff --git a/cmake/xo-bootstrap-macros.cmake b/cmake/xo-bootstrap-macros.cmake new file mode 100644 index 00000000..16644435 --- /dev/null +++ b/cmake/xo-bootstrap-macros.cmake @@ -0,0 +1,12 @@ +if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL "prefix")) + # default to typical install location for xo-project-macros + set(CMAKE_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/share/cmake) +endif() + +message("-- CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}") +message("-- CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") + +# needs to have been installed somewhere on CMAKE_MODULE_PATH, +# (e.g. from xo-cmake with the same value for CMAKE_INSTALL_PREFIX) +# +include(xo_macros/xo-project-macros) From 17d26aaf4efa1e772ea7961d09c297f3d4055234 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 29 Mar 2024 14:33:41 -0400 Subject: [PATCH 20/30] build: suppress bootstrap message in submodule build --- cmake/xo-bootstrap-macros.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/xo-bootstrap-macros.cmake b/cmake/xo-bootstrap-macros.cmake index 16644435..96592216 100644 --- a/cmake/xo-bootstrap-macros.cmake +++ b/cmake/xo-bootstrap-macros.cmake @@ -3,8 +3,10 @@ if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL "pr set(CMAKE_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/share/cmake) endif() -message("-- CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}") -message("-- CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") +if (NOT XO_SUBMODULE_BUILD) + message("-- CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}") + message("-- CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") +endif() # needs to have been installed somewhere on CMAKE_MODULE_PATH, # (e.g. from xo-cmake with the same value for CMAKE_INSTALL_PREFIX) From b128c9314d730781c026b17a1d857afd812a9a83 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 1 May 2024 14:34:47 -0400 Subject: [PATCH 21/30] xo-pyreflect: build: streamline using recent xo-cmake improvements --- CMakeLists.txt | 34 ++++++++++---------------------- cmake/xo-bootstrap-macros.cmake | 35 +++++++++++++++++++++++++++++++++ src/pyreflect/CMakeLists.txt | 3 --- src/pyreflect/pyreflect.cpp | 6 ++++++ 4 files changed, 51 insertions(+), 27 deletions(-) create mode 100644 cmake/xo-bootstrap-macros.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ccf4b129..cc36dfaa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,26 +3,19 @@ cmake_minimum_required(VERSION 3.10) project(xo_pyreflect VERSION 0.1) -enable_language(CXX) -# common XO cmake macros (see github.com:Rconybea/xo-cmake) -include(xo_macros/xo_cxx) -include(xo_macros/code-coverage) +include(GNUInstallDirs) +include(cmake/xo-bootstrap-macros.cmake) + +xo_cxx_toplevel_options2() # ---------------------------------------------------------------- -# unit test setup +# cmake -DCMAKE_BUILD_TYPE=coverage +xo_toplevel_coverage_config2() -enable_testing() -# activate code coverage for all executables + libraries (when configured with -DCODE_COVERAGE=ON) -add_code_coverage() -# 1. assuming that /nix/store/ prefixes .hpp files belonging to gcc, catch2 etc. -# we're not interested in code coverage for these sources. -# 2. exclude the utest/ subdir, we don't need coverage on the unit tests themselves; -# rather, want coverage on the code that the unit tests exercise. -# -# NOTE: this seems to work only with the 'ccov-all' target. In particular, doesn't seem to do anything with the 'ccov' target -# -add_code_coverage_all_targets(EXCLUDE /nix/store/* ${PROJECT_SOURCE_DIR}/utest/* ${PROJECT_BINARY_DIR}/local/* ${PROJECT_SOURCE_DIR}/repo/*) +# ---------------------------------------------------------------- +# cmake -DCMAKE_BUILD_TYPE=debug +xo_toplevel_debug_config2() # ---------------------------------------------------------------- # c++ settings (usually temporary) @@ -30,12 +23,8 @@ add_code_coverage_all_targets(EXCLUDE /nix/store/* ${PROJECT_SOURCE_DIR}/utest/* set(PROJECT_CXX_FLAGS "") add_definitions(${PROJECT_CXX_FLAGS}) -xo_toplevel_compile_options() - # ---------------------------------------------------------------- -# sources -# note: library=pyreflect (not xo_pyreflect) -> establishes pyreflectTargets add_subdirectory(src/pyreflect) #add_subdirectory(utest) @@ -44,7 +33,4 @@ add_subdirectory(src/pyreflect) xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) -# ---------------------------------------------------------------- -# install .hpp files - -#xo_install_include_tree() +# end CMakeLists.txt diff --git a/cmake/xo-bootstrap-macros.cmake b/cmake/xo-bootstrap-macros.cmake new file mode 100644 index 00000000..aba31169 --- /dev/null +++ b/cmake/xo-bootstrap-macros.cmake @@ -0,0 +1,35 @@ +# ---------------------------------------------------------------- +# for example: +# $ PREFIX=/usr/local # for example +# $ cmake -DCMAKE_MODULE_PATH=prefix -DCMAKE_INSTALL_PREFIX=$PREFIX -B .build +# +# will get +# CMAKE_MODULE_PATH +# from xo-cmake-config --cmake-module-path +# +# and expect .cmake macros in +# CMAKE_MODULE_PATH/xo_macros/xo_cxx.cmake +# ---------------------------------------------------------------- + +find_program(XO_CMAKE_CONFIG_EXECUTABLE NAMES xo-cmake-config REQUIRED) + +if ("${XO_CMAKE_CONFIG_EXECUTABLE}" STREQUAL "XO_CMAKE_CONFIG_EXECUTABLE-NOT_FOUND") + message(FATAL "could not find xo-cmake-config executable") +endif() + +message(STATUS "XO_CMAKE_CONFIG_EXECUTABLE=${XO_CMAKE_CONFIG_EXECUTABLE}") + +if (NOT XO_SUBMODULE_BUILD) + if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL prefix)) + # default to typical install location for xo-project-macros + execute_process(COMMAND ${XO_CMAKE_CONFIG_EXECUTABLE} --cmake-module-path OUTPUT_VARIABLE CMAKE_MODULE_PATH) + message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") + endif() +endif() + +# needs to have been installed somewhere on CMAKE_MODULE_PATH, +# (e.g. from xo-cmake with the same value for CMAKE_INSTALL_PREFIX) +# +include(xo_macros/xo_cxx) + +xo_cxx_bootstrap_message() diff --git a/src/pyreflect/CMakeLists.txt b/src/pyreflect/CMakeLists.txt index 94a71814..2bf242df 100644 --- a/src/pyreflect/CMakeLists.txt +++ b/src/pyreflect/CMakeLists.txt @@ -4,9 +4,6 @@ set(SELF_LIB pyreflect) set(SELF_SRCS pyreflect.cpp) # ---------------------------------------------------------------- -# pybind11 dep xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS}) - xo_pybind11_dependency(${SELF_LIB} reflect) - diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index fc6e8fe8..503635ed 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -26,6 +26,12 @@ namespace xo { //py::class_(m, "utc_nanos"); //py::class_(m, "TypeDescr"); + /* TypeDescrBase instances are created automatically at library load time + * by static initializers. The reflection library (xo-reflect) is responsible + * for lifetime of TypeDescrobjects. Under no circumstances should python + * (or pybind11) directly destroy a TypeDescrImpl instance, hence use of + * unowned_ptr here. + */ py::class_>(m, "TypeDescr") .def_static("print_reflected_types", From e02ce241ecc0f0e9be4cd92a63eeaf48ff8b22d4 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 1 May 2024 14:35:31 -0400 Subject: [PATCH 22/30] xo-pyreflect: ++ .gitignore .build dirs --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f52f1311..53a9c92f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # lsp keeps state here .cache # typical build directory -build +.build* # lsp: symlink to file in build directory (established manually) compile_commands.json From af8b0d4a4675a708678a2c594027b2452b0955b7 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 19 Jun 2024 10:55:57 -0400 Subject: [PATCH 23/30] xo-pyreflect: build: streamline cmake --- CMakeLists.txt | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d84942e..427a56b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,22 +5,10 @@ cmake_minimum_required(VERSION 3.10) project(xo_pyreflect VERSION 0.1) enable_language(CXX) +include(GNUInstallDirs) include(cmake/xo-bootstrap-macros.cmake) -# ---------------------------------------------------------------- -# unit test setup - -enable_testing() -# activate code coverage for all executables + libraries (when configured with -DCODE_COVERAGE=ON) -add_code_coverage() -# 1. assuming that /nix/store/ prefixes .hpp files belonging to gcc, catch2 etc. -# we're not interested in code coverage for these sources. -# 2. exclude the utest/ subdir, we don't need coverage on the unit tests themselves; -# rather, want coverage on the code that the unit tests exercise. -# -# NOTE: this seems to work only with the 'ccov-all' target. In particular, doesn't seem to do anything with the 'ccov' target -# -add_code_coverage_all_targets(EXCLUDE /nix/store/* ${PROJECT_SOURCE_DIR}/utest/* ${PROJECT_BINARY_DIR}/local/* ${PROJECT_SOURCE_DIR}/repo/*) +xo_cxx_toplevel_options3() # ---------------------------------------------------------------- # c++ settings (usually temporary) @@ -28,8 +16,6 @@ add_code_coverage_all_targets(EXCLUDE /nix/store/* ${PROJECT_SOURCE_DIR}/utest/* set(PROJECT_CXX_FLAGS "") add_definitions(${PROJECT_CXX_FLAGS}) -xo_toplevel_compile_options() - # ---------------------------------------------------------------- # sources From 00025a66e43416b907dc66c6de0a4c2af4e5ba55 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 19 Jun 2024 10:56:29 -0400 Subject: [PATCH 24/30] xo-pyreflect: + TypeDescr.lookup_by_name() --- src/pyreflect/pyreflect.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index fc6e8fe8..f93b4634 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -28,6 +28,8 @@ namespace xo { //py::class_(m, "TypeDescr"); py::class_>(m, "TypeDescr") + + .def_static("lookup_by_name", &TypeDescrBase::lookup_by_name) .def_static("print_reflected_types", [](){ TypeDescrBase::print_reflected_types(std::cout); }) .def_property_readonly("canonical_name", &TypeDescrBase::canonical_name) From 50d3d32fc3a5900c3c8b516e6a38bb3d2b99f940 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 19 Jun 2024 10:56:53 -0400 Subject: [PATCH 25/30] xo-pyreflect: + TypeDescr.short_name --- src/pyreflect/pyreflect.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index f93b4634..9447a4cd 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -33,6 +33,7 @@ namespace xo { .def_static("print_reflected_types", [](){ TypeDescrBase::print_reflected_types(std::cout); }) .def_property_readonly("canonical_name", &TypeDescrBase::canonical_name) + .def_property_readonly("short_name", &TypeDescrBase::short_name) .def("__repr__", &TypeDescrBase::display_string); /* note: this means python will use From e57ba44ae72b4f2218b1a6fad249479bc5cca521 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 19 Jun 2024 10:57:14 -0400 Subject: [PATCH 26/30] xo-pyreflect: + TypeDescr.complete_flag --- src/pyreflect/pyreflect.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index 9447a4cd..cf65d3d1 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -34,6 +34,7 @@ namespace xo { [](){ TypeDescrBase::print_reflected_types(std::cout); }) .def_property_readonly("canonical_name", &TypeDescrBase::canonical_name) .def_property_readonly("short_name", &TypeDescrBase::short_name) + .def_property_readonly("complete_flag", &TypeDescrBase::complete_flag) .def("__repr__", &TypeDescrBase::display_string); /* note: this means python will use From bd8c2c4e13fa96efd0bfe6a826b42390c0c19d34 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 19 Jun 2024 10:57:40 -0400 Subject: [PATCH 27/30] xo-pyreflect: bind Metatype; + TypeDescr.metatype --- src/pyreflect/pyreflect.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index cf65d3d1..a77993a5 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -22,6 +22,17 @@ namespace xo { namespace reflect { PYBIND11_MODULE(PYREFLECT_MODULE_NAME(), m) { + m.doc() = "pybind11 plugin for xo-reflect"; + + py::enum_(m, "Metatype") + .value("invalid", Metatype::mt_invalid) + .value("atomic", Metatype::mt_atomic) + .value("pointer", Metatype::mt_pointer) + .value("vector", Metatype::mt_vector) + .value("struct", Metatype::mt_struct) + .value("function", Metatype::mt_function) + ; + /* note: possibly move this to pytime/ if/when we provide it */ //py::class_(m, "utc_nanos"); @@ -32,8 +43,10 @@ namespace xo { .def_static("lookup_by_name", &TypeDescrBase::lookup_by_name) .def_static("print_reflected_types", [](){ TypeDescrBase::print_reflected_types(std::cout); }) + .def_property_readonly("canonical_name", &TypeDescrBase::canonical_name) .def_property_readonly("short_name", &TypeDescrBase::short_name) + .def_property_readonly("metatype", &TypeDescrBase::metatype) .def_property_readonly("complete_flag", &TypeDescrBase::complete_flag) .def("__repr__", &TypeDescrBase::display_string); From 76f5e4cacabc26ef72d652f0735cb0a3f1f43904 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 19 Jun 2024 10:58:26 -0400 Subject: [PATCH 28/30] xo-preflect: ++ .gitignore (+ .projectile file) --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 53a9c92f..2d66a655 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# emacs workspace config +.projectile # lsp keeps state here .cache # typical build directory From c3115779979a08c221ff61cf6bb8f20e94b8b1a9 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 14 Sep 2024 11:55:10 -0500 Subject: [PATCH 29/30] xo-pyreflect: bugfix: track ns change xo::ref::rp -> xo::rp --- src/pyreflect/pyreflect.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index ac5ef86e..846e8cba 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -16,7 +16,6 @@ namespace xo { using xo::time::utc_nanos; using xo::ref::unowned_ptr; - using xo::ref::rp; namespace py = pybind11; namespace reflect { From b361811b976568c0736827b323e1b154a4cdda3d Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 2 May 2025 19:21:17 -0500 Subject: [PATCH 30/30] bugfix: compiler nit --- src/pyreflect/pyreflect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index 503635ed..35b971a3 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -16,7 +16,7 @@ namespace xo { using xo::time::utc_nanos; using xo::ref::unowned_ptr; - using xo::ref::rp; + using xo::rp; namespace py = pybind11; namespace reflect {