chitralverma opened a new pull request, #9361:
URL: https://github.com/apache/opendal/pull/9361
# Which issue does this PR close?
Part of #9324 (tracker #9320).
# Rationale for this change
#9331 generated the C++ `ListOptions` from `core/core/src/types/options.rs`.
This PR generates `StatOptions` the same way, reusing that PR's table,
templates, and tests. It exposes no new option.
# What changes are included in this PR?
- `dev/src/generate/cpp.rs`: `OPTIONS` lists the eight `StatOptions` members
with their core kinds, in their released order. The generator renders the same
four layers as for `ListOptions`: the public struct in `include/options.hpp`,
the bridge struct in `src/options.rs`, `utils::ToFfiOptions(const StatOptions
&)`, and the Rust conversion into core. Core's `if_version_match`,
`if_version_not_match`, and `checksum` stay unexposed, and the generated
conversion lists them under `// Not exposed in C++ yet:`.
- The bridge now carries `Option<Timestamp>` as
`std::optional<std::chrono::system_clock::time_point>`, with the
`OptionalTimestamp` layout and C++ conversion that `operator.cpp` already uses.
Core rejects an out-of-range time, so a struct with a timestamp member converts
with `TryFrom` (error type `opendal::Error`). `ListOptions` keeps its `From`.
- Docs: each member carries its full core doc comment, rendered as in #9331,
plus three rules:
- A core error kind such as ``[`crate::ErrorKind::NotFound`]`` renders as
`` `NotFound` ``, the name that starts the `what()` of the exception the call
throws. The generator reads these names from `From<ErrorKind> for &'static str`
in `core/core/src/types/error.rs`. When a member names an error kind, the
struct doc adds: "When the operation fails with an error kind that a member
names, such as `NotFound`, it throws a `std::exception` whose `what()` starts
with that kind."
- Outside code spans, `\` becomes `\\` and `@` becomes `\@`, so Doxygen
prints them instead of reading a command. Quotes need no escaping in `///`
comments.
- No generated `///` line ends with a backslash, which would continue the
comment onto the next source line and hide the member declaration. `wrap_doc`
keeps a word that ends with a backslash on one line with the next word, as
clang-format does. A paragraph that ends with a backslash gets an empty
`<!---->`, which Doxygen drops. Current core docs have no backslash or `@`, so
`capability.hpp`, `metadata.hpp`, and the `ListOptions` text are unchanged.
- `generate_options` creates missing output directories.
- `data_structure.hpp`, `src/lib.rs`, and `src/operator.cpp` drop the
hand-written `StatOptions` mirror and conversions. `ci_bindings_cpp.yml` also
runs on changes to `core/core/src/types/error.rs`, which the generator now
reads.
- Tests:
- `dev`: the `StatOptions` text copied from `main`'s `data_structure.hpp`
must appear in the generated header once comments are removed, as the
`ListOptions` text already must. Each member of both structs must have a doc
with as many paragraphs as its core doc. It must also name exactly the
capabilities and error kinds listed in the test, and each capability must be
declared in the generated `capability.hpp`. No rustdoc markup or Rust path may
remain, and only `StatOptions` gets the error note. These checks replace
#9331's paragraph-by-paragraph comparison with core, so rewording or re-marking
core docs passes as long as the references stay the same. Unit tests check the
rendering against literal input: error kinds in both link forms, an unknown
kind left as written, quotes, backslashes, and `@` inside and outside code
spans, a backslash word at a wrap point, and a paragraph that ends with a
backslash. Other tests check that `StatOptions` converts with `TryFrom` and
that a core
`if_modified_since` changed to `Option<String>` stops generation.
- `tests/options_test.cpp`: a positional initializer in `main`'s member
order reaches the bridge, including a time before the epoch. Structured
bindings bind the eight members in order. A default `const StatOptions` reaches
the bridge with every value absent. On `memory`, a stat with the three
`override_*` members succeeds, and a stat of a missing file throws with
`what()` starting with `NotFound`. Setting any one of `version`, `if_match`,
`if_none_match`, `if_modified_since`, or `if_unmodified_since` throws with
`what()` starting with `Unsupported` and naming that argument.
- `src/options_test.rs`: every bridge field reaches core, absent values
stay `None`, and an out-of-range time fails the conversion with core's
timestamp error.
Scratch mutations confirmed that each new test can fail:
- Generator: dropping, swapping, or adding a `StatOptions` row fails the
two dev header tests. Regenerating the binding then fails the positional and
structured-binding tests, or breaks their compilation (`binds to 7 elements,
but 8 names were provided`). Skipping the kind check for `if_modified_since`
fails the kind test. Not rewriting error kinds, or not accepting the
`crate::ErrorKind::` form, fails the name test and the header doc test. Keeping
only the first doc paragraph fails four dev tests. Adding the error note to no
struct, or to every struct, fails the header doc test. Generating `From` for
`StatOptions` fails the `TryFrom` test.
- Escaping: turning off the Doxygen escape, the `<!---->` suffix, or the
`wrap_doc` rule fails the escape tests. With a core doc paragraph ending in
`C:\` and no suffix, the generated header loses `version`: GCC reports
`multi-line comment` and `'struct opendal::StatOptions' has no member named
'version'`.
- Binding: swapping `if_match` and `if_none_match` in the generated Rust
conversion fails the Rust field test and the C++ `Unsupported` test. Dropping
an `override_*` field, ignoring `has_value`, or dropping the timestamp error
fails a Rust test. Passing default options to core fails the `Unsupported`
test. In the generated C++ converter, skipping the pre-epoch normalization,
swapping the two timestamps, or sending `version` or
`override_content_disposition` as absent fails the positional test, and the
`Unsupported` test as well when a condition is affected.
# Are there any user-facing changes?
None in the API. `StatOptions` moves from `data_structure.hpp` to
`options.hpp`, which `data_structure.hpp` includes, so code that includes
either header sees the same declaration. With comments removed, all 19 struct
and class bodies in `include/` match `main`; `StatOptions` is the only one that
moved. `options.hpp` now also includes `<chrono>`. The `StatOptions` members
gain doc comments, which they had none of on `main`.
A probe compiled against `main`'s and this PR's headers printed identical
`sizeof`, `alignof`, member offsets, member types, and default values for all
eight options structs. Positional initialization, structured bindings, and
C++20 designated initialization of `StatOptions` gave the same values, and
compiler warnings were identical. This held on Linux x86-64 with GCC 13.3 and
clang 18.1.3, in C++17 and C++20. `StatOptions` stays 272 bytes with 8-byte
alignment.
# Breaking changes
None
# AI Usage Statement
- Harness: Claude Code via T3 Code. Model: Claude Opus 5.5
(`claude-opus-5-5`). Effort: xhigh. Role: implemented the generator, templates,
wiring, and tests; ran the mutation, layout, and Linux container checks;
drafted this description. The author reviews every change and claim.
- Decisions for review:
- Following #9334, the error-kind mapping lives in the C++ generator and
names what C++ callers can check. The C++ binding has no error-code API: a
failed call throws `rust::Error`, a `std::exception` whose `what()` is core's
`Display` for `Error` and starts with the kind name. A C++ test checks that
prefix for `NotFound` and `Unsupported` on `memory`. `ConditionNotMatch` is not
exercised, because `memory` supports no stat condition.
- The `override_*` docs keep core's "This option is only meaningful when
used along with presign." The C++ binding has no presign API, so these members
have no effect today.
- The options bridge declares its own `OptionalTimestamp`, and the
generated converter has its own `ToFfiOptionalTimestamp`, as #9331 did for
strings and sizes. `operator.cpp` keeps its copy for the still hand-written
`ReadOptions` and `ReaderOptions`.
- The `wrap_doc` rule also applies to the capability and metadata headers;
their output is unchanged.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]