-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
145 additions
and
96 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "expensive" | ||
version = "3.1.2" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dev-dependencies] | ||
anyhow = "1.0" | ||
tempfile = "3.12" | ||
|
||
dylint_internal = { version = "=3.1.2", path = "../internal", features = [ | ||
"clippy_utils", | ||
"rustup", | ||
"sed", | ||
"testing", | ||
] } | ||
|
||
[lints] | ||
workspace = true |
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// smoelius: As per `dylint-link/src/main.rs`: | ||
// "Only the MSVC toolchain is supported on Windows" | ||
#![cfg(not(target_os = "windows"))] | ||
|
||
use anyhow::{anyhow, Context, Result}; | ||
use dylint_internal::{ | ||
clippy_utils::set_toolchain_channel, find_and_replace, rustup::SanitizeEnvironment, | ||
testing::new_template, CommandExt, | ||
}; | ||
use std::{path::Path, process::Command}; | ||
use tempfile::{tempdir, NamedTempFile, TempDir}; | ||
|
||
const RUST_URL: &str = "https://github.com/rust-lang/rust"; | ||
|
||
#[test] | ||
fn custom_toolchain() { | ||
let tempdir = tempdir().unwrap(); | ||
|
||
new_template(tempdir.path()).unwrap(); | ||
|
||
let (_toolchain_dir, custom_toolchain) = build_custom_toolchain().unwrap(); | ||
|
||
patch_dylint_template(tempdir.path(), &custom_toolchain).unwrap(); | ||
|
||
dylint_internal::cargo::test(&format!("with custom toolchain `{custom_toolchain}`")) | ||
.build() | ||
.sanitize_environment() | ||
.current_dir(&tempdir) | ||
.success() | ||
.unwrap(); | ||
|
||
uninstall_toolchain(&custom_toolchain).unwrap(); | ||
} | ||
|
||
fn build_custom_toolchain() -> Result<(TempDir, String)> { | ||
let tempdir = tempdir().unwrap(); | ||
|
||
Command::new("git") | ||
.args([ | ||
"clone", | ||
"--depth=1", | ||
RUST_URL, | ||
&tempdir.path().to_string_lossy(), | ||
]) | ||
.success()?; | ||
|
||
// smoelius: Build the stage 2 compiler. This makes the `rustc_private` crates available for the | ||
// stage 1 compiler. | ||
Command::new("./x.py") | ||
.current_dir(&tempdir) | ||
.args(["build", "--stage=2"]) | ||
.success()?; | ||
|
||
let toolchain = random_string()?; | ||
|
||
// smoelius: Return a link to the stage 1 compiler. | ||
Command::new("rustup") | ||
.current_dir(&tempdir) | ||
.args([ | ||
"toolchain", | ||
"link", | ||
&toolchain, | ||
"build/x86_64-unknown-linux-gnu/stage1", | ||
]) | ||
.success()?; | ||
|
||
Ok((tempdir, toolchain)) | ||
} | ||
|
||
fn random_string() -> Result<String> { | ||
let tempfile = NamedTempFile::new().with_context(|| "Could not create named temp file")?; | ||
tempfile | ||
.path() | ||
.file_name() | ||
.map(|s| s.to_string_lossy().trim_start_matches('.').to_string()) | ||
.ok_or_else(|| anyhow!("Could not get file name")) | ||
} | ||
|
||
fn patch_dylint_template(path: &Path, channel: &str) -> Result<()> { | ||
// smoelius: `clippy_utils` may not build with the new toolchain. | ||
find_and_replace(&path.join("Cargo.toml"), "\r?\nclippy_utils = [^\r\n]*", "")?; | ||
|
||
set_toolchain_channel(path, channel) | ||
} | ||
|
||
fn uninstall_toolchain(toolchain: &str) -> Result<()> { | ||
Command::new("rustup") | ||
.args(["toolchain", "uninstall", toolchain]) | ||
.success() | ||
} |
Oops, something went wrong.