Skip to content

Commit cf474a5

Browse files
committed
Auto merge of #10133 - joshtriplett:release-short, r=ehuss
Support abbreviating `--release` as `-r` Of the options people regularly pass to cargo, `--release` seems by far the most common. Yet even on the command line, we expect people to type out `--release`. Add a short version `-r`, and add some tests in the testsuite that confirm it works.
2 parents f9089fc + c92d917 commit cf474a5

28 files changed

+68
-10
lines changed

src/cargo/util/command_prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub trait AppExt: Sized {
142142
}
143143

144144
fn arg_release(self, release: &'static str) -> Self {
145-
self._arg(opt("release", release))
145+
self._arg(opt("release", release).short("r"))
146146
}
147147

148148
fn arg_profile(self, profile: &'static str) -> Self {

src/doc/man/generated_txt/cargo-build.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ OPTIONS
142142
<https://doc.rust-lang.org/cargo/guide/build-cache.html>
143143
documentation for more details.
144144

145-
--release
145+
-r, --release
146146
Build optimized artifacts with the release profile. See also the
147147
--profile option for choosing a specific profile by name.
148148

src/doc/man/generated_txt/cargo-check.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ OPTIONS
148148
<https://doc.rust-lang.org/cargo/guide/build-cache.html>
149149
documentation for more details.
150150

151-
--release
151+
-r, --release
152152
Check optimized artifacts with the release profile. See also the
153153
--profile option for choosing a specific profile by name.
154154

src/doc/man/generated_txt/cargo-doc.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ OPTIONS
126126
<https://doc.rust-lang.org/cargo/guide/build-cache.html>
127127
documentation for more details.
128128

129-
--release
129+
-r, --release
130130
Document optimized artifacts with the release profile. See also the
131131
--profile option for choosing a specific profile by name.
132132

src/doc/man/generated_txt/cargo-fix.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ OPTIONS
221221
<https://doc.rust-lang.org/cargo/guide/build-cache.html>
222222
documentation for more details.
223223

224-
--release
224+
-r, --release
225225
Fix optimized artifacts with the release profile. See also the
226226
--profile option for choosing a specific profile by name.
227227

src/doc/man/generated_txt/cargo-run.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ OPTIONS
7171
<https://doc.rust-lang.org/cargo/guide/build-cache.html>
7272
documentation for more details.
7373

74-
--release
74+
-r, --release
7575
Run optimized artifacts with the release profile. See also the
7676
--profile option for choosing a specific profile by name.
7777

src/doc/man/generated_txt/cargo-rustc.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ OPTIONS
133133
<https://doc.rust-lang.org/cargo/guide/build-cache.html>
134134
documentation for more details.
135135

136-
--release
136+
-r, --release
137137
Build optimized artifacts with the release profile. See also the
138138
--profile option for choosing a specific profile by name.
139139

src/doc/man/generated_txt/cargo-rustdoc.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ OPTIONS
142142
<https://doc.rust-lang.org/cargo/guide/build-cache.html>
143143
documentation for more details.
144144

145-
--release
145+
-r, --release
146146
Document optimized artifacts with the release profile. See also the
147147
--profile option for choosing a specific profile by name.
148148

src/doc/man/generated_txt/cargo-test.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ OPTIONS
219219
<https://doc.rust-lang.org/cargo/guide/build-cache.html>
220220
documentation for more details.
221221

222-
--release
222+
-r, --release
223223
Test optimized artifacts with the release profile. See also the
224224
--profile option for choosing a specific profile by name.
225225

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{#option "`--release`"}}
1+
{{#option "`-r`" "`--release`"}}
22
{{actionverb}} optimized artifacts with the `release` profile.
33
See also the `--profile` option for choosing a specific profile by name.
44
{{/option}}

src/doc/src/commands/cargo-build.md

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ target artifacts are placed in a separate directory. See the
181181

182182

183183

184+
<dt class="option-term" id="option-cargo-build--r"><a class="option-anchor" href="#option-cargo-build--r"></a><code>-r</code></dt>
184185
<dt class="option-term" id="option-cargo-build---release"><a class="option-anchor" href="#option-cargo-build---release"></a><code>--release</code></dt>
185186
<dd class="option-desc">Build optimized artifacts with the <code>release</code> profile.
186187
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>

src/doc/src/commands/cargo-check.md

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ target artifacts are placed in a separate directory. See the
186186

187187

188188

189+
<dt class="option-term" id="option-cargo-check--r"><a class="option-anchor" href="#option-cargo-check--r"></a><code>-r</code></dt>
189190
<dt class="option-term" id="option-cargo-check---release"><a class="option-anchor" href="#option-cargo-check---release"></a><code>--release</code></dt>
190191
<dd class="option-desc">Check optimized artifacts with the <code>release</code> profile.
191192
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>

src/doc/src/commands/cargo-doc.md

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ target artifacts are placed in a separate directory. See the
164164

165165

166166

167+
<dt class="option-term" id="option-cargo-doc--r"><a class="option-anchor" href="#option-cargo-doc--r"></a><code>-r</code></dt>
167168
<dt class="option-term" id="option-cargo-doc---release"><a class="option-anchor" href="#option-cargo-doc---release"></a><code>--release</code></dt>
168169
<dd class="option-desc">Document optimized artifacts with the <code>release</code> profile.
169170
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>

src/doc/src/commands/cargo-fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ target artifacts are placed in a separate directory. See the
266266

267267

268268

269+
<dt class="option-term" id="option-cargo-fix--r"><a class="option-anchor" href="#option-cargo-fix--r"></a><code>-r</code></dt>
269270
<dt class="option-term" id="option-cargo-fix---release"><a class="option-anchor" href="#option-cargo-fix---release"></a><code>--release</code></dt>
270271
<dd class="option-desc">Fix optimized artifacts with the <code>release</code> profile.
271272
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>

src/doc/src/commands/cargo-run.md

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ target artifacts are placed in a separate directory. See the
9999

100100

101101

102+
<dt class="option-term" id="option-cargo-run--r"><a class="option-anchor" href="#option-cargo-run--r"></a><code>-r</code></dt>
102103
<dt class="option-term" id="option-cargo-run---release"><a class="option-anchor" href="#option-cargo-run---release"></a><code>--release</code></dt>
103104
<dd class="option-desc">Run optimized artifacts with the <code>release</code> profile.
104105
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>

src/doc/src/commands/cargo-rustc.md

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ target artifacts are placed in a separate directory. See the
168168

169169

170170

171+
<dt class="option-term" id="option-cargo-rustc--r"><a class="option-anchor" href="#option-cargo-rustc--r"></a><code>-r</code></dt>
171172
<dt class="option-term" id="option-cargo-rustc---release"><a class="option-anchor" href="#option-cargo-rustc---release"></a><code>--release</code></dt>
172173
<dd class="option-desc">Build optimized artifacts with the <code>release</code> profile.
173174
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>

src/doc/src/commands/cargo-rustdoc.md

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ target artifacts are placed in a separate directory. See the
183183

184184

185185

186+
<dt class="option-term" id="option-cargo-rustdoc--r"><a class="option-anchor" href="#option-cargo-rustdoc--r"></a><code>-r</code></dt>
186187
<dt class="option-term" id="option-cargo-rustdoc---release"><a class="option-anchor" href="#option-cargo-rustdoc---release"></a><code>--release</code></dt>
187188
<dd class="option-desc">Document optimized artifacts with the <code>release</code> profile.
188189
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>

src/doc/src/commands/cargo-test.md

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ target artifacts are placed in a separate directory. See the
262262

263263

264264

265+
<dt class="option-term" id="option-cargo-test--r"><a class="option-anchor" href="#option-cargo-test--r"></a><code>-r</code></dt>
265266
<dt class="option-term" id="option-cargo-test---release"><a class="option-anchor" href="#option-cargo-test---release"></a><code>--release</code></dt>
266267
<dd class="option-desc">Test optimized artifacts with the <code>release</code> profile.
267268
See also the <code>--profile</code> option for choosing a specific profile by name.</dd>

src/etc/man/cargo-build.1

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ target artifacts are placed in a separate directory. See the
169169
\fIbuild cache\fR <https://doc.rust\-lang.org/cargo/guide/build\-cache.html> documentation for more details.
170170
.RE
171171
.sp
172+
\fB\-r\fR,
172173
\fB\-\-release\fR
173174
.RS 4
174175
Build optimized artifacts with the \fBrelease\fR profile.

src/etc/man/cargo-check.1

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ target artifacts are placed in a separate directory. See the
174174
\fIbuild cache\fR <https://doc.rust\-lang.org/cargo/guide/build\-cache.html> documentation for more details.
175175
.RE
176176
.sp
177+
\fB\-r\fR,
177178
\fB\-\-release\fR
178179
.RS 4
179180
Check optimized artifacts with the \fBrelease\fR profile.

src/etc/man/cargo-doc.1

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ target artifacts are placed in a separate directory. See the
147147
\fIbuild cache\fR <https://doc.rust\-lang.org/cargo/guide/build\-cache.html> documentation for more details.
148148
.RE
149149
.sp
150+
\fB\-r\fR,
150151
\fB\-\-release\fR
151152
.RS 4
152153
Document optimized artifacts with the \fBrelease\fR profile.

src/etc/man/cargo-fix.1

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ target artifacts are placed in a separate directory. See the
269269
\fIbuild cache\fR <https://doc.rust\-lang.org/cargo/guide/build\-cache.html> documentation for more details.
270270
.RE
271271
.sp
272+
\fB\-r\fR,
272273
\fB\-\-release\fR
273274
.RS 4
274275
Fix optimized artifacts with the \fBrelease\fR profile.

src/etc/man/cargo-run.1

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ target artifacts are placed in a separate directory. See the
8080
\fIbuild cache\fR <https://doc.rust\-lang.org/cargo/guide/build\-cache.html> documentation for more details.
8181
.RE
8282
.sp
83+
\fB\-r\fR,
8384
\fB\-\-release\fR
8485
.RS 4
8586
Run optimized artifacts with the \fBrelease\fR profile.

src/etc/man/cargo-rustc.1

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ target artifacts are placed in a separate directory. See the
155155
\fIbuild cache\fR <https://doc.rust\-lang.org/cargo/guide/build\-cache.html> documentation for more details.
156156
.RE
157157
.sp
158+
\fB\-r\fR,
158159
\fB\-\-release\fR
159160
.RS 4
160161
Build optimized artifacts with the \fBrelease\fR profile.

src/etc/man/cargo-rustdoc.1

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ target artifacts are placed in a separate directory. See the
166166
\fIbuild cache\fR <https://doc.rust\-lang.org/cargo/guide/build\-cache.html> documentation for more details.
167167
.RE
168168
.sp
169+
\fB\-r\fR,
169170
\fB\-\-release\fR
170171
.RS 4
171172
Document optimized artifacts with the \fBrelease\fR profile.

src/etc/man/cargo-test.1

+1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ target artifacts are placed in a separate directory. See the
266266
\fIbuild cache\fR <https://doc.rust\-lang.org/cargo/guide/build\-cache.html> documentation for more details.
267267
.RE
268268
.sp
269+
\fB\-r\fR,
269270
\fB\-\-release\fR
270271
.RS 4
271272
Test optimized artifacts with the \fBrelease\fR profile.

tests/testsuite/build.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,25 @@ fn verbose_release_build() {
17751775
.run();
17761776
}
17771777

1778+
#[cargo_test]
1779+
fn verbose_release_build_short() {
1780+
let p = project().file("src/lib.rs", "").build();
1781+
p.cargo("build -v -r")
1782+
.with_stderr(
1783+
"\
1784+
[COMPILING] foo v0.0.1 ([CWD])
1785+
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
1786+
--emit=[..]link[..]\
1787+
-C opt-level=3[..]\
1788+
-C metadata=[..] \
1789+
--out-dir [..] \
1790+
-L dependency=[CWD]/target/release/deps`
1791+
[FINISHED] release [optimized] target(s) in [..]
1792+
",
1793+
)
1794+
.run();
1795+
}
1796+
17781797
#[cargo_test]
17791798
fn verbose_release_build_deps() {
17801799
let p = project()

tests/testsuite/run.rs

+23
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,29 @@ fn release_works() {
936936
assert!(p.release_bin("foo").is_file());
937937
}
938938

939+
#[cargo_test]
940+
fn release_short_works() {
941+
let p = project()
942+
.file(
943+
"src/main.rs",
944+
r#"
945+
fn main() { if cfg!(debug_assertions) { panic!() } }
946+
"#,
947+
)
948+
.build();
949+
950+
p.cargo("run -r")
951+
.with_stderr(
952+
"\
953+
[COMPILING] foo v0.0.1 ([CWD])
954+
[FINISHED] release [optimized] target(s) in [..]
955+
[RUNNING] `target/release/foo[EXE]`
956+
",
957+
)
958+
.run();
959+
assert!(p.release_bin("foo").is_file());
960+
}
961+
939962
#[cargo_test]
940963
fn run_bin_different_name() {
941964
let p = project()

0 commit comments

Comments
 (0)