about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-27 17:43:20 +0000
committerbors <bors@rust-lang.org>2024-03-27 17:43:20 +0000
commit0157da41ee9a1f6fb1a20e00ea62ab4122e2feaa (patch)
tree741b5837eef2affdf7001be59d47174ebe1ce1fd /compiler/rustc_parse/src
parentd5db7fb537c0352eec3855aa0331c271c48ac4f6 (diff)
parent1f2178b9e7b43f4efe549e19889eafeec9061e8c (diff)
downloadrust-0157da41ee9a1f6fb1a20e00ea62ab4122e2feaa.tar.gz
rust-0157da41ee9a1f6fb1a20e00ea62ab4122e2feaa.zip
Auto merge of #122460 - jieyouxu:rmake-example-refactor, r=Nilstrieb
Rework rmake support library API

### Take 1: Strongly-typed API

Context: https://github.com/rust-lang/rust/pull/122448#discussion_r1523774427

> My 2 cents: from my experience with writing similar "test DSLs", I would suggest to create these helpers as soon as possible in the process (basically the first time someone needs them, not only after N similar usages), and basically treat any imperative code in these high-level tests as a maintenance burden, basically making them as declarative as possible. Otherwise it might be a bit annoying to keep refactoring the tests later once such helpers are available.
>
> I would even discourage the arg method and create explicit methods for setting things like unpretty, the output file etc., but this might be more controversial, as it will make the invoked command-line arguments more opaque.

cc `@Kobzol` for the testing DSL suggestion.

Example:

```rs
let output = Rustc::new()
    .input_file("main.rs")
    .emit(&[EmitKind::Metadata])
    .extern_("stable", &stable_path)
    .output();
```

### Take 2: xshell-based macro API

Example:

```rs
let sh = Shell::new()?;
let stable_path = stable_path.to_string_lossy();
let output = cmd!(sh, "rustc main.rs --emit=metadata --extern stable={stable_path}").output()?;
```

### Take 3: Weakly-typed API with a few helper methods

```rs
let output = Rustc::new()
    .input("main.rs")
    .emit("metadata")
    .extern_("stable", &stable_path)
    .output();
```
Diffstat (limited to 'compiler/rustc_parse/src')
0 files changed, 0 insertions, 0 deletions