Skip to content

Commit

Permalink
refactor(embedded): Simplify temp-manifest dir
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 13, 2023
1 parent cedfad4 commit f220e64
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 35 deletions.
7 changes: 6 additions & 1 deletion src/cargo/util/toml/embedded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ impl RawScript {
) -> CargoResult<std::path::PathBuf> {
let hash = self.hash().to_string();
assert_eq!(hash.len(), 64);
let leaf_dir = self
.path
.file_name()
.ok_or_else(|| anyhow::format_err!("no file name"))?
.to_string_lossy();
let mut workspace_root = target_dir.to_owned();
workspace_root.push("eval");
workspace_root.push(&hash[0..2]);
workspace_root.push(&hash[2..4]);
workspace_root.push(&hash[4..]);
workspace_root.push(self.package_name()?);
workspace_root.push(leaf_dir.as_ref());
std::fs::create_dir_all(&workspace_root).with_context(|| {
format!(
"failed to create temporary workspace at {}",
Expand Down
66 changes: 32 additions & 34 deletions tests/testsuite/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ args: []
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] echo v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/echo)
[COMPILING] echo v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/echo.rs)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/echo/target/debug/echo_[..]`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/echo.rs/target/debug/echo_[..]`
",
)
.run();
Expand Down Expand Up @@ -111,9 +111,9 @@ args: []
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] echo v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/echo)
[COMPILING] echo v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/echo.rs)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/echo/target/debug/echo_[..]`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/echo.rs/target/debug/echo_[..]`
",
)
.run();
Expand Down Expand Up @@ -203,9 +203,9 @@ fn main() {
)
.with_stderr(
"\
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script)
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script.rs)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..]`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script.rs/target/debug/script_[..]`
",
)
.run();
Expand Down Expand Up @@ -235,9 +235,9 @@ fn main() {
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script)
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script.rs)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..]`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script.rs/target/debug/script_[..]`
",
)
.run();
Expand All @@ -264,9 +264,9 @@ fn main() {
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script)
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script.rs)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..]`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script.rs/target/debug/script_[..]`
",
)
.run();
Expand All @@ -282,7 +282,7 @@ fn main() {
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..]`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script.rs/target/debug/script_[..]`
",
)
.run();
Expand All @@ -298,9 +298,9 @@ fn main() {
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script)
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script.rs)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..]`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script.rs/target/debug/script_[..]`
",
)
.run();
Expand All @@ -327,9 +327,9 @@ fn main() {
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script)
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script.rs)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..]`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script.rs/target/debug/script_[..]`
",
)
.run();
Expand All @@ -352,9 +352,9 @@ args: ["-NotAnArg"]
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script)
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script.rs)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..] -NotAnArg`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script.rs/target/debug/script_[..] -NotAnArg`
",
)
.run();
Expand All @@ -377,9 +377,9 @@ args: ["-NotAnArg"]
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script)
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script.rs)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..] -NotAnArg`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script.rs/target/debug/script_[..] -NotAnArg`
",
)
.run();
Expand All @@ -402,9 +402,9 @@ args: ["--help"]
.with_stderr(
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script)
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script.rs)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..] --help`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script.rs/target/debug/script_[..] --help`
",
)
.run();
Expand All @@ -413,11 +413,9 @@ args: ["--help"]
#[cargo_test]
fn test_name_has_weird_chars() {
let script = ECHO_SCRIPT;
let p = cargo_test_support::project()
.file("s-h.w§c!.rs", script)
.build();
let p = cargo_test_support::project().file("s-w§c!", script).build();

p.cargo("-Zscript s-h.w§c!.rs")
p.cargo("-Zscript ./s-w§c!")
.masquerade_as_nightly_cargo(&["script"])
.with_stdout(
r#"bin: [ROOT]/home/.cargo/eval/target/eval/[..]
Expand All @@ -426,15 +424,15 @@ args: []
)
.with_stderr(
r#"[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] s-h_w_c_ v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/s-h_w_c_)
[WARNING] crate `s_h_w_c__[..]` should have a snake case name
[COMPILING] s-w_c_ v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/s-w§c!)
[WARNING] crate `s_w_c__[..]` should have a snake case name
|
= help: convert the identifier to snake case: `s_h_w_c_[..]`
= help: convert the identifier to snake case: `s_w_c_[..]`
= note: `#[warn(non_snake_case)]` on by default
[WARNING] `s-h_w_c_` (bin "s-h_w_c__[..]") generated 1 warning
[WARNING] `s-w_c_` (bin "s-w_c__[..]") generated 1 warning
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/s-h_w_c_/target/debug/s-h_w_c__[..]`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/s-w§c!/target/debug/s-w_c__[..]`
"#,
)
.run();
Expand Down Expand Up @@ -470,9 +468,9 @@ fn main() {
[DOWNLOADING] crates ...
[DOWNLOADED] script v1.0.0 (registry `dummy-registry`)
[COMPILING] script v1.0.0
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script)
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script.rs)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..] --help`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script.rs/target/debug/script_[..] --help`
",
)
.run();
Expand Down Expand Up @@ -507,9 +505,9 @@ fn main() {
"\
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
[COMPILING] bar v0.0.1 ([ROOT]/foo/bar)
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script)
[COMPILING] script v0.0.0 ([ROOT]/home/.cargo/eval/target/eval/[..]/script.rs)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script/target/debug/script_[..] --help`
[RUNNING] `[ROOT]/home/.cargo/eval/target/eval/[..]/script.rs/target/debug/script_[..] --help`
",
)
.run();
Expand Down

0 comments on commit f220e64

Please sign in to comment.