internal: Don't log default build script outputs

This commit is contained in:
Lukas Wirth 2022-06-03 13:50:49 +02:00
parent 4f5c7aafff
commit d0e3114441
2 changed files with 29 additions and 20 deletions

View File

@ -18,7 +18,7 @@ use crate::{cfg_flag::CfgFlag, CargoConfig, CargoWorkspace, Package};
#[derive(Debug, Default, Clone, PartialEq, Eq)] #[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct WorkspaceBuildScripts { pub struct WorkspaceBuildScripts {
pub(crate) outputs: ArenaMap<Package, BuildScriptOutput>, outputs: ArenaMap<Package, Option<BuildScriptOutput>>,
error: Option<String>, error: Option<String>,
} }
@ -72,6 +72,7 @@ impl WorkspaceBuildScripts {
cmd cmd
} }
pub(crate) fn run( pub(crate) fn run(
config: &CargoConfig, config: &CargoConfig,
workspace: &CargoWorkspace, workspace: &CargoWorkspace,
@ -91,13 +92,13 @@ impl WorkspaceBuildScripts {
cmd.current_dir(workspace.workspace_root()); cmd.current_dir(workspace.workspace_root());
let mut res = WorkspaceBuildScripts::default(); let mut res = WorkspaceBuildScripts::default();
let outputs = &mut res.outputs;
// NB: Cargo.toml could have been modified between `cargo metadata` and // NB: Cargo.toml could have been modified between `cargo metadata` and
// `cargo check`. We shouldn't assume that package ids we see here are // `cargo check`. We shouldn't assume that package ids we see here are
// exactly those from `config`. // exactly those from `config`.
let mut by_id: FxHashMap<String, Package> = FxHashMap::default(); let mut by_id: FxHashMap<String, Package> = FxHashMap::default();
for package in workspace.packages() { for package in workspace.packages() {
res.outputs.insert(package, BuildScriptOutput::default()); outputs.insert(package, None);
by_id.insert(workspace[package].id.clone(), package); by_id.insert(workspace[package].id.clone(), package);
} }
@ -141,7 +142,8 @@ impl WorkspaceBuildScripts {
} }
acc acc
}; };
let package_build_data = &mut res.outputs[package]; let package_build_data =
outputs[package].get_or_insert_with(Default::default);
// cargo_metadata crate returns default (empty) path for // cargo_metadata crate returns default (empty) path for
// older cargos, which is not absolute, so work around that. // older cargos, which is not absolute, so work around that.
if !message.out_dir.as_str().is_empty() { if !message.out_dir.as_str().is_empty() {
@ -167,7 +169,9 @@ impl WorkspaceBuildScripts {
message.filenames.iter().find(|name| is_dylib(name)) message.filenames.iter().find(|name| is_dylib(name))
{ {
let filename = AbsPathBuf::assert(PathBuf::from(&filename)); let filename = AbsPathBuf::assert(PathBuf::from(&filename));
res.outputs[package].proc_macro_dylib_path = Some(filename); outputs[package]
.get_or_insert_with(Default::default)
.proc_macro_dylib_path = Some(filename);
} }
} }
} }
@ -189,17 +193,18 @@ impl WorkspaceBuildScripts {
)?; )?;
for package in workspace.packages() { for package in workspace.packages() {
let package_build_data = &mut res.outputs[package]; if let Some(package_build_data) = &mut outputs[package] {
tracing::info!( tracing::info!(
"{} BuildScriptOutput: {:?}", "{} BuildScriptOutput: {:?}",
workspace[package].manifest.parent().display(), workspace[package].manifest.parent().display(),
package_build_data, package_build_data,
); );
// inject_cargo_env(package, package_build_data); // inject_cargo_env(package, package_build_data);
if let Some(out_dir) = &package_build_data.out_dir { if let Some(out_dir) = &package_build_data.out_dir {
// NOTE: cargo and rustc seem to hide non-UTF-8 strings from env! and option_env!() // NOTE: cargo and rustc seem to hide non-UTF-8 strings from env! and option_env!()
if let Some(out_dir) = out_dir.as_os_str().to_str().map(|s| s.to_owned()) { if let Some(out_dir) = out_dir.as_os_str().to_str().map(|s| s.to_owned()) {
package_build_data.envs.push(("OUT_DIR".to_string(), out_dir)); package_build_data.envs.push(("OUT_DIR".to_string(), out_dir));
}
} }
} }
} }
@ -218,6 +223,10 @@ impl WorkspaceBuildScripts {
pub fn error(&self) -> Option<&str> { pub fn error(&self) -> Option<&str> {
self.error.as_deref() self.error.as_deref()
} }
pub(crate) fn get_output(&self, idx: Package) -> Option<&BuildScriptOutput> {
self.outputs.get(idx)?.as_ref()
}
} }
// FIXME: File a better way to know if it is a dylib. // FIXME: File a better way to know if it is a dylib.

View File

@ -312,9 +312,9 @@ impl ProjectWorkspace {
let pkg_root = cargo[pkg].manifest.parent().to_path_buf(); let pkg_root = cargo[pkg].manifest.parent().to_path_buf();
let mut include = vec![pkg_root.clone()]; let mut include = vec![pkg_root.clone()];
include.extend( let out_dir =
build_scripts.outputs.get(pkg).and_then(|it| it.out_dir.clone()), build_scripts.get_output(pkg).and_then(|it| it.out_dir.clone());
); include.extend(out_dir);
// In case target's path is manually set in Cargo.toml to be // In case target's path is manually set in Cargo.toml to be
// outside the package root, add its parent as an extra include. // outside the package root, add its parent as an extra include.
@ -586,7 +586,7 @@ fn cargo_to_crate_graph(
let crate_id = add_target_crate_root( let crate_id = add_target_crate_root(
&mut crate_graph, &mut crate_graph,
&cargo[pkg], &cargo[pkg],
build_scripts.outputs.get(pkg), build_scripts.get_output(pkg),
cfg_options, cfg_options,
&mut |path| load_proc_macro(&cargo[tgt].name, path), &mut |path| load_proc_macro(&cargo[tgt].name, path),
file_id, file_id,