sapling/eden/fs
Zeyi (Rice) Fan 8290ea3545 cli_rs: add stack config proc macro
Summary:
**Problem:** EdenFS has the classic hierarchical configuration design. We load from `/etc/eden/edenfs.rc` first, then `/etc/eden/conf.d/*` then `$HOME/.edenrc`. The latter can overwrite the former. At the end we have a complete view of the configurations.

`serde` is great, but it can't give us the information of whether it generated a field from `serde(default)` or from de-serialization. So we can't just deserialize then merge the configuration files. We need that information, and nor serde should give us that functionality.

`stack-config` is created to load configurations with serde. It automatically generates code with the intermediate data structure and taking care of merging of multiple configuration files. It derives a data type based on the original struct but wrap each field with `Option<T>` and mark it with Serde. Then it generates the code to merge and build the final concrete configuration data type.

It does not care what kind of data format the configuration file is, as long as it can deserialize into the generate optional type, it accepts it.

Example, say I have a file with this structure:

```
#[derive(StackConfig)]
struct Config {
  path: String,
}
```

Then this crate will generate:

```
mod __stack_config_private {
  #[derive(serde::Deserialize)]
  pub(super) struct ConfigOpt {
    path: Option<String>
  }

  ...
}

struct ConfigLoader {
  layers: Vec<__stack_config_private::ConfigOpt>,
}

impl ConfigLoader {
  fn new() { ... }
  fn load(&mut self, layer: __stack_config_private::ConfigOpt> { ... }
  fn build(self) -> Config { ... }
}
```

See `examples/parse.rs` for usage.

Reviewed By: xavierd

Differential Revision: D26377547

fbshipit-source-id: 1e07d9867742913fd76ed4f765160f0035a2f2a3
2021-02-12 12:33:47 -08:00
..
benchharness add 4k random writes benchmark 2020-07-14 16:13:37 -07:00
benchmarks Remove dead includes in eden 2020-10-09 15:25:47 -07:00
cli Add annotations to eden/fs/cli/top.py 2021-02-12 11:38:44 -08:00
cli_rs cli_rs: add stack config proc macro 2021-02-12 12:33:47 -08:00
config nfs: controls whether Mountd should register itself with rpcbind 2021-02-03 17:54:55 -08:00
docs run linter in eden/fs/docs 2021-01-25 16:13:54 -08:00
fuse inodes: move dispatchers around 2021-02-10 11:52:06 -08:00
inodes inodes: move dispatchers around 2021-02-10 11:52:06 -08:00
journal record all commit transitions in the journal 2021-02-04 18:38:35 -08:00
model model: remove test-only constructor for TreeEntry 2021-01-05 14:08:14 -08:00
monitor Apply clang-format update fixes 2021-01-10 10:06:29 -08:00
nfs fs: default initialize XdrVariant 2021-02-10 13:18:46 -08:00
notifications notifications: support Windows 2020-11-11 09:37:56 -08:00
prjfs inodes: move dispatchers around 2021-02-10 11:52:06 -08:00
py run linter in eden/fs/py 2021-01-25 16:13:55 -08:00
rocksdb Remove dead includes in eden 2019-10-11 16:45:01 -07:00
scripts move eden/scripts/ into eden/fs/ 2020-11-04 18:29:49 -08:00
service nfs: add NfsServer class 2021-02-09 12:47:11 -08:00
sqlite remove dependency on glog 2020-11-10 16:31:15 -08:00
store rate limit logging 2021-01-29 14:34:23 -08:00
takeover Apply clang-format update fixes 2021-01-10 10:06:29 -08:00
telemetry implement FUSE_FALLOCATE 2021-01-20 19:04:59 -08:00
testharness inodes: move dispatchers around 2021-02-10 11:52:06 -08:00
third-party eden: support NO_OPEN support on macOS 2020-07-27 17:53:03 -07:00
utils Rename Try::throwIfFailed -> throwUnlessValue 2021-01-11 13:05:17 -08:00
CMakeLists.txt nfs: make it compile with getdeps builds 2021-02-03 17:54:54 -08:00