Skip to content

Commit cada441

Browse files
committed
Revert "feat: Add CARGO_RUSTC_CURRENT_DIR"
This reverts commit e81d84c. Fixes #14798
1 parent fbc8ba8 commit cada441

File tree

3 files changed

+4
-267
lines changed

3 files changed

+4
-267
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -717,16 +717,6 @@ fn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult
717717
let tmp = build_runner.files().layout(unit.kind).prepare_tmp()?;
718718
base.env("CARGO_TARGET_TMPDIR", tmp.display().to_string());
719719
}
720-
if build_runner.bcx.gctx.nightly_features_allowed {
721-
// This must come after `build_base_args` (which calls `add_path_args`) so that the `cwd`
722-
// is set correctly.
723-
base.env(
724-
"CARGO_RUSTC_CURRENT_DIR",
725-
base.get_cwd()
726-
.map(|c| c.display().to_string())
727-
.unwrap_or(String::new()),
728-
);
729-
}
730720

731721
Ok(base)
732722
}

src/doc/src/reference/environment-variables.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ corresponding environment variable is set to the empty string, `""`.
269269
where integration tests or benchmarks are free to put any data needed by
270270
the tests/benches. Cargo initially creates this directory but doesn't
271271
manage its content in any way, this is the responsibility of the test code.
272-
* `CARGO_RUSTC_CURRENT_DIR` --- This is a path that `rustc` is invoked from **(nightly only)**.
273272

274273
[Cargo target]: cargo-targets.md
275274
[binaries]: cargo-targets.md#binaries

tests/testsuite/build.rs

Lines changed: 4 additions & 256 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,11 +1656,6 @@ fn crate_env_vars() {
16561656
16571657
// Verify CARGO_TARGET_TMPDIR isn't set for bins
16581658
assert!(option_env!("CARGO_TARGET_TMPDIR").is_none());
1659-
1660-
// Verify CARGO_RUSTC_CURRENT_DIR is set for examples
1661-
let workspace_dir = std::path::Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
1662-
let file_path = workspace_dir.join(file!());
1663-
assert!(file_path.exists(), "{}", file_path.display());
16641659
}
16651660
"#,
16661661
)
@@ -1698,11 +1693,6 @@ fn crate_env_vars() {
16981693
// Check that CARGO_TARGET_TMPDIR isn't set for lib code
16991694
assert!(option_env!("CARGO_TARGET_TMPDIR").is_none());
17001695
env::var("CARGO_TARGET_TMPDIR").unwrap_err();
1701-
1702-
// Verify CARGO_RUSTC_CURRENT_DIR is set for examples
1703-
let workspace_dir = std::path::Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
1704-
let file_path = workspace_dir.join(file!());
1705-
assert!(file_path.exists(), "{}", file_path.display());
17061696
}
17071697
17081698
#[test]
@@ -1711,13 +1701,6 @@ fn crate_env_vars() {
17111701
assert!(option_env!("CARGO_TARGET_TMPDIR").is_none());
17121702
env::var("CARGO_TARGET_TMPDIR").unwrap_err();
17131703
}
1714-
1715-
#[test]
1716-
fn unit_env_cargo_rustc_current_dir() {
1717-
let workspace_dir = std::path::Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
1718-
let file_path = workspace_dir.join(file!());
1719-
assert!(file_path.exists(), "{}", file_path.display());
1720-
}
17211704
"#,
17221705
)
17231706
.file(
@@ -1734,11 +1717,6 @@ fn crate_env_vars() {
17341717
17351718
// Verify CARGO_TARGET_TMPDIR isn't set for examples
17361719
assert!(option_env!("CARGO_TARGET_TMPDIR").is_none());
1737-
1738-
// Verify CARGO_RUSTC_CURRENT_DIR is set for examples
1739-
let workspace_dir = std::path::Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
1740-
let file_path = workspace_dir.join(file!());
1741-
assert!(file_path.exists(), "{}", file_path.display());
17421720
}
17431721
"#,
17441722
)
@@ -1749,13 +1727,6 @@ fn crate_env_vars() {
17491727
fn integration_env_cargo_target_tmpdir() {
17501728
foo::check_tmpdir(option_env!("CARGO_TARGET_TMPDIR"));
17511729
}
1752-
1753-
#[test]
1754-
fn integration_env_cargo_rustc_current_dir() {
1755-
let workspace_dir = std::path::Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
1756-
let file_path = workspace_dir.join(file!());
1757-
assert!(file_path.exists(), "{}", file_path.display());
1758-
}
17591730
"#,
17601731
);
17611732

