Commit Graph

44 Commits

Author SHA1 Message Date
Ed Page 69ba69f908 refactor: Resolve clap deprecations 2022-09-28 13:32:27 -05:00
Ed Page 96948f7a24 refactor(cli): Upgrade to clap v4 2022-09-28 13:32:14 -05:00
Ed Page 0a78364fd1 refactor(cli): Align with clap 3.1 on terminology
clap 3.1 renamed `App` to `Command`.  When we upgrade to clap v4, the
lifetime will be removed and we can just use `clap::Command` instead of
a type alias.  This is prep for that.
2022-09-20 13:28:36 -05:00
Weihang Lo f128cbd5da
Stabilize `--crate-type` flag for `cargo rust` 2022-07-16 23:25:55 +01:00
Ed Page fc0ca1e178 refactor: Resolve clap 3.2 deprecations 2022-06-13 10:02:23 -05:00
Jon Gjengset f78ffb9f32 Avoid new deprecation warnings from clap 3.1.0 2022-02-16 16:26:55 -08:00
Josh Triplett c06691897a Stabilize `-Ztimings` as `--timings`
The `-Ztimings` option has existed for years, and many people use it to
profile and optimize their builds. It's one of the common reasons people
use nightly cargo.

The machine-readable JSON output may warrant further careful inspection
before we commit to a stable format. However, for the human-readable
output we don't need to make any commitment about the exact output.

Add a `--timings` option, as the stable equivalent to `-Ztimings`.
Stabilize the `html` output format, and require `-Zunstable-options` for
the `json` output format.

Document the new option, and update the testsuite.
2022-01-30 21:43:48 -08:00
Ed Page 92fa72d480 refactor: Resolve Arg::multiple deprecation
Note: `cargo vendor --sync` did not use `multi_opt` and so it has both
multiple occurrences **and** multiple values.  If we want to deprecate
this, we'll need `unstable-grouped` to be stablized (or pin our clap
version) and ensure each group has only 1 value.
2022-01-06 09:18:14 -06:00
Ed Page 88a122c428 refactor: Resolve Arg::with_name deprecation 2022-01-06 09:13:34 -06:00
Ed Page f17ecafc24 Upgrade to Clap 3
- One parser change found by `cargo_config::includes` is that clap 2
  would ignore any values after a `=` for flags.
  `cargo config --show-origin` is a flag but the test passed `--show-origin=yes` which
  happens to give the desired result for that test but is the same as
  `--show-origin=no` or `--show-origin=alien-invasion`.
- The parser now panics when accessing an undefined attribute but clap
  takes advantage of that for sharing code across commands that have
  different subsets of arguments defined.  I've extended clap so we can
  "look before you leap" and put the checks at the argument calls to
  start off with so its very clear what is tenuously shared.  This
  allows us to go in either direction in the future, either addressing
  how we are sharing between commands or by moving this down into the
  extension methods and pretending this clap feature doesn't exist
- On that topic, a test found clap-rs/clap#3263.  For now, there is a
  hack in clap.  Depending on how we fix that in clap for clap 4.0, we
  might need to re-address things in cargo.
- `value_of_os` now requires setting `allow_invalid_utf8`, otherwise it
  asserts.  To help catch this, I updated the argument definitions
  associated with lookups reported by:
  - `rg 'values?_os' src/`
  - `rg 'values?_of_os' src/`
- clap now reports `2` for usage errors, so we had to bypass clap's
  `exit` call to keep the same exit code.

BREAKING CHANGE: API now uses clap3
2022-01-05 19:54:54 -06:00
hi-rustin a3e3ff99c9 Add arg_quiet
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2021-12-06 19:12:07 +08:00
hi-rustin 660ce6bba4 Add tests
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2021-11-23 22:58:18 +08:00
hi-rustin 0c5f348bc2 Add crate type flag to rustc command
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2021-11-21 12:31:00 +08:00
hi-rustin 17c0ea7417 Improve the help text of the --quiet args for all commands
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2021-11-14 20:41:00 +08:00
Eric Huss 73dba767d1 Support custom profiles in legacy commands.
This makes the following changes:

- Allows `cargo check`, `cargo fix`, and `cargo rustc` to support custom
  named profiles. This retains the legacy behavior of those commands.
- Fixes `cargo bench` so that it supports custom named profiles.
2021-07-13 15:22:09 -07:00
Eric Huss abbd2b0bb1 Add `cargo rustc --print` unstable docs. 2021-05-04 08:55:23 -07:00
Aaron Hill 6177c6584b
Implement future incompatibility report support
cc rust-lang/rust#71249

This implements the Cargo side of 'Cargo report future-incompat'

Based on feedback from alexcrichton and est31, I'm implemented this a
flag `--future-compat-report` on `cargo check/build/rustc`, rather than
a separate `cargo describe-future-incompatibilities` command. This
allows us to avoid writing additional information to disk (beyond the
pre-existing recording of rustc command outputs).

