Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support path_in_vcs as part of cargo_vcs_metadata #9866

Merged
merged 1 commit into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Support path_in_vcs as part of cargo_vcs_metadata
  • Loading branch information
nipunn1313 committed Sep 26, 2021
commit b8b127a87037d230e2204fa92595e49d519efdb9
8 changes: 8 additions & 0 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ enum GeneratedFile {
#[derive(Serialize)]
struct VcsInfo {
git: GitVcsInfo,
/// Path to the package within repo (empty string if root). / not \
path_in_vcs: String,
}

#[derive(Serialize)]
Expand Down Expand Up @@ -408,8 +410,14 @@ fn check_repo_state(
"found (git) Cargo.toml at {:?} in workdir {:?}",
path, workdir
);
let path_in_vcs = path
.parent()
.and_then(|p| p.to_str())
.unwrap_or("")
.replace("\\", "/");
return Ok(Some(VcsInfo {
git: git(p, src_files, &repo)?,
path_in_vcs,
}));
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/doc/man/cargo-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ fields in the manifest.
See [the reference](../reference/publishing.html) for more details about
packaging and publishing.

### .cargo_vcs_info.json format

Will generate a `.cargo_vcs_info.json` in the following format

```javascript
{
"git": {
"sha1": "aac20b6e7e543e6dd4118b246c77225e3a3a1302"
},
"path_in_vcs": ""
}
```

`path_in_vcs` will be set to a repo-relative path for packages
in subdirectories of the version control repository.

## OPTIONS

### Package Options
Expand Down
13 changes: 13 additions & 0 deletions src/doc/man/generated_txt/cargo-package.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ DESCRIPTION
<https://doc.rust-lang.org/cargo/reference/publishing.html> for more
details about packaging and publishing.

.cargo_vcs_info.json format
Will generate a .cargo_vcs_info.json in the following format

{
"git": {
"sha1": "aac20b6e7e543e6dd4118b246c77225e3a3a1302"
},
"path_in_vcs": ""
}

path_in_vcs will be set to a repo-relative path for packages in
subdirectories of the version control repository.

OPTIONS
Package Options
-l, --list
Expand Down
16 changes: 16 additions & 0 deletions src/doc/src/commands/cargo-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ fields in the manifest.
See [the reference](../reference/publishing.html) for more details about
packaging and publishing.

### .cargo_vcs_info.json format

Will generate a `.cargo_vcs_info.json` in the following format

```javascript
{
"git": {
"sha1": "aac20b6e7e543e6dd4118b246c77225e3a3a1302"
},
"path_in_vcs": ""
}
```

`path_in_vcs` will be set to a repo-relative path for packages
in subdirectories of the version control repository.

## OPTIONS

### Package Options
Expand Down
16 changes: 16 additions & 0 deletions src/etc/man/cargo-package.1
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ fields in the manifest.
.sp
See \fIthe reference\fR <https://doc.rust\-lang.org/cargo/reference/publishing.html> for more details about
packaging and publishing.
.SS ".cargo_vcs_info.json format"
Will generate a \fB\&.cargo_vcs_info.json\fR in the following format
.sp
.RS 4
.nf
{
"git": {
"sha1": "aac20b6e7e543e6dd4118b246c77225e3a3a1302"
},
"path_in_vcs": ""
}
.fi
.RE
.sp
\fBpath_in_vcs\fR will be set to a repo\-relative path for packages
in subdirectories of the version control repository.
.SH "OPTIONS"
.SS "Package Options"
.sp
Expand Down
32 changes: 28 additions & 4 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ fn package_verbose() {
let repo = git::repo(&root)
.file("Cargo.toml", &basic_manifest("foo", "0.0.1"))
.file("src/main.rs", "fn main() {}")
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
.file("a/src/lib.rs", "")
.file("a/a/Cargo.toml", &basic_manifest("a", "0.0.1"))
.file("a/a/src/lib.rs", "")
.build();
cargo_process("build").cwd(repo.root()).run();

Expand All @@ -167,7 +167,8 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
r#"{{
"git": {{
"sha1": "{}"
}}
}},
"path_in_vcs": ""
}}
"#,
repo.revparse_head()
Expand All @@ -187,7 +188,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for

println!("package sub-repo");
cargo_process("package -v --no-verify")
.cwd(repo.root().join("a"))
.cwd(repo.root().join("a/a"))
.with_stderr(
"\
[WARNING] manifest has no description[..]
Expand All @@ -200,6 +201,29 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
",
)
.run();

let f = File::open(&repo.root().join("a/a/target/package/a-0.0.1.crate")).unwrap();
let vcs_contents = format!(
r#"{{
"git": {{
"sha1": "{}"
}},
"path_in_vcs": "a/a"
}}
"#,
repo.revparse_head()
);
validate_crate_contents(
f,
"a-0.0.1.crate",
&[
"Cargo.toml",
"Cargo.toml.orig",
"src/lib.rs",
".cargo_vcs_info.json",
],
&[(".cargo_vcs_info.json", &vcs_contents)],
);
}

#[cargo_test]
Expand Down