Skip to content

Commit

Permalink
Support path_in_vcs as part of cargo_vcs_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunn1313 committed Sep 26, 2021
1 parent 6b6b0b4 commit b8b127a
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 4 deletions.
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

0 comments on commit b8b127a

Please sign in to comment.