Skip to content

Commit cc8eb13

Browse files
committed
Auto merge of #9866 - nipunn1313:pkg_in_repo2, r=ehuss
Support path_in_vcs as part of cargo_vcs_metadata Depends on #9865 - this PR will look simpler once that one lands. I can't target my PR to the base branch of #9865 as an external contributor (since it's in my fork). For now just review the latest commit of this one. This is a backward compatible change that is an alternative to #9837
2 parents 6b6b0b4 + b8b127a commit cc8eb13

File tree

6 files changed

+97
-4
lines changed

6 files changed

+97
-4
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ enum GeneratedFile {
6666
#[derive(Serialize)]
6767
struct VcsInfo {
6868
git: GitVcsInfo,
69+
/// Path to the package within repo (empty string if root). / not \
70+
path_in_vcs: String,
6971
}
7072

7173
#[derive(Serialize)]
@@ -408,8 +410,14 @@ fn check_repo_state(
408410
"found (git) Cargo.toml at {:?} in workdir {:?}",
409411
path, workdir
410412
);
413+
let path_in_vcs = path
414+
.parent()
415+
.and_then(|p| p.to_str())
416+
.unwrap_or("")
417+
.replace("\\", "/");
411418
return Ok(Some(VcsInfo {
412419
git: git(p, src_files, &repo)?,
420+
path_in_vcs,
413421
}));
414422
}
415423
}

src/doc/man/cargo-package.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ fields in the manifest.
4343
See [the reference](../reference/publishing.html) for more details about
4444
packaging and publishing.
4545

46+
### .cargo_vcs_info.json format
47+
48+
Will generate a `.cargo_vcs_info.json` in the following format
49+
50+
```javascript
51+
{
52+
"git": {
53+
"sha1": "aac20b6e7e543e6dd4118b246c77225e3a3a1302"
54+
},
55+
"path_in_vcs": ""
56+
}
57+
```
58+
59+
`path_in_vcs` will be set to a repo-relative path for packages
60+
in subdirectories of the version control repository.
61+
4662
## OPTIONS
4763

4864
### Package Options

src/doc/man/generated_txt/cargo-package.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ DESCRIPTION
4545
<https://doc.rust-lang.org/cargo/reference/publishing.html> for more
4646
details about packaging and publishing.
4747

48+
.cargo_vcs_info.json format
49+
Will generate a .cargo_vcs_info.json in the following format
50+
51+
{
52+
"git": {
53+
"sha1": "aac20b6e7e543e6dd4118b246c77225e3a3a1302"
54+
},
55+
"path_in_vcs": ""
56+
}
57+
58+
path_in_vcs will be set to a repo-relative path for packages in
59+
subdirectories of the version control repository.
60+
4861
OPTIONS
4962
Package Options
5063
-l, --list

src/doc/src/commands/cargo-package.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ fields in the manifest.
4343
See [the reference](../reference/publishing.html) for more details about
4444
packaging and publishing.
4545

46+
### .cargo_vcs_info.json format
47+
48+
Will generate a `.cargo_vcs_info.json` in the following format
49+
50+
```javascript
51+
{
52+
"git": {
53+
"sha1": "aac20b6e7e543e6dd4118b246c77225e3a3a1302"
54+
},
55+
"path_in_vcs": ""
56+
}
57+
```
58+
59+
`path_in_vcs` will be set to a repo-relative path for packages
60+
in subdirectories of the version control repository.
61+
4662
## OPTIONS
4763

4864
### Package Options

src/etc/man/cargo-package.1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ fields in the manifest.
6767
.sp
6868
See \fIthe reference\fR <https://doc.rust\-lang.org/cargo/reference/publishing.html> for more details about
6969
packaging and publishing.
70+
.SS ".cargo_vcs_info.json format"
71+
Will generate a \fB\&.cargo_vcs_info.json\fR in the following format
72+
.sp
73+
.RS 4
74+
.nf
75+
{
76+
"git": {
77+
"sha1": "aac20b6e7e543e6dd4118b246c77225e3a3a1302"
78+
},
79+
"path_in_vcs": ""
80+
}
81+
.fi
82+
.RE
83+
.sp
84+
\fBpath_in_vcs\fR will be set to a repo\-relative path for packages
85+
in subdirectories of the version control repository.
7086
.SH "OPTIONS"
7187
.SS "Package Options"
7288
.sp

tests/testsuite/package.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ fn package_verbose() {
140140
let repo = git::repo(&root)
141141
.file("Cargo.toml", &basic_manifest("foo", "0.0.1"))
142142
.file("src/main.rs", "fn main() {}")
143-
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
144-
.file("a/src/lib.rs", "")
143+
.file("a/a/Cargo.toml", &basic_manifest("a", "0.0.1"))
144+
.file("a/a/src/lib.rs", "")
145145
.build();
146146
cargo_process("build").cwd(repo.root()).run();
147147

@@ -167,7 +167,8 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
167167
r#"{{
168168
"git": {{
169169
"sha1": "{}"
170-
}}
170+
}},
171+
"path_in_vcs": ""
171172
}}
172173
"#,
173174
repo.revparse_head()
@@ -187,7 +188,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
187188

188189
println!("package sub-repo");
189190
cargo_process("package -v --no-verify")
190-
.cwd(repo.root().join("a"))
191+
.cwd(repo.root().join("a/a"))
191192
.with_stderr(
192193
"\
193194
[WARNING] manifest has no description[..]
@@ -200,6 +201,29 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
200201
",
201202
)
202203
.run();
204+
205+
let f = File::open(&repo.root().join("a/a/target/package/a-0.0.1.crate")).unwrap();
206+
let vcs_contents = format!(
207+
r#"{{
208+
"git": {{
209+
"sha1": "{}"
210+
}},
211+
"path_in_vcs": "a/a"
212+
}}
213+
"#,
214+
repo.revparse_head()
215+
);
216+
validate_crate_contents(
217+
f,
218+
"a-0.0.1.crate",
219+
&[
220+
"Cargo.toml",
221+
"Cargo.toml.orig",
222+
"src/lib.rs",
223+
".cargo_vcs_info.json",
224+
],
225+
&[(".cargo_vcs_info.json", &vcs_contents)],
226+
);
203227
}
204228

205229
#[cargo_test]

0 commit comments

Comments
 (0)