feat(tidy): add fairmq-modernize-run-device

- Migrate a device main file from <runFairMQDevice.h> to
  <fairmq/runDevice.h>: the include, the FairMQDevicePtr return type,
  the const ProgOptions& parameter and 'return new T(...)', which becomes
  'return std::make_unique<T>(...)'.
- Fix all of it or nothing: if a return statement of getDevice() is not
  a plain new expression, only report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-09 22:57:09 +00:00
parent 67fd7f2305
commit 871e7e54cf
7 changed files with 295 additions and 2 deletions

View File

@@ -133,7 +133,7 @@ The table is in the order of the headers that declare the deprecated alias. The
| `FairMQUnmanagedRegion` | [`fair::mq::UnmanagedRegion`](/api/fair/mq/UnmanagedRegion/) | `UnmanagedRegion.h` | yes |
| `FairMQUnmanagedRegionPtr` | [`fair::mq::UnmanagedRegionPtr`](/api/fair/mq/#UnmanagedRegionPtr) | `UnmanagedRegion.h` | yes |
| `FairMQRegionConfig` | [`fair::mq::RegionConfig`](/api/fair/mq/RegionConfig/) | `UnmanagedRegion.h` | yes |
| `FairMQDevicePtr` | `std::unique_ptr<fair::mq::Device>` as the return type of `getDevice()` | `runFairMQDevice.h` | no |
| `FairMQDevicePtr` | `std::unique_ptr<fair::mq::Device>` as the return type of `getDevice()` | `runFairMQDevice.h` | yes, with `fairmq-modernize-run-device` |
All old names are global, except `fair::mq::FairMQMemoryResource`. All names in the table except `FairMQDevicePtr` have the attribute `[[deprecated]]`.
@@ -185,7 +185,7 @@ The CMake package is `FairMQ`. Link your targets with `FairMQ::FairMQ`. The exec
## Automate the move with fairmq-tidy
`fairmq-tidy` finds the old headers, most old type names and `Device::fChannels`. With `--fix`, it replaces them in your files. See [Check code with fairmq-tidy](/guides/fairmq-tidy/) and the [list of checks](/tools/fairmq-tidy/#checks).
`fairmq-tidy` finds the old headers, most old type names, the deprecated functions and members, and a `getDevice()` for `runFairMQDevice.h`. With `--fix`, it replaces most of them in your files. See [Check code with fairmq-tidy](/guides/fairmq-tidy/) and the [list of checks](/tools/fairmq-tidy/#checks).
## Related pages

View File

@@ -39,6 +39,7 @@ The `fairmq-*` checks are a clang-tidy module ([Module.cxx](/source/fairmq/tidy/
| `fairmq-modernize-nonnamespaced-types` | Uses of the deprecated global type aliases, for example `FairMQDevice` or `InputMsgCallback` | The namespaced type, for example `fair::mq::Device` |
| `fairmq-modernize-parts-api` | Calls of `Parts::AtRef()` and of `Parts::AddPart(Message*)` | `At()` with `->` or `*`, and `MessagePtr(p)` |
| `fairmq-modernize-progoptions-accessors` | Calls of the deprecated accessors `ProgOptions::GetValue()`, `GetStringValue()` and `SetValue()` | `GetProperty()`, `GetPropertyAsString()` and `SetProperty()` |
| `fairmq-modernize-run-device` | A `getDevice()` for `<runFairMQDevice.h>` that returns a raw pointer | `<fairmq/runDevice.h>`, `std::unique_ptr` and `std::make_unique` |
The checks report a name in a macro, but they do not fix it. Like all clang-tidy checks, they show findings in headers only if the header matches `--header-filter=<regex>`.
@@ -117,6 +118,18 @@ The check does not fix a call on an object expression with side effects, for exa
For a key that does not exist, the old accessors return a default-constructed value, and `GetProperty()` throws. The default `{}` keeps the old behavior. If you know that the key exists, remove the `{}`. The check fixes `SetValue()` only if the code does not use its result, because `SetProperty()` returns `void`.
### fairmq-modernize-run-device
The check moves a device main file from `<runFairMQDevice.h>` to `<fairmq/runDevice.h>`, see [Replace runFairMQDevice.h](/guides/migrate-names/#replace-runfairmqdeviceh):
| Code | Fix |
| --- | --- |
| `#include <runFairMQDevice.h>` | `#include <fairmq/runDevice.h>` |
| `FairMQDevicePtr getDevice(const fair::mq::ProgOptions& config)` | `std::unique_ptr<fair::mq::Device> getDevice(fair::mq::ProgOptions& config)` |
| `return new MyDevice(config);` | `return std::make_unique<MyDevice>(config);` |
The check changes all of these lines or none. If a `return` statement of `getDevice()` does not return a `new` expression, the check reports the function without a fix.
## Build fairmq-tidy
Set the CMake option `BUILD_TIDY_TOOL` (default `OFF`) when you configure FairMQ: