init project

This commit is contained in:
Zhuo Yang 2024-09-10 13:35:36 +08:00
commit 11be0872cd
5 changed files with 107 additions and 0 deletions

42
README.md Normal file
View File

@ -0,0 +1,42 @@
# wmake_with_bear
[中文](./README.zh_CN.md) | [English](./README.md)
## Project Description
The `compile_commands.json` file is often used to help various language servers (such as clangd, ccls, etc.) understand how to compile a project, enabling features like code navigation, completion, and analysis.
This project aims to help OpenFOAM generate `compile_commands.json`. The `bear` tool is specifically used to generate this file, as it wraps the build command `make` to capture various compilation options. Since OpenFOAM's native build tool `wmake` is a wrapper around `make`, it makes sense to combine `wmake` with `bear` to generate `compile_commands.json`.
In fact, the com version of OpenFOAM has already considered this and provides a `-with-bear` option to invoke `bear`. However, this project seeks to be more general, supporting both the com and org versions, as well as the foam-extend version. The good news is that these three main branches share some common logic in the underlying `wmake` toolchain.
## Installation and Usage
### Dependencies
This project clearly depends on Bear. You can usually install it using the system's package manager or through tools like Conda for precompiled versions. Of course, you can also compile it from source. For more details, refer to [rizsotto/Bear](https://github.com/rizsotto/Bear).
### Installation
The installation is straightforward:
```bash
# Activate your OpenFOAM environment, then clone the project and run the install script
$ git clone --depth 1 https://github.com/zhyang-dev/wmake_with_bear.git
$ cd wmake_with_bear && chmod +x install && ./install
```
### Usage
The installation command above will create a `wmake_with_bear` and alias `bwmake` in the `$WM_PROJECT_DIR/wmake` directory. To generate `compile_commands.json` in a project, use `bwmake` instead of `wmake`.
### Testing
The following tests use icoFoam as an example.
The usage of `bwmake` is basically the same as `wmake`, but `bwmake` can generate `compile_commands.json`. In OpenFOAM-v2012, using `bwmake` to compile icoFoam produces the result shown below.
![](./assets/test_bwmake_with_of2012.png)
Using `clangd` as the language server in VSCode, you can see that code suggestions work correctly.
![](./assets/vscode_clangd_icoFoam_bwmake.png)

40
README.zh_CN.md Normal file
View File

@ -0,0 +1,40 @@
# wmake_with_bear
[中文](./README.zh_CN.md) | [English](./README.md)
## 项目说明
compile_commands.json常被用于帮助各种language server例如常见的clandccls等理解如何编译项目以便提供代码导航、补全和分析等功能。
本项目的目标是帮助OpenFOAM项目生成compile_commands.json。bear工具专门用来生成该文件它需要包裹构建命令make以获取各种编译选项。而OpenFOAM原生的编译工具wmake是对make的包装因此有道理认为wmake可以与bear结合以生成compile_commands.json。
事实上com版的OpenFOAM发行已经考虑到了这一点它提供了`-with-bear`选项来调用bear但是本项目希望更加通用同时支持com和org甚至是foam-extend版。好消息是这三个主流分支在wmake工具链的底层逻辑上还有一定共性。
## 安装和使用
### 依赖
显然该项目依赖bear一般可以使用系统的包管理器安装或者通过conda之类的工具安装预编译的版本当然也可以自行源码编译。
具体可以参考[rizsotto/Bear](https://github.com/rizsotto/Bear)
### 安装
项目的安装很简单:
```bash
$ # activate your of environment, then in any place, clone the project and run install script
$ git clone --depth 1 https://github.com/zhyang-dev/wmake_with_bear.git
$ cd xxx && chmod +x install && ./install
```
### 使用
上述安装命令会在`$WM_PROJECT_DIR/wmake`目录下创建一个`wmake_with_bear`以及别名`bwmake`
这样在希望生成`compile_commands.json`的项目中,使用`bwmake`替换`wmake`就能调用wmake同时生成该json文件。
### 测试
下面以icoFoam为例测试。
bwmake的使用跟wmake使用基本相同但是bwmake能够生成`compile_commands.json`。
在OpenFOAM-v2012中使用bwmake编译icoFoam的效果如下图所示。
![](./assets/test_bwmake_with_of2012.png)
在VSCode中使用clangd作为language server可以发现能够正常代码提示。
![](./assets/vscode_clangd_icoFoam_bwmake.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 KiB

25
install Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
# check bear
if bear_version="$(bear --version 2>&1)"
then
echo "bear version: $bear_version"
else
echo "bear not found"
exit 1
fi
# check openfoam environment
if [ -n "$WM_PROJECT_VERSION" ]
then
echo "openfoam version: OpenFOAM-$WM_PROJECT_VERSION"
else
echo "openfoam not found"
exit 1
fi
# create wmake_with_bear and bwmake
cd $WM_PROJECT_DIR/wmake
[ -e wmake_with_bear ] && { echo "wmake_with_bear exists, exiting..."; exit 1; }
cp -i wmake wmake_with_bear
sed -i 's/"make"/"bear -- make"/g' wmake_with_bear
ln -s wmake_with_bear bwmake || { echo "link bwmake exists, exiting."; exit 1; }
echo "done."