Skip to content

Commit 9e4136f

Browse files
committed
associate CROSS_DEBUG with MessageInfo
print line of source for message if `CROSS_DEBUG=1` don't make `CROSS_DEBUG=1` mean verbosity = verbosity.level() + 1
1 parent 08acc54 commit 9e4136f

File tree

6 files changed

+81
-22
lines changed

6 files changed

+81
-22
lines changed

src/bin/commands/images.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::{BTreeMap, BTreeSet};
22

3+
use clap::builder::PossibleValue;
34
use clap::{Args, Subcommand};
45
use cross::docker::{self, CROSS_CUSTOM_DOCKERFILE_IMAGE_PREFIX};
56
use cross::shell::MessageInfo;
@@ -50,10 +51,10 @@ impl clap::ValueEnum for OutputFormat {
5051
&[Self::Human, Self::Json]
5152
}
5253

53-
fn to_possible_value<'a>(&self) -> Option<clap::PossibleValue<'a>> {
54+
fn to_possible_value(&self) -> Option<PossibleValue> {
5455
match self {
55-
OutputFormat::Human => Some(clap::PossibleValue::new("human")),
56-
OutputFormat::Json => Some(clap::PossibleValue::new("json")),
56+
OutputFormat::Human => Some(PossibleValue::new("human")),
57+
OutputFormat::Json => Some(PossibleValue::new("json")),
5758
}
5859
}
5960
}