This PR contains:

* Gating of all functionality behind `-Z report-future-incompat`.
  Without this flag, all user output is unchanged.
* Passing `-Z emit-future-incompat-report` to rustc when
  `-Z report-future-incompat` is enabled
* Parsing the rustc JSON future incompat report, and displaying it
  it a user-readable format.
* Emitting a warning at the end of a build if any crates had
  future-incompat reports
* A `--future-incompat-report` flag, which shows the full report for
  each affected crate.
* Tests for all of the above.

At the moment, we can use the `array_into_iter` to write a test.
However, we might eventually get to a point where rustc is not currently
emitting future-incompat reports for any lints. What would we want the
cargo tests to do in this situation?

This functionality didn't require any significant internal changes to
Cargo, with one exception: we now process captured command output for
all units, not just ones where we want to display warnings. This may
result in a slightly longer time to run `cargo build/check/rustc` from
a full cache. since we do slightly more work for each upstream
dependency. Doing this seems unavoidable with the current architecture,
since we need to process captured command outputs to detect
any future-incompat-report messages that were emitted.
2021-03-04 15:21:15 -05:00
Chris Field a740608352 Merge branch 'master' of https://github.com/rust-lang/cargo into feature-rustc-cfg-argument
# Conflicts:
#	src/cargo/ops/cargo_compile.rs
2021-02-09 13:20:32 -05:00
Chris Field 13807557cd Change implementation
The implementation now follows `rustc --print <INFO>` and adds the
`--print <INFO>` option to the `cargo rustc` subcommand. When the `cargo
rustc --print <INFO>` command is executed, all extra arguments are
passed to the `rustc --print <INFO>` command including the
Cargo-specific (compiler) target flags and options from Cargo's
configuration and environment variables. If multiple `--target <TRIPLE>`
options are used, then the list is of (compiler) targets are iterated
and outputed with an empty line delimiting the output for each compiler
target. If no `--target <TRIPLE>` is used, then the host compiler target
is used.

None of the output is altered. It is just a straight dump of the `rustc
--print <FOO>` command.

This implementation works with any of the `<INFO>` values for the `rustc
--print <FOO>` command, i.e. `cfg`, `target-list`, `sysroot`, etc.

Most of the arguments for either `cargo rustc` are ignored unles
recognized by the `rustc --print <FOO>` argument. For
example, `--target <TRIPLE>`. Cargo configuration is target dependent,
so the `--target <TRIPLE>` must be recognized.
2021-01-30 14:09:01 -05:00
Chris Field afa1905e75 Remove `--print-cfg` argument
The `--print-cfg` flag will be replaced with the `--print foo` option
and passed to `rustc --print foo`. The output will be the "raw" output
from the `rustc --print foo` command instead of a serialized JSON of the
RustcTarget Data. This is the first step in changing the implementation.
The serialization code is no longer needed.
2021-01-30 11:46:23 -05:00
Dirkjan Ochtman c221fec911 Implement support for rust-version field in project metadata 2021-01-20 11:40:41 +01:00
Chris Field 698fe70833 Fix formatting 2021-01-08 13:31:19 -05:00
Chris Field fc83cbedbb Refactor to use constant for arg name
A static constant is used to define the arg name since this may change
after review but the string is used as an ID in processing arguments.
2021-01-08 12:53:01 -05:00
Chris Field 7f1c268ab7 Fix typo 2021-01-08 12:50:02 -05:00
Chris Field e078a6c9ce Change to lighter weight `--print-cfg`
The `--cfg` flag is changed to `--print-cfg`, so it is a little more
obvious what the flag will do. At the same time, the implementation is
changed to only affect the `cargo rustc` subcommand. It skips
downloading the entire crate graph and compiling/building the project.
Instead, it just obtains the rustc target data similar to the
`ops::compile` function and then returns. The `ops::print_cfg` function
is added, but this could also be moved to just the `cargo rustc`
subcommand.
2021-01-08 12:46:16 -05:00
Chris Field 9be620a770 Fix formatting 2020-12-19 13:08:38 -05:00
Chris Field af3a843c5e Change the `--cfg` and `--rustc-cfg` to hidden
Similar to the `--unit-graph` flag, which is also hidden, the `--cfg`
and `--rustc-cfg` are hidden. I think they will be made visible once the
feature is stablized.
2020-12-19 11:33:34 -05:00
Chris Field e9e4593f40 Change option name for subcommands
The `--cfg` option is changed to `--rustc-cfg` for the build, bench,
test, and check subcommands but left as `--cfg` for the rustc
subcommand. The `--rustc-cfg` flag is more descriptive of
configuration (cfg) that will be printed as JSON, but it looks weird if
`--rustc-cfg` is used with the rustc subcommand, i.e.:

```pwsh
PS C:\>cargo rustc --rustc-cfg
```

