Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Add host link path in rustc invocations to reenable rmpv testcase #291

Merged
merged 3 commits into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 44 additions & 21 deletions src/bin/cargo-semver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
let mut child = Command::new("rust-semver-public");
child
.arg("--crate-type=lib")
.args(&["--extern", &*format!("new={}", current_rlib.display())])
.args(&[format!("-L{}", current_deps_output.display())]);
.args(&["--extern", &*format!("new={}", current_rlib.display())]);

for link_path in current_deps_output {
child.args(&[format!("-L{}", link_path.display())]);
}

if let Some(target) = matches.opt_str("target") {
child.args(&["--target", &target]);
Expand Down Expand Up @@ -195,13 +198,16 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
stable.rlib_and_dep_output(config, &name, false, matches)?;

if matches.opt_present("d") {
println!(
"--extern old={} -L{} --extern new={} -L{}",
stable_rlib.display(),
stable_deps_output.display(),
current_rlib.display(),
current_deps_output.display()
);
print!("--extern old={} ", stable_rlib.display());
for link_path in stable_deps_output {
print!("-L {} ", link_path.display());
}
print!("--extern new={}", current_rlib.display());
for link_path in current_deps_output {
print!("-L {} ", link_path.display());
}
println!();

return Ok(());
}

Expand All @@ -210,10 +216,14 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
let mut child = Command::new("rust-semverver");
child
.arg("--crate-type=lib")
.args(&["--extern", &*format!("old={}", stable_rlib.display())])
.args(&[format!("-L{}", stable_deps_output.display())])
.args(&["--extern", &*format!("new={}", current_rlib.display())])
.args(&[format!("-L{}", current_deps_output.display())]);
.args(&["--extern", &*format!("old={}", stable_rlib.display())]);
for link_path in stable_deps_output {
child.args(&[format!("-L{}", link_path.display())]);
}
child.args(&["--extern", &*format!("new={}", current_rlib.display())]);
for link_path in current_deps_output {
child.args(&[format!("-L{}", link_path.display())]);
}

if let Some(target) = matches.opt_str("target") {
child.args(&["--target", &target]);
Expand All @@ -235,6 +245,8 @@ fn run(config: &cargo::Config, matches: &getopts::Matches) -> Result<()> {
},
);

debug!("rust-semverver invocation: {:?}", child);

let mut child = child
.spawn()
.map_err(|e| anyhow::Error::msg(format!("could not spawn rustc: {}", e)))?;
Expand Down Expand Up @@ -474,7 +486,7 @@ impl<'a> WorkInfo<'a> {
name: &str,
current: bool,
matches: &getopts::Matches,
) -> Result<(PathBuf, PathBuf)> {
) -> Result<(PathBuf, Vec<PathBuf>)> {
// We don't need codegen-ready artifacts (which .rlib files are) so
// settle for .rmeta files, which result from `cargo check` mode
let mode = cargo::core::compiler::CompileMode::Check { test: false };
Expand Down Expand Up @@ -531,18 +543,29 @@ impl<'a> WorkInfo<'a> {
let build_plan: BuildPlan = serde_json::from_slice(&plan_output)
.map_err(|_| anyhow::anyhow!("Can't read build plan"))?;

// TODO: handle multiple outputs gracefully
for i in &build_plan.invocations {
debug!("{:?}", &build_plan.invocations);
let paths = build_plan.invocations.iter().find_map(|i| {
if let Some(kind) = i.target_kind.get(0) {
if kind.contains("lib") && i.package_name == name {
let deps_output = &compilation.deps_output[&compile_kind];

return Ok((i.outputs[0].clone(), deps_output.clone()));
let rlib_path = i.outputs[0].clone();
let mut link_paths = vec![
compilation.deps_output[&compile_kind].clone(),
compilation.deps_output[&cargo::core::compiler::CompileKind::Host].clone(),
];
// if host and `compile_kind` are the same, only return once
link_paths.dedup();
return Some((rlib_path, link_paths));
}
}
}

Err(anyhow::Error::msg("lost build artifact".to_owned()))
None
});

if let Some(paths) = paths {
Ok(paths)
} else {
Err(anyhow::Error::msg("lost build artifact".to_owned()))
}
}
}

Expand Down
11 changes: 5 additions & 6 deletions tests/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ mod full {
};

fn test_full(crate_name: &str, old_version: &str, new_version: &str, expected_result: bool) {
// FIXME: CI started to fail since 2022-04-25, ignore the rmpv test on CI for now.
if crate_name == "rmpv" && env::var_os("CI").unwrap_or_default() == "true" {
return;
}

// Add target dir to PATH so cargo-semver will call the right rust-semverver
if let Some(path) = env::var_os("PATH") {
let mut paths = env::split_paths(&path).collect::<Vec<_>>();
Expand Down Expand Up @@ -94,14 +89,18 @@ mod full {
.expect("could not read line from rust-semverver output")
.trim_end();

let has_expected_line = stdout.lines().any(|l| l.starts_with("version bump"));

stdout
.lines()
.chain(stderr.lines())
.map(|l| l.trim_end())
.skip_while(|line|
// skip everything before the first important bit of info
!line.starts_with("version bump") &&
// ...unless debugging is enabled
// ...if we know it's in there at all
has_expected_line &&
// ...unless debugging is enabled, then always show
!log_enabled!(Level::Debug))
.map(|line| {
// sanitize paths for reproducibility
Expand Down