src/bin/cross.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ pub fn main() -> cross::Result<()> {
1818
let target_list = rustc::target_list(&mut Verbosity::Quiet.into())?;
1919
let args = cli::parse(&target_list)?;
2020
let subcommand = args.subcommand;
21-
let mut msg_info = shell::MessageInfo::create(
22-
args.verbose
23-
+ cross::config::bool_from_envvar(&std::env::var("CROSS_DEBUG").unwrap_or_default())
24-
as u8,
25-
args.quiet,
26-
args.color.as_deref(),
27-
)?;
21+
let mut msg_info = shell::MessageInfo::create(args.verbose, args.quiet, args.color.as_deref())?;
2822
let status = match cross::run(args, target_list, &mut msg_info)? {
2923
Some(status) => status,
3024
None => {

src/docker/remote.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ macro_rules! bail_container_exited {
2929
}};
3030
}
3131

32+
#[track_caller]
3233
fn subcommand_or_exit(engine: &Engine, cmd: &str) -> Result<Command> {
3334
bail_container_exited!();
3435
Ok(engine.subcommand(cmd))
@@ -42,6 +43,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
4243
// NOTE: `reldir` should be a relative POSIX path to the root directory
4344
// on windows, this should be something like `mnt/c`. that is, all paths
4445
// inside the container should not have the mount prefix.
46+
#[track_caller]
4547
fn create_dir(
4648
&self,
4749
reldir: &str,
@@ -57,6 +59,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
5759

5860
// copy files for a docker volume, for remote host support
5961
// NOTE: `reldst` has the same caveats as `reldir` in `create_dir`.
62+
#[track_caller]
6063
fn copy_files(
6164
&self,
6265
src: &Path,
@@ -72,6 +75,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
7275
}
7376

7477
// copy files for a docker volume, for remote host support
78+
#[track_caller]
7579
fn copy_files_nocache(
7680
&self,
7781
src: &Path,
@@ -92,6 +96,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
9296

9397
// copy files for a docker volume, for remote host support
9498
// provides a list of files relative to src.
99+
#[track_caller]
95100
fn copy_file_list(
96101
&self,
97102
src: &Path,
@@ -116,6 +121,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
116121

117122
// removed files from a docker volume, for remote host support
118123
// provides a list of files relative to src.
124+
#[track_caller]
119125
fn remove_file_list(
120126
&self,
121127
reldst: &str,
@@ -156,6 +162,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
156162
.run_and_get_status(msg_info, true)
157163
}
158164

165+
#[track_caller]
159166
fn container_path_exists(
160167
&self,
161168
relpath: &str,
@@ -173,6 +180,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
173180
.success())
174181
}
175182

183+
#[track_caller]
176184
pub fn copy_xargo(&self, mount_prefix: &str, msg_info: &mut MessageInfo) -> Result<()> {
177185
let dirs = &self.toolchain_dirs;
178186
let reldst = dirs.xargo_mount_path_relative()?;
@@ -194,6 +202,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
194202
Ok(())
195203
}
196204

205+
#[track_caller]
197206
pub fn copy_cargo(
198207
&self,
199208
mount_prefix: &str,
@@ -230,6 +239,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
230239
}
231240

232241
// copy over files needed for all targets in the toolchain that should never change
242+
#[track_caller]
233243
fn copy_rust_base(&self, mount_prefix: &str, msg_info: &mut MessageInfo) -> Result<()> {
234244
let dirs = &self.toolchain_dirs;
235245

@@ -273,6 +283,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
273283
warn_symlinks(had_symlinks, msg_info)
274284
}
275285

286+
#[track_caller]
276287
fn copy_rust_manifest(&self, mount_prefix: &str, msg_info: &mut MessageInfo) -> Result<()> {
277288
let dirs = &self.toolchain_dirs;
278289

@@ -298,6 +309,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
298309
}
299310

300311
// copy over the toolchain for a specific triple
312+
#[track_caller]
301313
fn copy_rust_triple(
302314
&self,
303315
target_triple: &TargetTriple,
@@ -335,6 +347,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
335347
Ok(())
336348
}
337349

350+
#[track_caller]
338351
pub fn copy_rust(
339352
&self,
340353
target_triple: Option<&TargetTriple>,
@@ -355,6 +368,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
355368
Ok(())
356369
}
357370

371+
#[track_caller]
358372
fn copy_mount(
359373
&self,
360374
src: &Path,

src/docker/shared.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,22 +696,26 @@ impl<'a, 'b> DockerVolume<'a, 'b> {
696696
Self { engine, name }
697697
}
698698

699+
#[track_caller]
699700
pub fn create(&self, msg_info: &mut MessageInfo) -> Result<ExitStatus> {
700701
self.engine
701702
.run_and_get_status(&["volume", "create", self.name], msg_info)
702703
}
703704

705+
#[track_caller]
704706
pub fn remove(&self, msg_info: &mut MessageInfo) -> Result<ExitStatus> {
705707
self.engine
706708
.run_and_get_status(&["volume", "rm", self.name], msg_info)
707709
}
708710

711+
#[track_caller]
709712
pub fn exists(&self, msg_info: &mut MessageInfo) -> Result<bool> {
710713
self.engine
711714
.run_and_get_output(&["volume", "inspect", self.name], msg_info)
712715
.map(|output| output.status.success())
713716
}
714717

718+
#[track_caller]
715719
pub fn existing(
716720
engine: &Engine,
717721
toolchain: &QualifiedToolchain,
@@ -834,6 +838,7 @@ impl Engine {
834838
command
835839
}
836840

841+
#[track_caller]
837842
pub(crate) fn run_and_get_status(
838843
&self,
839844
args: &[&str],
@@ -842,6 +847,7 @@ impl Engine {
842847
self.command().args(args).run_and_get_status(msg_info, true)
843848
}
844849

850+
#[track_caller]
845851
pub(crate) fn run_and_get_output(
846852
&self,
847853
args: &[&str],

src/extensions.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ pub const STRIPPED_BINS: &[&str] = &[crate::docker::DOCKER, crate::docker::PODMA
1010
pub trait CommandExt {
1111
fn fmt_message(&self, msg_info: &mut MessageInfo) -> String;
1212

13+
#[track_caller]
1314
fn print(&self, msg_info: &mut MessageInfo) -> Result<()> {
1415
let msg = self.fmt_message(msg_info);
1516
msg_info.print(&msg)
1617
}
1718

19+
#[track_caller]
1820
fn info(&self, msg_info: &mut MessageInfo) -> Result<()> {
1921
let msg = self.fmt_message(msg_info);
2022
msg_info.info(&msg)
2123
}
2224

25+
#[track_caller]
2326
fn debug(&self, msg_info: &mut MessageInfo) -> Result<()> {
2427
let msg = self.fmt_message(msg_info);
2528
msg_info.debug(&msg)
@@ -31,13 +34,17 @@ pub trait CommandExt {
3134
status: ExitStatus,
3235
output: Option<&Output>,
3336
) -> Result<(), CommandError>;
37+
#[track_caller]
3438
fn run(&mut self, msg_info: &mut MessageInfo, silence_stdout: bool) -> Result<()>;
39+
#[track_caller]
3540
fn run_and_get_status(
3641
&mut self,
3742
msg_info: &mut MessageInfo,
3843
silence_stdout: bool,
3944
) -> Result<ExitStatus>;
45+
#[track_caller]
4046
fn run_and_get_stdout(&mut self, msg_info: &mut MessageInfo) -> Result<String>;
47+
#[track_caller]
4148
fn run_and_get_output(&mut self, msg_info: &mut MessageInfo) -> Result<std::process::Output>;
4249
fn command_pretty(
4350
&self,
@@ -84,20 +91,33 @@ impl CommandExt for Command {
8491
format!("{}", C(self, msg_info, strip))
8592
}
8693

94+
#[track_caller]
8795
fn fmt_message(&self, mut msg_info: &mut MessageInfo) -> String {
96+
use std::fmt::Write;
8897
let msg_info = &mut msg_info;
98+
let mut string = String::new();
99+
if let Some(caller) = msg_info.caller() {
100+
write!(string, "[{}] ->\n+ ", caller).unwrap();
101+
} else {
102+
write!(string, "+ ").unwrap();
103+
};
89104
if let Some(cwd) = self.get_current_dir() {
90-
format!(
91-
"+ {:?} {}",
105+
write!(
106+
string,
107+
"{:?} {}",
92108
cwd,
93109
msg_info.as_verbose(|info| self.command_pretty(info, |_| false))
94110
)
111+
.unwrap();
95112
} else {
96-
format!(
97-
"+ {}",
113+
write!(
114+
string,
115+
"{}",
98116
msg_info.as_verbose(|info| self.command_pretty(info, |_| false))
99117
)
118+
.unwrap();
100119
}
120+
string
101121
}
102122

103123
fn status_result(
@@ -127,6 +147,7 @@ impl CommandExt for Command {
127147
}
128148

129149
/// Runs the command to completion
150+
#[track_caller]
130151
fn run_and_get_status(
131152
&mut self,
132153
msg_info: &mut MessageInfo,
@@ -146,6 +167,7 @@ impl CommandExt for Command {
146167
}
147168

148169
/// Runs the command to completion and returns its stdout
170+
#[track_caller]
149171
fn run_and_get_stdout(&mut self, msg_info: &mut MessageInfo) -> Result<String> {
150172
let out = self.run_and_get_output(msg_info)?;
151173
self.status_result(msg_info, out.status, Some(&out))
@@ -158,6 +180,7 @@ impl CommandExt for Command {
158180
/// # Notes
159181
///
160182
/// This command does not check the status.
183+
#[track_caller]
161184
fn run_and_get_output(&mut self, msg_info: &mut MessageInfo) -> Result<std::process::Output> {
162185
self.debug(msg_info)?;
163186
self.output().map_err(|e| {

0 commit comments

Comments
 (0)