versus

```
PS C:\>cargo rustc --cfg
```

By using the rustc subcommad, the type of output and configuration is
known, but wiht the other subcommands it is ambiguous what a lone
`--cfg` would output.
2020-12-16 14:53:18 -05:00
Chris Field 0018ef0698 Add minimum working implementation
The `--cfg` flag is added to the `cargo rustc` subcommand. The
implementation generally follows the `--unit-graph` implementation in
that it aborts compilation after the build context is created.

I discovered that cargo runs the `rustc --print cfg` every time it
builds/compiles a package. It stores this information for all compiler
targets and the host in the `RustcTargetData` struct, which is further
populated when the build context is created. When the `rustc --print
cfg` command is ran internally, all of the Cargo configurations and
environment variables are applied to the command. This means that the
command does not need to be re-run for the `--cfg` flag. Instead, I just
needed to print what was already populated into the `RustcTargetData`
struct for the build context and abort before executing the
build/compile job.

The existence of the `rustc --print cfg` command being executed
internally to Cargo also meant that multi-target and cross-compilation
are naturally supported. However, the output kind of has to be JSON
because it is not possible to select a single compiler target to print.
It gets messy very quickly if multiple targets are specified and which
one to use for the "human" output similar to the `rustc --print cfg`
command. The solution is to output in JSON like the `--unit-graph` flag
and include the data for the host and any specified targets. A
downstream parser can then pull out/extract the target data that is
needed.

The `--cfg` flag needs to be added to the `cargo build` subcommand, too.
The `--unit-graph` flag is available in both subcommands and so should
the `--cfg` flag for consistency. Ultimately, the `cargo build`
subcommand "calls" the `cargo rustc` subcommand. In other words, both
subcommands use the same implementation.

The flag does not appear in the help text, but the `--unit-graph` does
not either. I need to work on this as well.
2020-12-15 17:24:30 -05:00
Eric Huss 0e26eae5c1 Display embedded man pages for built-in commands. 2020-08-03 12:30:38 -07:00
Eric Huss aa80a984c0 Add unit-graph JSON output. 2020-03-15 15:16:36 -07:00
KaneGreen 367fe7bfcb Modified the help information of cargo-rustc 2020-02-17 10:11:27 +08:00
Alex Crichton 3a18c89a55 Migrate from the `failure` crate to `anyhow`
The `anyhow` crate interoperates with the `std::error::Error` trait
rather than a custom `Fail` trait, and this is the general trend of
error handling in Rust as well.

Note that this is mostly mechanical (sed) and intended to get the test
suite passing. As usual there's still more idiomatic cleanup that can
happen, but that's left to later commits.
2020-01-07 16:50:09 -08:00
Dan Aloni 29b7e90ba3 named-profiles: formatting fixes from 'cargo fmt' 2019-06-20 19:43:33 +03:00
Dan Aloni 2f81adb115 named-profiles: feature gate exemptions
To preserve old `profile` behavior, some cases of `--profile`
should not trigger an error. Plus, the 'check' profile should be
allowed for profile selection tests and `rustc --profile=check`.
2019-06-20 18:32:29 +03:00
Dan Aloni 86c459d423 Support for named Cargo profiles
This allows creating custom profiles that inherit from other profiles.

For example, one can have a release-lto profile that looks like this:

    [profile.release-lto]
    inherits = "release"
    lto = true

The profile name will also carry itself into the output directory name
so that the different build outputs can be cached independently from
one another.

So in effect, at the `target` directory, a name will be created for
the new profile, in addition to the 'debug' and 'release' builds:

```
    $ cargo build --profile release-lto
    $ ls -l target
    debug release release-lto
```
2019-05-27 21:35:31 +03:00
Collins Abitekaniza e873e4e9d5 explicitly add --quiet option to all subcommands 2019-02-21 18:35:17 +03:00
Damian a51759c5e8 Moved checks into compile_options(), changed tests 2019-01-03 23:00:45 +01:00
Dale Wijnand 54c4214251
Remove trailing extern crate usage 2018-12-13 15:21:32 +00:00
Dale Wijnand 6d1d3a6840
Fix 2018 edition idioms 2018-12-06 20:26:07 +01:00
Dale Wijnand 04ddd4d0fc
Upgrade to Rust 2018 2018-12-06 20:18:35 +01:00
Eric Huss 3a1cad6f28 --all-targets fixes
- Fix: `cargo test --all-targets` was running lib tests three times.
- `--all-targets` help strings were wrong or misleading.
- Minor cleanup to add `Proposal` type to maybe make the code more readable.
2018-09-16 20:33:05 -07:00
Dirkjan Ochtman 293a2a7fab Expose CompileMode in command_prelude 2018-05-03 21:54:48 +02:00
Eric Huss 795f69b3dd Address autobins warning. 2018-05-03 10:08:26 -07:00