cli/build-rs: remove metadata command dependency in favor of env vars

When building this project with [Nix/Crane](https://github.com/ipetkov/crane/discussions/693), if the `jj-cli` dependency is specified in `Cargo.toml` as a git-based crate, `cargo vendor` splits this workspace up into sub-crate directories, which causes `cargo metadata` to fail when searching for relative deps in the workspace root.

This commit simply changes how the crate version is determined, using Cargo's built-in environment variable [`CARGO_PKG_VERSION`](https://doc.rust-lang.org/cargo/reference/environment-variables.html)
This commit is contained in:
Kaleb Pace 2024-09-03 22:28:35 -05:00 committed by Martin von Zweigbergk
parent 250a28b5a5
commit dbb579adec
4 changed files with 1 additions and 56 deletions

42
Cargo.lock generated
View file

@ -266,38 +266,6 @@ dependencies = [
"serde",
]
[[package]]
name = "camino"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3"
dependencies = [
"serde",
]
[[package]]
name = "cargo-platform"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24b1f0365a6c6bb4020cd05806fd0d33c44d38046b8bd7f0e40814b9763cabfc"
dependencies = [
"serde",
]
[[package]]
name = "cargo_metadata"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7daec1a2a2129eeba1644b220b4647ec537b0b5d4bfd6876fcc5a540056b592"
dependencies = [
"camino",
"cargo-platform",
"semver",
"serde",
"serde_json",
"thiserror",
]
[[package]]
name = "cassowary"
version = "0.3.0"
@ -1853,7 +1821,6 @@ dependencies = [
"assert_matches",
"async-trait",
"bstr",
"cargo_metadata",
"chrono",
"clap",
"clap-markdown",
@ -2832,15 +2799,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "semver"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
dependencies = [
"serde",
]
[[package]]
name = "serde"
version = "1.0.209"

View file

@ -24,7 +24,6 @@ async-trait = "0.1.82"
backoff = "0.4.0"
blake2 = "0.10.6"
bstr = "1.10.0"
cargo_metadata = "0.17.0"
clap = { version = "4.5.16", features = [
"derive",
"deprecated",

View file

@ -47,9 +47,6 @@ required-features = ["test-fakes"]
[[test]]
name = "runner"
[build-dependencies]
cargo_metadata = { workspace = true }
[dependencies]
bstr = { workspace = true }
chrono = { workspace = true }

View file

@ -16,20 +16,11 @@ use std::path::Path;
use std::process::Command;
use std::str;
use cargo_metadata::MetadataCommand;
const GIT_HEAD_PATH: &str = "../.git/HEAD";
const JJ_OP_HEADS_PATH: &str = "../.jj/repo/op_heads/heads";
fn main() -> std::io::Result<()> {
let path = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let meta = MetadataCommand::new()
.manifest_path("./Cargo.toml")
.current_dir(&path)
.exec()
.unwrap();
let root = meta.root_package().unwrap();
let version = &root.version;
let version = std::env::var("CARGO_PKG_VERSION").unwrap();
if Path::new(GIT_HEAD_PATH).exists() {
// In colocated repo, .git/HEAD should reflect the working-copy parent.