forked from rust-lang/cargo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate libs also don't see artifact dependencies as libraries with …
…lib=false Also ---- - Add prelimiary test for validating build-time artifacts - Try to fix CI on gnu windows Which apparently generates paths similar to linux, but with .exe suffix. The current linux patterns should match that. - refactor Help sharing code across modules
- Loading branch information
Showing
4 changed files
with
172 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::core::compiler::unit_graph::UnitDep; | ||
use crate::core::compiler::{Context, CrateType, FileFlavor, Unit}; | ||
use crate::core::TargetKind; | ||
use crate::CargoResult; | ||
use cargo_util::ProcessBuilder; | ||
|
||
pub fn set_env( | ||
cx: &Context<'_, '_>, | ||
dependencies: &[UnitDep], | ||
cmd: &mut ProcessBuilder, | ||
) -> CargoResult<()> { | ||
for unit_dep in dependencies.iter().filter(|d| d.unit.artifact) { | ||
for artifact_path in cx | ||
.outputs(&unit_dep.unit)? | ||
.iter() | ||
.filter_map(|f| (f.flavor == FileFlavor::Normal).then(|| &f.path)) | ||
{ | ||
let artifact_type_upper = unit_artifact_type_name_upper(&unit_dep.unit); | ||
let dep_name_upper = unit_dep | ||
.dep_name | ||
.unwrap_or(unit_dep.unit.pkg.name()) | ||
.to_uppercase() | ||
.replace("-", "_"); | ||
cmd.env( | ||
&format!("CARGO_{}_DIR_{}", artifact_type_upper, dep_name_upper), | ||
artifact_path.parent().expect("parent dir for artifacts"), | ||
); | ||
cmd.env( | ||
&format!( | ||
"CARGO_{}_FILE_{}_{}", | ||
artifact_type_upper, | ||
dep_name_upper, | ||
unit_dep.unit.target.name() | ||
), | ||
artifact_path, | ||
); | ||
if unit_dep.unit.target.name().to_uppercase() == dep_name_upper { | ||
cmd.env( | ||
&format!("CARGO_{}_FILE_{}", artifact_type_upper, dep_name_upper,), | ||
artifact_path, | ||
); | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn unit_artifact_type_name_upper(unit: &Unit) -> &'static str { | ||
match unit.target.kind() { | ||
TargetKind::Lib(kinds) => match kinds.as_slice() { | ||
&[CrateType::Cdylib] => "CDYLIB", | ||
&[CrateType::Staticlib] => "STATICLIB", | ||
invalid => unreachable!("BUG: artifacts cannot be of type {:?}", invalid), | ||
}, | ||
TargetKind::Bin => "BIN", | ||
invalid => unreachable!("BUG: artifacts cannot be of type {:?}", invalid), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters