一个完全开源的,有力的解决方案,用于修改和生成C ++源代码。减少C ++项目中的样板代码量。
此存储库将尽快迁移到https://github.com/blockspacer/flextool
CXXCTP将被弃用。喜欢Flextool
CXXCTP是一种跨副本,可扩展C ++以进行新的内省,反射和编译时间执行。
CXXCTP并非旨在创建预定义的源代码转换集。用户可以共享C ++脚本以进行源代码转换。
假设有人在开源社区共享了有用的脚本interface.cxx和enum_to_json.cxx 。您只需将它们放入ctp_scripts文件夹中,就可以在项目中使用它们。
元编程是编写程序的“艺术”,以将其他程序视为其数据。这意味着程序可以生成,读取,分析和转换代码甚至自身以实现某个解决方案。
注意:该项目是按原样提供的,无需任何保修(请参阅许可证)。
您为什么不只是扩展Clang,因为它还提供了一些实验功能(例如模块)?
Clang是一个编译器,而该项目是一个转板器,它将代码转换为标准化的C ++代码,而无需修改LLVM/组件。
由于该工具的输出是C ++代码,因此您可以使用Emscripten编译转移代码,使用静态代码分析仪,运行代码在Cring等。
CXXCTP允许您创建和共享脚本
在开发中,请参见示例。当前仅支持Linux。
请注意,您可以在Windows/Mac/等下运行Linux容器。
// usage example from ReflShapeKind.hpp
enum class
$apply(
reflect_enum
)
ReflShapeKind0 : uint32_t {
Box = 3 ,
Sphere = 6 ,
}; // Usage example. NOTE: no inheritance & definition outside lib.
// in lib .h
struct drawable {
virtual void draw ( const char * arg1) const noexcept = 0;
};
struct printable {
virtual void print ( const char * arg1, const char * arg2) const noexcept = 0;
};
struct canvas3D {
std::string name3D;
};
struct canvas4D {
std::string name4D;
};
// in app .cpp
void draw<drawable>( const canvas3D& data, const char * arg1){
std::cout << " drawing to canvas3D name = " << data. name3D << std::endl;
}
void draw<drawable>( const canvas4D& data, const char * arg1){
std::cout << " drawing to canvas4D name = " << data. name4D << std::endl;
}
void print<printable>( const canvas3D& data, const char * arg1, const char * arg2){
std::cout << " printing to canvas3D name = " << data. name3D << std::endl;
}
void print<printable>( const canvas4D& data, const char * arg1, const char * arg2){
std::cout << " printing to canvas4D name = " << data. name4D << std::endl;
}
std::vector< _tc_combined_t <drawable>> vec {
canvas3D{},
canvas4D{},
};
_tc_combined_t <drawable, printable> CVS = canvas4D{};
CVS.draw( " " );
CVS.print( " " , " " );
canvas3D cvs3D;
CVS = std::move(cvs3D);
canvas4D cvs4D;
CVS = cvs4D; // copy
CVS = vec.at( 0 ); // <drawable> to <drawable, printable>$ export (
static int resultSomeInt = 2345 ;
)
$eval( " #include <optional> " )
$exec(
printf ( " execkjljlk n " );
printf ( " execasdasd n " );
)
$set_embed( " set_embed103 " ,
printf ( " set_embed101 n " );
printf ( " set_embed102 n " );
)
$embed(
[&clangMatchResult, &clangRewriter, &clangDecl]() {
printf ( " embed01 n " );
printf ( " embed02 n " );
return new llvm::Optional<std::string>{ " embed03 " };
}();
) class
$apply(make_interface;make_removefuncbody;make_reflect)
SomeInterfaceName {
virtual ~SomeInterfaceName () = 0 ;
/* int f ( ) { // {}
int i = 6;
{
// {
// }
}
return i;
}; */
int foo ();
virtual void foobar ( int & arg1) = 0 ;
virtual inline void zoobar ( int & arg2);
// int m_bar;
// int m_bar2 = 2;
};git submodule sync --recursive
git fetch --recurse-submodules
git submodule update --init --recursive --depth 100 --progress
# or
git submodule update --force --recursive --init --remote安装和配置docker:https://medium.com/@saniaky/configure-docker-to-use-a-host-proxy-e88bd988888888c0aa
克隆代码(如上)和cd中的克隆DIR。
注意:您可能需要使用--build-arg NO_SSL="False"构建Docker映像。在Dockerfile中阅读评论。
# Give docker the rights to access X-server
sudo -E xhost +local:docker
# build Dockerfile
sudo -E docker build --no-cache
--build-arg GIT_WITH_OPENSSL= " "
--build-arg NO_SSL= " False "
-t cpp-docker-cxxctp .
# Now let’s check if our image has been created.
sudo -E docker images
# Run in container without leaving host terminal
sudo -E docker run -v " $PWD " :/home/u/cxxctp -w /home/u/cxxctp cpp-docker-cxxctp CXXCTP_tool -version --version
# Run a terminal in container
sudo -E docker run --rm -v " $PWD " :/home/u/cxxctp -w /home/u/cxxctp -it -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix cpp-docker-cxxctp
# type in container terminal
CXXCTP_tool -version --version # Run a terminal in container
sudo -E docker run --rm -v " $PWD " :/home/u/cxxctp -w /home/u/cxxctp -it -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix cpp-docker-cxxctp
# An example of how to build (with Makefile generated from cmake) inside the container
# Mounts $PWD to /home/u/cxxctp and runs command
mkdir build
sudo -E docker run --rm -v " $PWD " :/home/u/cxxctp -w /home/u/cxxctp/build cpp-docker-cxxctp cmake -DCONAN_AUTO_INSTALL=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE ..
# Run resulting app in host OS:
# ./build/<app> pip install --index-url=https://pypi.python.org/simple/ --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org wheel
&&
pip install --index-url=https://pypi.python.org/simple/ --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org virtualenv
&&
pip install --index-url=https://pypi.python.org/simple/ --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org conan
&&
pip install --index-url=https://pypi.python.org/simple/ --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org conan_package_tools
conan profile new default --detect
# conan profile update settings.compiler.libcxx=libstdc++11 default
conan remote list
conan search * boost * -r all ~/.conan/conan.conf中配置代理和cacert_path,请参阅https://docs.conan.io/en/latest/reference/config_files/config_files/conan.conf.html#proxies
配置Conan Clang配置文件,然后使用-Profile Clang:
/usr/bin/clang-6.0 -v
/usr/bin/clang++-6.0 -v
nano ~ /.conan/profiles/clang
[settings]
# We are building in Ubuntu Linux
os_build=Linux
os=Linux
arch_build=x86_64
arch=x86_64
compiler=clang
compiler.version=6.0
compiler.libcxx=libstdc++11
[env]
CC=/usr/bin/clang-6.0
CXX=/usr/bin/clang++-6.0然后conan install ***** --profile clang
/usr/bin/gcc -v
/usr/bin/g++ -v
nano ~ /.conan/profiles/gcc
[settings]
# We are building in Ubuntu Linux
os_build=Linux
os=Linux
arch_build=x86_64
arch=x86_64
compiler=gcc
compiler.version=7
compiler.libcxx=libstdc++11
[env]
CC=/usr/bin/gcc
CXX=/usr/bin/g++如果您想禁用SSL(在代理下等):
# see https://docs.conan.io/en/latest/reference/commands/misc/remote.html#conan-remote
conan remote update conan-center https://conan.bintray.com False
conan search boost * -r=conan-center
conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan
conan remote update bincrafters https://api.bintray.com/conan/bincrafters/public-conan False
conan search boost * -r=bincrafters如果要设置Corp。卡塞特:
CONAN_CACERT_PATH=/path/to/ca-bundle.crt
file $CONAN_CACERT_PATH有用的链接:
为了添加依赖项遥控器列表,请键入以下命令:
cmake -E time conan config install conan/remotes/
# OR:
# cmake -E time conan config install conan/remotes_disabled_ssl/ # NOTE: don't forget to re-run `conan install` after command below
# NOTE: change `build_type=Debug` to `build_type=Release` in production
cmake -DEXTRA_CONAN_OPTS= " --profile;clang;-s;build_type=Debug;--build;missing " -P tools/buildConanThirdparty.cmakeconan remote add Manu343726 https://api.bintray.com/conan/manu343726/conan-packages False
git clone http://github.com/foonathan/type_safe.git -b v0.2.1
cd type_safe
# NOTE: change `build_type=Debug` to `build_type=Release` in production
CONAN_REVISIONS_ENABLED=1
CONAN_VERBOSE_TRACEBACK=1
CONAN_PRINT_RUN_COMMANDS=1
CONAN_LOGGING_LEVEL=10
GIT_SSL_NO_VERIFY=true
conan create . conan/stable -s build_type=Debug --profile clang --build missing # NOTE: change `build_type=Debug` to `build_type=Release` in production
git clone http://github.com/mosra/corrade.git && cd corrade
CONAN_REVISIONS_ENABLED=1
CONAN_VERBOSE_TRACEBACK=1
CONAN_PRINT_RUN_COMMANDS=1
CONAN_LOGGING_LEVEL=10
GIT_SSL_NO_VERIFY=true
conan create . magnum/stable -s build_type=Debug --profile clang --build missing -tf package/conan/test_packagesudo apt-get install openmpi-bin openmpi-common libopenmpi-devsudo -E apt-get purge -y cmake
bash scripts/install_cmake.sh安装CXTPL库https://github.com/blockspacer/cxtpl
安装cxtpl_tool https://github.com/blockspacer/cxtpl#how-to-build
BEFORE install_cling.sh:
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install clang-6.0 libstdc++6 libstdc++-6-dev
sudo update-alternatives --config c++
sudo update-alternatives --config cc
sudo ldconfig
export CC=clang-6.0
export CXX=clang++-6.0 # Build Cling into `cling-build` folder
cd scripts
bash install_cling.sh如CXTPL https://github.com/blockspacer/cxtpl#how-to-build中的安装deps
export CC=clang-6.0
export CXX=clang++-6.0
cmake -E remove_directory build
cmake -E make_directory build
cmake -E remove_directory resources/cxtpl/generated
cmake -E make_directory resources/cxtpl/generated
# NOTE: change `build_type=Debug` to `build_type=Release` in production
CONAN_REVISIONS_ENABLED=1
CONAN_VERBOSE_TRACEBACK=1
CONAN_PRINT_RUN_COMMANDS=1
CONAN_LOGGING_LEVEL=10
GIT_SSL_NO_VERIFY=true
cmake -E chdir build
cmake -E time
conan install
-s build_type=Debug
--build=missing
--profile clang
-o enable_tests=False
-o openssl:shared=True
..
cmake -E chdir build cmake -E time cmake -DCONAN_AUTO_INSTALL=OFF -DENABLE_CLING=TRUE -DBUILD_SHARED_LIBS=FALSE -DBUILD_EXAMPLES=FALSE -DALLOW_PER_PROJECT_CTP_SCRIPTS=TRUE -DBUNDLE_EXAMPLE_SCRIPTS=FALSE -DCMAKE_BUILD_TYPE=Debug -DENABLE_CXXCTP=TRUE ..
cmake -E chdir build cmake -E time cmake --build . -- -j6
# you can install CXXCTP_tool:
sudo cmake -E chdir build make install
# NOTE: You can also use the “-p” flag with CMAKE_EXPORT_COMPILE_COMMANDS. See https://variousburglarious.com/2018/02/18/include-paths-for-clang-tools/
# cmake -E chdir build ./tool/CXXCTP_tool -p=../example_compile_commands/
# NOTE: runs CXXCTP_tool on multiple files and adds include paths by `-extra-arg=-I`
cmake -E chdir build ./tool/CXXCTP_tool -L .=DBG9 -extra-arg=-I $PWD /include -extra-arg=-I../resources ../examples/built_in/for_codegen/example_make_reflect.cpp
# check generator output
file build/example_make_reflect.cpp.generated.cpp或在GDB下:
rm -rf * generated * ; clear && clear ; gdb ./CXXCTP -ex " run " -ex " bt " -ex " q " 使用共享的cxxctp_core作为共享库-DBUILD_SHARED_LIBS=TRUE 。
从https://github.com/blockspacer/cxtpl或手动手动forly for clang支持(替换folly_use_jemalloc用folly_assume_no_jemalloc)运行bash脚本/install_folly.sh。
在构建和-DENABLE_CLING=TRUE之前,请使用clang(不是GCC!)
export CC=clang-6.0
export CXX=clang++-6.0
sudo rm -rf examples/ * /ctp_scripts/ * / * /generated/
cmake -E remove_directory build
cmake -E make_directory build
cmake -E remove_directory resources/cxtpl/generated
cmake -E make_directory resources/cxtpl/generated
# NOTE: clang profile!
# NOTE: change `build_type=Debug` to `build_type=Release` in production
CONAN_REVISIONS_ENABLED=1
CONAN_VERBOSE_TRACEBACK=1
CONAN_PRINT_RUN_COMMANDS=1
CONAN_LOGGING_LEVEL=10
GIT_SSL_NO_VERIFY=true
cmake -E chdir build
cmake -E time
conan install
-s build_type=Debug
--build=missing
--profile clang
-o enable_tests=False
-o openssl:shared=True
..
cmake -E chdir build cmake -E time cmake -DCONAN_AUTO_INSTALL=OFF -DENABLE_CLING=TRUE -DBUILD_SHARED_LIBS=TRUE -DALLOW_PER_PROJECT_CTP_SCRIPTS=TRUE -DBUILD_EXAMPLES=FALSE -DBUNDLE_EXAMPLE_SCRIPTS=FALSE -DCLEAN_CXXCTP_GEN=TRUE -DCMAKE_BUILD_TYPE=Debug -DENABLE_CXXCTP=TRUE ..
# OR cmake -E chdir build cmake -E time cmake -DCONAN_AUTO_INSTALL=OFF -DENABLE_CLING=TRUE -DBUILD_SHARED_LIBS=TRUE -DALLOW_PER_PROJECT_CTP_SCRIPTS=FALSE -DBUILD_EXAMPLES=FALSE -DBUNDLE_EXAMPLE_SCRIPTS=TRUE -DCLEAN_CXXCTP_GEN=TRUE -DCMAKE_BUILD_TYPE=Debug -DENABLE_CXXCTP=TRUE ..
cmake -E chdir build cmake -E time cmake --build . -- -j6
# you can install CXXCTP_tool:
sudo cmake -E chdir build make install
# check supported plugins
/usr/local/bin/CXXCTP_tool --plugins如果您安装了cxxctp_tool-可以运行示例:
# requires CXXCTP_tool
sudo cmake -E chdir build make install
# use -DBUILD_EXAMPLES=TRUE
rm ./build/examples/simple/CXXCTP_tool_for_CXXCTP_example.log
cmake -E chdir build cmake -E time cmake -DCONAN_AUTO_INSTALL=OFF -DENABLE_CLING=TRUE -DBUILD_SHARED_LIBS=TRUE -DBUILD_EXAMPLES=TRUE -DBUNDLE_EXAMPLE_SCRIPTS=FALSE -DALLOW_PER_PROJECT_CTP_SCRIPTS=TRUE -DCMAKE_BUILD_TYPE=Debug -DENABLE_CXXCTP=TRUE ..
cmake -E chdir build cmake -E time cmake --build . -- -j6
cat ./build/examples/simple/CXXCTP_tool_for_CXXCTP_example.log
Check that ` .log ` find doesn ` t contain errors
# run examples
build/bin/CXXCTP_example不要忘记设置cring包括-extra-arg=-I$PWD/include和库路径,包括-extra-arg=-L$PWD/build和.so/.dll libs by -extra-arg=-lCXXCTP_core :
# NOTE: runs CXXCTP_tool on multiple files and adds include paths by `-extra-arg=-I`
cmake -E chdir build ./tool/CXXCTP_tool --ctp_scripts_paths= $PWD -L .=DBG9 -extra-arg=-I $PWD /include -extra-arg=-L $PWD /build -extra-arg=-lCXXCTP_core -extra-arg=-I../resources ../resources/ReflShapeKind.hpp ../resources/test_typeclass_base1.hpp ../resources/test_typeclass_instance1.hpp ../resources/test.cpp使用-extra-arg选项CXXCTP_tool :
-extra-arg=-I $PWD /include -extra-arg=-I $PWD /include/foo -extra-arg=-DMY_DEFINITION=1 -extra-arg=-DONE_MORE_DEFINITION=1例子:
cmake -E chdir build ./tool/CXXCTP_tool --ctp_scripts_paths= $PWD -L .=DBG9 -extra-arg=-I $PWD /include -extra-arg=-I../resources ../resources/ReflShapeKind.hpp ../resources/test_typeclass_base1.hpp ../resources/test_typeclass_instance1.hpp ../resources/test.cpp以下各节涵盖了CXXCTP的使用,自定义规则和调试。
您可以编写自定义C ++脚本以进行源代码转换或使用现有的脚本。
CXXCTP按词典顺序加载来自CTP_Scripts文件夹的所有C ++脚本。
ctp_script的示例内容:
utils必须在脚本之前加载(相关),因此我们在文件夹名称之前添加了1_ , 2_ ,...(请参见上文)。
您可以在C ++脚本中使用#include ,使用文件系统,访问Internet等。
目录`
安装-DENABLE_CLING=TRUE -DINSTALL_CLING=TRUE并设置LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/lib/: $LD_LIBRARY_PATH
sudo ldconfig您可以使用C ++注释来告诉CXXCTP它必须执行什么操作。
假设我们想将类变成界面:
// Source
class SomeInterfaceName {
int foo1 () {
// ...
};
int foo ();
virtual void foobar ( int & arg1) = 0;
virtual void zoobar ( int & arg2);
virtual ~SomeInterfaceName () = 0 ;
};
// <== will be changed into ==>
// Result
class SomeInterfaceName {
virtual int foo1 () = 0;
virtual int foo () = 0;
virtual void foobar ( int & arg1) = 0;
virtual void zoobar ( int & arg2) = 0;
virtual ~SomeInterfaceName () = 0 ;
};我们可以使用funccall操作来运行C ++脚本进行源代码转换。让我们假设脚本名称为make_interface和make_removefuncbody (按照您需要的名称)。
__attribute__ ((annotate( " {gen};{funccall};make_interface;make_removefuncbody " ))) {gen}; - 每个CXXCTP注释中使用的关键字。
{funccall}; - 用于告诉CXXCTP的关键字必须用包裹执行C ++脚本。
make_interface;make_removefuncbody两个脚本CXXCTP将执行什么。
脚本将从左侧( make_interface )执行到右( make_removefuncbody )。
通常,您不需要编写长长的C ++注释,只需使用C ++ #define (或包含具有常见定义的内置标题):
# define $apply(...)
__attribute__ ((annotate( " {gen};{funccall}; " #__VA_ARGS__)))
class
$apply(make_interface;
make_removefuncbody)
SomeInterfaceName {
virtual ~SomeInterfaceName () = 0 ;
int foo ();
virtual void foobar ( int & arg1) = 0 ;
virtual void zoobar ( int & arg2);
};使用类似的方法,您可以将多个源代码转换步骤应用于同一class / struct /等。
在ctp_scripts中使用您的函数创建文件
复制custom_plugins.cmake.example为custom_plugins.cmake
通过add_ctp_plugin将脚本路径附加到custom_plugins.cmake :
# first arg - typeclass_instance - script function name
# second arg - script source file
# third arg - script header file
# last arg - path to CMakeLists.txt used to generate script-related files
add_ctp_plugin(
" typeclass_instance "
${CMAKE_CURRENT_SOURCE_DIR} /examples/simple/ctp_scripts/2_scripts/typeclass_instance/typeclass_instance.cpp
${CMAKE_CURRENT_SOURCE_DIR} /examples/simple/ctp_scripts/2_scripts/typeclass_instance/typeclass_instance.hpp
${CMAKE_CURRENT_SOURCE_DIR} /examples/simple/ctp_scripts/2_scripts/typeclass_instance
)检查您的函数名称是否存在于生成的文件ctp_registry.cpp中(可以在cring / dev mode中跳过)
代码转换的功能签名必须与cxxctp_callback兼容:
typedef std::function< const char *(
const cxxctp::parsed_func& func_with_args,
const clang::ast_matchers::MatchFinder::MatchResult& matchResult,
clang::Rewriter& rewriter,
const clang::Decl* decl,
const std::vector<cxxctp::parsed_func>& all_funcs_with_args)> cxxctp_callback;详细功能签名:
all_funcs_with_args执行的功能(请参见下文)parsed_func interface和foo_with_args 。将功能名称视为__VA_ARGS__
# define $apply(...)
__attribute__ ((annotate( " {gen};{funccall}; " #__VA_ARGS__)))示例make_interface和make_removefuncbody两个函数名称:
$apply(make_interface;
make_removefuncbody)如果您需要代码生成:
.cxtpl )。使用cxtpl_tool https://github.com/blockspacer/cxtpl构建文件std::string cxtpl_output ,它将存储使用一些参数的模板渲染的结果。.cxtpl )中包含文件生成。 .cxtpl .cxtpl是C ++模板引擎的文件扩展名https://github.com/blockspacer/cxtpl
.cxtpl (cmake)将.cxtpl文件添加到Codegen_files.cmake中
注意:在DEV模式(例如Cring模式)中,最好使用CXTPL_TOOL https://github.com/blockspacer/cxtpl生成模板文件,您可以将生成规则添加到Codegen_files.cmake中。
注意:不要忘记为.cxtpl和.cxtpl.h文件提供共享代码规则(添加到版本控制系统)。
.cxtpl您有两个选择:
.cxtpl生成文件,然后将其包含在C ++脚本中。类似于编译时间,但是您可以重新生成或更改文件而无需计划重新编译。请注意,可以生成文件并将其包含在脚本中;只需将脚本分为多个倍数。.cxtpl生成一个字符串,然后将其运行在单独的固定解释器中。在大多数情况下,您将使用第一个选项。 .cxtpl将反射数据传递到模板引擎。
使用cxtpl_tool https://github.com/blockspacer/cxtpl从模板中生成文件
在CXXCTP脚本( .cpp )中:
// see ReflectAST.cpp
reflection::NamespacesTree m_namespaces;
// `node` from AST parser (libtooling)
reflection::ClassInfoPtr structInfo = reflector.ReflectClass(node, &m_namespaces);
// ...
stuct Arguments {
// any custom arguments here ...
std::string arg1 = " arg1... " ;
std::string arg2 = " arg2... " ;
// reflection data here (ClassInfoPtr) ...
};
// ...
std::map<std::string, std::any> cxtpl_params;
{
cxtpl_params[ " Arguments " ] =
std::make_any<Arguments>(Arguments{});
cxtpl_params[ " generator_path " ] =
std::make_any<std::string>( " enum_gen_hpp.cxtpl " );
cxtpl_params[ " generator_includes " ] =
std::make_any<std::vector<std::string>>(
std::vector<std::string>{});
std::string cxtpl_output;
# include " ../../resources/cxtpl/generated/enum_gen_hpp.cxtpl.cpp "
writeToFile (cxtpl_output, gen_hpp_name);
}在.cxtpl模板:
const auto arguments = std::any_cast<Arguments>(cxtpl_params.at( " Arguments " ));
std::cout << arguments.arg1;作为示例,请参见resources/cxtpl/enum_gen_hpp.cxtpl 。
cxxctp_tool包装libtooling添加自定义命令行选项。
与libtooling有关的选项(类型-HELP或-HELP):
Generic Options:
-help - Display available options (-help-hidden for more)
-help-list - Display list of available options (-help-list-hidden for more)
-version - Display the version of this program
Use override options:
-extra-arg= < string > - Additional argument to append to the compiler command line
-extra-arg-before= < string > - Additional argument to prepend to the compiler command line
-p= < string > - Build path与cxxctp_tool有关的选项(类型-HELP,不是-HELP):
ctp_scripts_paths通行费将搜索CTP_Scripts子文件夹的路径列表
注意: ctp_scripts_paths需要-DENABLE_CLING=TRUE
-L .=DBG9是格式中的日志配置
将记录配置的示例写入文件和控制台流的示例:
./build/bin/CXXCTP_tool -L " .:=INFO:default:console; default=file:path=y.log,async=true,sync_level=DBG9;console=stream:stream=stderr " --srcdir更改输入文件的当前文件系统路径。
- 更改输出文件的当前文件系统路径的--resdir 。
示例(自定义输出dir):
# Remove old generated files
rm -rf gen
rm -rf build/ * generated *
` --version ` to get tool version
` -version ` to get clang version
# Build files to `gen/out` dir
mkdir -p gen/out
cmake -E chdir gen ../build/bin/CXXCTP_tool --resdir= $PWD /gen/out --ctp_scripts_paths= $PWD -L .=DBG9 -extra-arg=-I $PWD /include -extra-arg=-I../resources ../resources/ReflShapeKind.hpp ../resources/test_typeclass_base1.hpp ../resources/test_typeclass_instance1.hpp ../resources/test.cppctp_scripts删除旧的构建工件和生成的文件。
通过-DBUNDLE_EXAMPLE_SCRIPTS=TRUE将脚本与CXXCTP_tool捆绑在一起。
确保您的脚本(插件)通过custom_plugins.cmake.example添加到CXXCTP_tool 。
禁用人为投影脚本-DALLOW_PER_PROJECT_CTP_SCRIPTS=FALSE 。
检查您的脚本(插件)是否在build/tool/CXXCTP_tool --plugins中
检查CXXCTP_tool的系统安装版本与build/tool/CXXCTP_tool (按日期/文件哈希)相同
在gdb下手动运行CXXCTP_tool :
gdb -ex " r " -ex " bt " --args build/tool/CXXCTP_tool .........检查所有所需路径是否在-extra-arg=中。
在DBG9模式下进行日志文件,然后检查.log文件。
CXXCTP使用libTooling解析和修改C ++。
LibTooling是一个库,用于支持基于Clang的独立工具。
有用的链接:
CXXCTP使用CRING在编译时执行C ++。
您可以将保留用于热代码重新加载 / repl / fast C ++原型 /脚本引擎 / jit /等。
有用的链接:
sudo apt install clang-format基于.clang-format文件运行:
find . -regex ' .*.(cpp|hpp|cu|c|h) ' -exec clang-format -style=file -i {} ;有用的链接:
.clang-format文件https://leimao.github.io/blog/clang-format-quick-tutorial/在提出拉请请求之前,请阅读我们的贡献指南。
请注意,该项目已使用行为守则发布。通过参加该项目,您同意遵守其条款。
由于Flexferrum的autoprogrammer ,该项目可能是可能的。
有关Flexferrum在媒体中的autoprogrammer的文章:
所有开源组件均在其关联的开源许可下使用。
使用的开源组件:
请参阅许可证文件
Cmake Files通过样式检查,可以通过从存储库的根中运行运行cmake-format.py来修复。这需要Python 3和Cmake_format(注意:当前在Windows上不起作用)
使用autoformatter cmake-format.py和run-cmake-format.py
pip3 install cmake_format
python3 run-cmake-format.py在命令行运行中使用特定cmakelists.txt文件上使用cmake-format
python3 -m cmake_format -c cmake-format.py -i CMakeLists.txt有一个官方的Visual Studio扩展名,可以在此处找到其详细信息。
关注Cmake styleguide https://github.com/ruslo/0
.cxtpl的项目