Skip to content

Commit

Permalink
Add logging support & some preliminary logging
Browse files Browse the repository at this point in the history
This is just generally nice to have, and is already a transitive
dependency, so let's go ahead.
  • Loading branch information
cmyr committed Oct 13, 2023
1 parent 7754a4c commit 321f1d6
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ chrono = "0.4.6"
structopt = { version = "^0.3", default-features = false }
semver = "1.0"
termcolor = "1.0"
env_logger = "0.10.0"
log = "0.4.20"
9 changes: 8 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::opt::{AppConfig, CargoOpts, Target};
pub(crate) fn run(app_config: AppConfig) -> Result<()> {
// 1. Detect the type of Xcode Instruments installation
let xctrace_tool = instruments::XcodeInstruments::detect()?;
log::debug!("using {xctrace_tool}");

// 2. Render available templates if the user asked
if app_config.list_templates {
Expand All @@ -35,6 +36,8 @@ pub(crate) fn run(app_config: AppConfig) -> Result<()> {
None => important_paths::find_root_manifest_for_wd(cargo_config.cwd()),
}?;

log::debug!("using cargo manifest at {}", manifest_path.display());

let workspace = Workspace::new(&manifest_path, &cargo_config)?;

// 3.1: warn if --open passed. We do this here so we have access to cargo's
Expand All @@ -48,6 +51,8 @@ pub(crate) fn run(app_config: AppConfig) -> Result<()> {
}

let cargo_options = app_config.to_cargo_opts()?;

log::debug!("building profile target {}", cargo_options.target);
let target_filepath = match build_target(&cargo_options, &workspace) {
Ok(path) => path,
Err(e) => {
Expand All @@ -56,6 +61,8 @@ pub(crate) fn run(app_config: AppConfig) -> Result<()> {
}
};

log::debug!("running against target {}", target_filepath.display());

#[cfg(target_arch = "aarch64")]
codesign(&target_filepath, &workspace)?;

Expand Down Expand Up @@ -176,7 +183,7 @@ fn make_compile_opts(cargo_options: &CargoOpts, cfg: &Config) -> Result<CompileO
compile_options.cli_features = cargo_options.features.clone();
compile_options.spec = cargo_options.package.clone().into();

if cargo_options.target != Target::Main {
if cargo_options.target != Target::Default {
let (bins, examples, benches) = match &cargo_options.target {
Target::Bin(bin) => (vec![bin.clone()], vec![], vec![]),
Target::Example(bin) => (vec![], vec![bin.clone()], vec![]),
Expand Down
11 changes: 10 additions & 1 deletion src/instruments.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! interfacing with the `instruments` command line tool
use std::fmt::Write;
use std::fmt::{Display, Write};
use std::fs;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
Expand Down Expand Up @@ -485,6 +485,15 @@ fn get_tty() -> Result<Option<String>> {
.map(|tty| format!("/dev/{}", tty)))
}

impl Display for XcodeInstruments {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
XcodeInstruments::XcTrace => f.write_str("xctrace"),
XcodeInstruments::InstrumentsBinary => f.write_str("legacy instruments binary"),
}
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod opt;
compile_error!("cargo-instruments requires macOS.");

fn main() {
env_logger::init();
use structopt::StructOpt;
let opt::Cli::Instruments(args) = opt::Cli::from_args();

Expand Down
12 changes: 6 additions & 6 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub(crate) struct AppConfig {
/// Represents the kind of target to profile.
#[derive(Debug, PartialEq)]
pub(crate) enum Target {
Main,
Default,
Example(String),
Bin(String),
Bench(String),
Expand Down Expand Up @@ -151,10 +151,10 @@ impl fmt::Display for Package {
impl fmt::Display for Target {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Target::Main => write!(f, "src/main.rs"),
Target::Example(bin) => write!(f, "examples/{}.rs", bin),
Target::Bin(bin) => write!(f, "bin/{}.rs", bin),
Target::Bench(bench) => write!(f, "bench {}", bench),
Target::Default => write!(f, "default"),
Target::Example(bin) => write!(f, "{bin} (example)",),
Target::Bin(bin) => write!(f, "{bin} (bin)"),
Target::Bench(bench) => write!(f, "{bench} (bench)"),
}
}
}
Expand Down Expand Up @@ -201,7 +201,7 @@ impl AppConfig {
} else if let Some(ref bench) = self.bench {
Target::Bench(bench.clone())
} else {
Target::Main
Target::Default
}
}
}
Expand Down

0 comments on commit 321f1d6

Please sign in to comment.