@@ -1771,13 +1742,6 @@ fn crate_env_vars() {
17711742
fn bench_env_cargo_target_tmpdir(_: &mut Bencher) {
17721743
foo::check_tmpdir(option_env!("CARGO_TARGET_TMPDIR"));
17731744
}
1774-
1775-
#[test]
1776-
fn bench_env_cargo_rustc_current_dir() {
1777-
let workspace_dir = std::path::Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
1778-
let file_path = workspace_dir.join(file!());
1779-
assert!(file_path.exists(), "{}", file_path.display());
1780-
}
17811745
"#,
17821746
)
17831747
.build()
@@ -1786,9 +1750,7 @@ fn crate_env_vars() {
17861750
};
17871751

17881752
println!("build");
1789-
p.cargo("build -v")
1790-
.masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
1791-
.run();
1753+
p.cargo("build -v").run();
17921754

17931755
println!("bin");
17941756
p.process(&p.bin("foo-bar"))
@@ -1799,229 +1761,15 @@ fn crate_env_vars() {
17991761
.run();
18001762

18011763
println!("example");
1802-
p.cargo("run --example ex-env-vars -v")
1803-
.masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
1804-
.run();
1764+
p.cargo("run --example ex-env-vars -v").run();
18051765

18061766
println!("test");
1807-
p.cargo("test -v")
1808-
.masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
1809-
.run();
1767+
p.cargo("test -v").run();
18101768

18111769
if is_nightly() {
18121770
println!("bench");
1813-
p.cargo("bench -v")
1814-
.masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
1815-
.run();
1816-
}
1817-
}
1818-
1819-
#[cargo_test]
1820-
fn cargo_rustc_current_dir_foreign_workspace_dep() {
1821-
let foo = project()
1822-
.file(
1823-
"Cargo.toml",
1824-
r#"
1825-
[workspace]
1826-
1827-
[package]
1828-
name = "foo"
1829-
version = "0.0.1"
1830-
edition = "2015"
1831-
authors = []
1832-
1833-
[dependencies]
1834-
baz.path = "../baz"
1835-
baz_member.path = "../baz/baz_member"
1836-
"#,
1837-
)
1838-
.file("src/lib.rs", "")
1839-
.build();
1840-
let _baz = project()
1841-
.at("baz")
1842-
.file(
1843-
"Cargo.toml",
1844-
r#"
1845-
[workspace]
1846-
members = ["baz_member"]
1847-
1848-
[package]
1849-
name = "baz"
1850-
version = "0.1.0"
1851-
edition = "2015"
1852-
"#,
1853-
)
1854-
.file("src/lib.rs", "")
1855-
.file(
1856-
"tests/env.rs",
1857-
r#"
1858-
use std::path::Path;
1859-
1860-
#[test]
1861-
fn baz_env() {
1862-
let workspace_dir = Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
1863-
let manifest_dir = Path::new(option_env!("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
1864-
let manifest_path = Path::new(option_env!("CARGO_MANIFEST_PATH").expect("CARGO_MANIFEST_PATH"));
1865-
let current_dir = std::env::current_dir().expect("current_dir");
1866-
let file_path = workspace_dir.join(file!());
1867-
assert!(file_path.exists(), "{}", file_path.display());
1868-
let workspace_dir = std::fs::canonicalize(current_dir.join(workspace_dir)).expect("CARGO_RUSTC_CURRENT_DIR");
1869-
let manifest_path = std::fs::canonicalize(current_dir.join(manifest_dir.clone()).join("Cargo.toml")).expect("CARGO_MANIFEST_PATH");
1870-
let manifest_dir = std::fs::canonicalize(current_dir.join(manifest_dir)).expect("CARGO_MANIFEST_DIR");
1871-
assert_eq!(workspace_dir, manifest_dir.clone());
1872-
assert_eq!(manifest_dir.join("Cargo.toml"), manifest_path);
1873-
}
1874-
"#,
1875-
)
1876-
.file(
1877-
"baz_member/Cargo.toml",
1878-
r#"
1879-
[package]
1880-
name = "baz_member"
1881-
version = "0.1.0"
1882-
edition = "2015"
1883-
authors = []
1884-
"#,
1885-
)
1886-
.file("baz_member/src/lib.rs", "")
1887-
.file(
1888-
"baz_member/tests/env.rs",
1889-
r#"
1890-
use std::path::Path;
1891-
1892-
#[test]
1893-
fn baz_member_env() {
1894-
let workspace_dir = Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
1895-
let file_path = workspace_dir.join(file!());
1896-
assert!(file_path.exists(), "{}", file_path.display());
1897-
}
1898-
"#,
1899-
)
1900-
.build();
1901-
1902-
// Verify it works from a different workspace
1903-
foo.cargo("test -p baz")
1904-
.masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
1905-
.with_stdout_data(str![[r#"
1906-
1907-
running 0 tests
1908-
1909-
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
1910-
1911-
1912-
running 1 test
1913-
test baz_env ... ok
1914-
1915-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
1916-
1917-
1918-
running 0 tests
1919-
1920-
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
1921-
1922-
1923-
"#]])
1924-
.run();
1925-
foo.cargo("test -p baz_member")
1926-
.masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
1927-
.with_stdout_data(str![[r#"
1928-
1929-
running 0 tests
1930-
1931-
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
1932-
1933-
1934-
running 1 test
1935-
test baz_member_env ... ok
1936-
1937-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
1938-
1939-
1940-
running 0 tests
1941-
1942-
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
1943-
1944-
1945-
"#]])
1946-
.run();
1947-
}
1948-
1949-
#[cargo_test]
1950-
fn cargo_rustc_current_dir_non_local_dep() {
1951-
Package::new("bar", "0.1.0")
1952-
.file(
1953-
"tests/bar_env.rs",
1954-
r#"
1955-
use std::path::Path;
1956-
1957-
#[test]
1958-
fn bar_env() {
1959-
let workspace_dir = Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
1960-
let manifest_dir = Path::new(option_env!("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
1961-
let manifest_path = Path::new(option_env!("CARGO_MANIFEST_PATH").expect("CARGO_MANIFEST_PATH"));
1962-
let current_dir = std::env::current_dir().expect("current_dir");
1963-
let file_path = workspace_dir.join(file!());
1964-
assert!(file_path.exists(), "{}", file_path.display());
1965-
let workspace_dir = std::fs::canonicalize(current_dir.join(workspace_dir)).expect("CARGO_RUSTC_CURRENT_DIR");
1966-
let manifest_path = std::fs::canonicalize(current_dir.join(manifest_dir.clone()).join("Cargo.toml")).expect("CARGO_MANIFEST_PATH");
1967-
let manifest_dir = std::fs::canonicalize(current_dir.join(manifest_dir)).expect("CARGO_MANIFEST_DIR");
1968-
assert_eq!(workspace_dir, manifest_dir.clone());
1969-
assert_eq!(manifest_dir.join("Cargo.toml"), manifest_path);
1970-
}
1971-
"#,
1972-
)
1973-
.publish();
1974-
1975-
let p = project()
1976-
.file("src/lib.rs", "")
1977-
.file(
1978-
"Cargo.toml",
1979-
r#"
1980-
[package]
1981-
name = "foo"
1982-
version = "0.0.1"
1983-
edition = "2015"
1984-
1985-
[dependencies]
1986-
bar = "0.1.0"
1987-
"#,
1988-
)
1989-
.build();
1990-
1991-
p.cargo("test -p bar")
1992-
.masquerade_as_nightly_cargo(&["CARGO_RUSTC_CURRENT_DIR"])
1993-
.with_stdout_data(str![[r#"
1994-
1995-
running 1 test
1996-
test bar_env ... ok
1997-
1998-
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
1999-
2000-
2001-
"#]])
2002-
.run();
2003-
}
2004-
2005-
#[cargo_test]
2006-
fn cargo_rustc_current_dir_is_not_stable() {
2007-
if is_nightly() {
2008-
return;
1771+
p.cargo("bench -v").run();
20091772
}
2010-
let p = project()
2011-
.file(
2012-
"tests/env.rs",
2013-
r#"
2014-
use std::path::Path;
2015-
2016-
#[test]
2017-
fn env() {
2018-
assert_eq!(option_env!("CARGO_RUSTC_CURRENT_DIR"), None);
2019-
}
2020-
"#,
2021-
)
2022-
.build();
2023-
2024-
p.cargo("test").run();
20251773
}
20261774

20271775
#[cargo_test]

0 commit comments

Comments
 (0)