Skip to content

Commit

Permalink
Be more explicit about what cargo is doing
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Jan 29, 2022
1 parent 854a989 commit 4c710d4
Show file tree
Hide file tree
Showing 27 changed files with 184 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [push, pull_request]
on: [pull_request, push, workflow_dispatch]

concurrency:
group: ci-${{ github.ref }}
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion cargo-dylint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ pub struct Dylint {
#[clap(
short,
long,
help = "Do not show warnings or progress running commands besides `cargo check`"
help = "Do not show warnings or progress running commands besides `cargo check` and \
`cargo fix`"
)]
pub quiet: bool,

Expand Down
13 changes: 8 additions & 5 deletions cargo-dylint/tests/custom_toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ mod custom_toolchain {

patch_dylint_template(tempdir.path(), &custom_toolchain).unwrap();

dylint_internal::test()
.sanitize_environment()
.current_dir(tempdir.path())
.success()
.unwrap();
dylint_internal::test(
&format!("with custom toolchain `{}`", custom_toolchain),
false,
)
.sanitize_environment()
.current_dir(tempdir.path())
.success()
.unwrap();

uninstall_toolchain(&custom_toolchain).unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion cargo-dylint/tests/dylint_driver_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn dylint_driver_path() {

create_dir_all(&dylint_driver_path).unwrap();

dylint_internal::test()
dylint_internal::test("dylint-template", false)
.sanitize_environment()
.current_dir(tempdir.path())
.envs(vec![(
Expand Down
52 changes: 32 additions & 20 deletions cargo-dylint/tests/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,24 @@ fn one_name_multiple_toolchains() {
dylint_internal::clone_dylint_template(tempdir.path()).unwrap();

patch_dylint_template(tempdir.path(), CHANNEL_A, CLIPPY_UTILS_TAG_A).unwrap();
dylint_internal::build()
.sanitize_environment()
.current_dir(tempdir.path())
.success()
.unwrap();
dylint_internal::build(
&format!("dylint-template with channel `{}`", CHANNEL_A),
false,
)
.sanitize_environment()
.current_dir(tempdir.path())
.success()
.unwrap();

patch_dylint_template(tempdir.path(), CHANNEL_B, CLIPPY_UTILS_TAG_B).unwrap();
dylint_internal::build()
.sanitize_environment()
.current_dir(tempdir.path())
.success()
.unwrap();
dylint_internal::build(
&format!("dylint-template with channel `{}`", CHANNEL_B),
false,
)
.sanitize_environment()
.current_dir(tempdir.path())
.success()
.unwrap();

std::process::Command::cargo_bin("cargo-dylint")
.unwrap()
Expand Down Expand Up @@ -81,17 +87,23 @@ fn one_name_multiple_paths() {
dylint_internal::clone_dylint_template(tempdirs.0.path()).unwrap();
dylint_internal::clone_dylint_template(tempdirs.1.path()).unwrap();

dylint_internal::build()
.sanitize_environment()
.current_dir(tempdirs.0.path())
.success()
.unwrap();
dylint_internal::build(
&format!("dylint-template in {:?}", tempdirs.0.path()),
false,
)
.sanitize_environment()
.current_dir(tempdirs.0.path())
.success()
.unwrap();

dylint_internal::build()
.sanitize_environment()
.current_dir(tempdirs.1.path())
.success()
.unwrap();
dylint_internal::build(
&format!("dylint-template in {:?}", tempdirs.1.path()),
false,
)
.sanitize_environment()
.current_dir(tempdirs.1.path())
.success()
.unwrap();

let paths = join_paths(&[
&target_debug(tempdirs.0.path()).unwrap(),
Expand Down
57 changes: 34 additions & 23 deletions cargo-dylint/tests/package_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ fn new_package() {
.assert()
.success();

dylint_internal::build()
dylint_internal::build("filled-in dylint-template", false)
.sanitize_environment()
.current_dir(&path)
.success()
.unwrap();

dylint_internal::test()
dylint_internal::test("filled-in dylint-template", false)
.sanitize_environment()
.current_dir(&path)
.success()
Expand Down Expand Up @@ -62,37 +62,48 @@ fn downgrade_upgrade_package() {

upgrade().args(&["--force"]).assert().success();

dylint_internal::build()
dylint_internal::build("downgraded dylint-template", false)
.sanitize_environment()
.current_dir(tempdir.path())
.success()
.unwrap();

dylint_internal::test()
dylint_internal::test("downgraded dylint-template", false)
.sanitize_environment()
.current_dir(tempdir.path())
.success()
.unwrap();

std::process::Command::cargo_bin("cargo-dylint")
.unwrap()
.args(&["dylint", "--upgrade", &tempdir.path().to_string_lossy()])
.assert()
.success();

// smoelius: Right now, dylint-template does not build with nightly-2021-10-07. So
// dylint-template's rust-toolchain file is ahead of Clippy 1.57.0's by a few days.
/* dylint_internal::build()
.sanitize_environment()
.current_dir(tempdir.path())
.success()
.unwrap();
dylint_internal::test()
.sanitize_environment()
.current_dir(tempdir.path())
.success()
.unwrap(); */
if cfg!(not(unix)) {
std::process::Command::cargo_bin("cargo-dylint")
.unwrap()
.args(&["dylint", "--upgrade", &tempdir.path().to_string_lossy()])
.assert()
.success();
} else {
std::process::Command::cargo_bin("cargo-dylint")
.unwrap()
.args(&[
"dylint",
"--upgrade",
&tempdir.path().to_string_lossy(),
"--bisect",
])
.assert()
.success();

dylint_internal::build("upgraded dylint-template", false)
.sanitize_environment()
.current_dir(tempdir.path())
.success()
.unwrap();

dylint_internal::test("upgraded dylint-template", false)
.sanitize_environment()
.current_dir(tempdir.path())
.success()
.unwrap();
}
}

fn rust_version(path: &Path) -> Result<Version> {
Expand Down
10 changes: 10 additions & 0 deletions driver/Cargo.lock

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

11 changes: 3 additions & 8 deletions dylint/src/driver_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{
env::consts,
fs::{copy, create_dir_all, write},
path::{Path, PathBuf},
process::Stdio,
};
use tempfile::tempdir;

Expand Down Expand Up @@ -160,15 +159,11 @@ fn build(opts: &crate::Dylint, toolchain: &str, driver: &Path) -> Result<()> {
toolchain_path.to_string_lossy()
);

let mut command = dylint_internal::build();
command
dylint_internal::build(&format!("driver for toolchain `{}`", toolchain), opts.quiet)
.sanitize_environment()
.envs(vec![(env::RUSTFLAGS, rustflags)])
.current_dir(&package);
if opts.quiet {
command.stderr(Stdio::null());
}
command.success()?;
.current_dir(&package)
.success()?;

let binary = metadata.target_directory.join("debug").join(format!(
"dylint_driver-{}{}",
Expand Down
5 changes: 3 additions & 2 deletions dylint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,11 @@ fn check_or_fix(
let target_dir_str = target_dir.to_string_lossy();
let driver = driver_builder::get(opts, toolchain)?;
let dylint_libs = serde_json::to_string(&paths)?;
let description = format!("with toolchain `{}`", toolchain);
let mut command = if opts.fix {
dylint_internal::fix()
dylint_internal::fix(&description)
} else {
dylint_internal::check()
dylint_internal::check(&description)
};
let mut args = vec!["--target-dir", &target_dir_str];
if let Some(path) = &opts.manifest_path {
Expand Down
22 changes: 9 additions & 13 deletions dylint/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ use glob::glob;
use if_chain::if_chain;
use serde::Deserialize;
use serde_json::{Map, Value};
use std::{
path::{Path, PathBuf},
process::Stdio,
};
use std::path::{Path, PathBuf};

#[derive(Debug, Deserialize)]
struct Library {
Expand Down Expand Up @@ -294,15 +291,14 @@ fn package_library_path(
let target_dir = target_dir(metadata, package_root, package_id)?;

if !opts.no_build {
let mut command = dylint_internal::build();
command
.sanitize_environment()
.current_dir(package_root)
.args(&["--release", "--target-dir", &target_dir.to_string_lossy()]);
if opts.quiet {
command.stderr(Stdio::null());
}
command.success()?;
dylint_internal::build(
&format!("workspace metadata entry `{}`", package_id.name()),
opts.quiet,
)
.sanitize_environment()
.current_dir(package_root)
.args(&["--release", "--target-dir", &target_dir.to_string_lossy()])
.success()?;
}

Ok(target_dir.join("release"))
Expand Down
33 changes: 19 additions & 14 deletions dylint/src/package_options/bisect.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::Dylint;
use anyhow::{Context, Result};
use dylint_internal::Command;
use std::os::unix::fs::PermissionsExt;
use std::{
fs::{remove_file, rename},
io::Write,
path::Path,
process::Stdio,
};
use tempfile::NamedTempFile;

Expand Down Expand Up @@ -58,7 +60,7 @@ const TEMPORARY_FILES: &[&str] = &[
"successful_build_seen",
];

pub fn bisect(path: &Path, start: &str) -> Result<()> {
pub fn bisect(opts: &Dylint, path: &Path, start: &str) -> Result<()> {
Command::new("cargo")
.args(&["bisect-rustc", "-V"])
.success()
Expand All @@ -72,19 +74,22 @@ pub fn bisect(path: &Path, start: &str) -> Result<()> {

remove_temporary_files(path);

let result = Command::new("cargo")
.args(&[
"bisect-rustc",
"--start",
start,
"--preserve",
"--regress=success",
"--script",
&*script.path().to_string_lossy(),
"--test-dir",
&*test_dir.to_string_lossy(),
])
.success();
let mut command = Command::new("cargo");
command.args(&[
"bisect-rustc",
"--start",
start,
"--preserve",
"--regress=success",
"--script",
&*script.path().to_string_lossy(),
"--test-dir",
&*test_dir.to_string_lossy(),
]);
if opts.quiet {
command.stderr(Stdio::null());
}
let result = command.success();

remove_temporary_files(path);

Expand Down
11 changes: 8 additions & 3 deletions dylint/src/package_options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,17 @@ pub fn upgrade_package(opts: &Dylint, path: &Path) -> Result<()> {

#[cfg(unix)]
if opts.bisect {
dylint_internal::update()
let file_name = path
.file_name()
.ok_or_else(|| anyhow!("Could not get file name"))?;
let description = format!("`{}`", file_name.to_string_lossy());

dylint_internal::update(&description, opts.quiet)
.sanitize_environment()
.current_dir(path)
.success()?;

if dylint_internal::build()
if dylint_internal::build(&description, opts.quiet)
.sanitize_environment()
.current_dir(path)
.args(&["--tests"])
Expand All @@ -253,7 +258,7 @@ pub fn upgrade_package(opts: &Dylint, path: &Path) -> Result<()> {

let start = new_nightly.format("%Y-%m-%d").to_string();

bisect::bisect(path, &start)?;
bisect::bisect(opts, path, &start)?;
}
}

Expand Down
Loading

0 comments on commit 4c710d4

Please sign in to comment.