Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #19751 from VictorArcium/env-var-cargo-manifest-path
Support environment variable CARGO_MANIFEST_PATH.
Chayim Refael Friedman 12 months ago
parent d7e977a · parent 32e09de · commit d30deb5
-rw-r--r--crates/ide-completion/src/completions/env_vars.rs1
-rw-r--r--crates/project-model/src/env.rs1
-rw-r--r--crates/project-model/test_data/output/cargo_hello_world_project_model.txt5
-rw-r--r--crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt5
-rw-r--r--crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt5
5 files changed, 17 insertions, 0 deletions
diff --git a/crates/ide-completion/src/completions/env_vars.rs b/crates/ide-completion/src/completions/env_vars.rs
index cd18b3dcfd..92cbf411c1 100644
--- a/crates/ide-completion/src/completions/env_vars.rs
+++ b/crates/ide-completion/src/completions/env_vars.rs
@@ -13,6 +13,7 @@ use crate::{
const CARGO_DEFINED_VARS: &[(&str, &str)] = &[
("CARGO", "Path to the cargo binary performing the build"),
("CARGO_MANIFEST_DIR", "The directory containing the manifest of your package"),
+ ("CARGO_MANIFEST_PATH", "The path to the manifest of your package"),
("CARGO_PKG_VERSION", "The full version of your package"),
("CARGO_PKG_VERSION_MAJOR", "The major version of your package"),
("CARGO_PKG_VERSION_MINOR", "The minor version of your package"),
diff --git a/crates/project-model/src/env.rs b/crates/project-model/src/env.rs
index e7293b0b2e..450def5461 100644
--- a/crates/project-model/src/env.rs
+++ b/crates/project-model/src/env.rs
@@ -18,6 +18,7 @@ pub(crate) fn inject_cargo_package_env(env: &mut Env, package: &PackageData) {
let manifest_dir = package.manifest.parent();
env.set("CARGO_MANIFEST_DIR", manifest_dir.as_str());
+ env.set("CARGO_MANIFEST_PATH", package.manifest.as_str());
env.set("CARGO_PKG_VERSION", package.version.to_string());
env.set("CARGO_PKG_VERSION_MAJOR", package.version.major.to_string());
diff --git a/crates/project-model/test_data/output/cargo_hello_world_project_model.txt b/crates/project-model/test_data/output/cargo_hello_world_project_model.txt
index 4ef9d81611..3722e2c721 100644
--- a/crates/project-model/test_data/output/cargo_hello_world_project_model.txt
+++ b/crates/project-model/test_data/output/cargo_hello_world_project_model.txt
@@ -52,6 +52,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "hello_world",
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
+ "CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
"CARGO_PKG_AUTHORS": "",
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
@@ -136,6 +137,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "hello_world",
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
+ "CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
"CARGO_PKG_AUTHORS": "",
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
@@ -220,6 +222,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "an_example",
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
+ "CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
"CARGO_PKG_AUTHORS": "",
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
@@ -304,6 +307,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "it",
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
+ "CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
"CARGO_PKG_AUTHORS": "",
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
@@ -384,6 +388,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "libc",
"CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98",
+ "CARGO_MANIFEST_PATH": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98/Cargo.toml",
"CARGO_PKG_AUTHORS": "The Rust Project Developers",
"CARGO_PKG_DESCRIPTION": "Raw FFI bindings to platform libraries like libc.\n",
"CARGO_PKG_HOMEPAGE": "https://github.com/rust-lang/libc",
diff --git a/crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt b/crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt
index 4ef9d81611..3722e2c721 100644
--- a/crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt
+++ b/crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt
@@ -52,6 +52,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "hello_world",
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
+ "CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
"CARGO_PKG_AUTHORS": "",
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
@@ -136,6 +137,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "hello_world",
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
+ "CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
"CARGO_PKG_AUTHORS": "",
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
@@ -220,6 +222,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "an_example",
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
+ "CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
"CARGO_PKG_AUTHORS": "",
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
@@ -304,6 +307,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "it",
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
+ "CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
"CARGO_PKG_AUTHORS": "",
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
@@ -384,6 +388,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "libc",
"CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98",
+ "CARGO_MANIFEST_PATH": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98/Cargo.toml",
"CARGO_PKG_AUTHORS": "The Rust Project Developers",
"CARGO_PKG_DESCRIPTION": "Raw FFI bindings to platform libraries like libc.\n",
"CARGO_PKG_HOMEPAGE": "https://github.com/rust-lang/libc",
diff --git a/crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt b/crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt
index 52089d1dbc..7b156ea63a 100644
--- a/crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt
+++ b/crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt
@@ -51,6 +51,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "hello_world",
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
+ "CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
"CARGO_PKG_AUTHORS": "",
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
@@ -134,6 +135,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "hello_world",
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
+ "CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
"CARGO_PKG_AUTHORS": "",
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
@@ -217,6 +219,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "an_example",
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
+ "CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
"CARGO_PKG_AUTHORS": "",
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
@@ -300,6 +303,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "it",
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
+ "CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
"CARGO_PKG_AUTHORS": "",
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
@@ -380,6 +384,7 @@
"CARGO": "$CARGO$",
"CARGO_CRATE_NAME": "libc",
"CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98",
+ "CARGO_MANIFEST_PATH": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98/Cargo.toml",
"CARGO_PKG_AUTHORS": "The Rust Project Developers",
"CARGO_PKG_DESCRIPTION": "Raw FFI bindings to platform libraries like libc.\n",
"CARGO_PKG_HOMEPAGE": "https://github.com/rust-lang/libc",