Skip to content

Commit

Permalink
Finishing up.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch committed Mar 8, 2022
1 parent 8399a88 commit d361169
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ use std::process::Command;

#[derive(Debug)]
pub struct Subcommand {
args: Args,
package: String,
manifest: PathBuf,
target_dir: PathBuf,
target: Option<String>,
host_triple: String,
profile: Profile,
artifacts: Vec<Artifact>,
quiet: bool,
config: Option<LocalizedConfig>,
lib_name: Option<String>,
}
Expand Down Expand Up @@ -95,19 +94,22 @@ impl Subcommand {
.ok_or(Error::RustcNotFound)?;
let profile = args.profile();
Ok(Self {
args,
package,
manifest: manifest_path,
target_dir,
target: args.target,
host_triple,
profile,
artifacts,
quiet: args.quiet,
config,
lib_name: manifest.lib.unwrap_or_default().name,
})
}

pub fn args(&self) -> &Args {
&self.args
}

pub fn package(&self) -> &str {
&self.package
}
Expand All @@ -117,7 +119,7 @@ impl Subcommand {
}

pub fn target(&self) -> Option<&str> {
self.target.as_deref()
self.args.target.as_deref()
}

pub fn profile(&self) -> &Profile {
Expand All @@ -137,27 +139,36 @@ impl Subcommand {
}

pub fn quiet(&self) -> bool {
self.quiet
self.args.quiet
}

pub fn config(&self) -> Option<&LocalizedConfig> {
self.config.as_ref()
}

pub fn artifact(&self, artifact: Artifact, crate_type: CrateType) -> PathBuf {
let target = self.target().unwrap_or_else(|| self.host_triple());
pub fn build_dir(&self, target: Option<&str>) -> PathBuf {
let target_dir = dunce::simplified(self.target_dir()).to_path_buf();
let arch_dir = if let Some(target) = target {
target_dir.join(target)
} else {
target_dir
};
arch_dir.join(self.profile())
}

pub fn artifact(
&self,
artifact: &Artifact,
target: Option<&str>,
crate_type: CrateType,
) -> PathBuf {
let triple = target.unwrap_or_else(|| self.host_triple());
let name = if crate_type.is_lib() {
self.lib_name.as_deref()
} else {
None
};
let file_name = artifact.file_name(name, crate_type, target);
let target_dir = self.target_dir.clone();
let arch_dir = if let Some(target) = self.target() {
target_dir.join(target)
} else {
target_dir
};
arch_dir.join(self.profile()).join(artifact).join(file_name)
let file_name = artifact.file_name(name, crate_type, triple);
self.build_dir(target).join(artifact).join(file_name)
}
}

0 comments on commit d361169

Please sign in to comment.