Skip to content

Commit fec5c8f

Browse files
Rollup merge of #141789 - ferrocene:hoverbear/exclude-cargo-home-from-in-tree-consideration, r=clubby789
Exclude `CARGO_HOME` from `generate-copyright` in-tree determination On Ferrocene, we noticed that in our releases the out-of-tree notices were not being included. When `x.py run generate-copyright` was ran on local development machines, it worked fine. After some investigations ``@tshepang`` and I determined that the problem was that the cargo registry (located in `CARGO_HOME`) started with the source directory on CI jobs, and was being excluded by this line: https://github.com/rust-lang/rust/blob/15825b7161f8bd6a3482211fbf6727a52aa1166b/src/tools/generate-copyright/src/cargo_metadata.rs#L85-L88 In Ferrocene's `run.sh` we set `CARGO_HOME` to be `build/cargo-home`: https://github.com/ferrocene/ferrocene/blob/96a45dd9a18c6e54d3cd81750a78fe459fa48af0/ferrocene/ci/run.sh#L34-L46 which caused this issue. This PR passes the `CARGO_HOME` variable to the `generate-copyright` tool and expands the consideration of in-tree-ness to be aware of `CARGO_HOME`. It is an upstreaming of ferrocene/ferrocene#1491. ## Testing Run `CARGO_HOME=build/cargo-home ./x.py run generate-copyright` on `master`, then check `build/host/doc/COPYRIGHT` and look for out of tree dependencies (at the bottom). Then, try running the same command in this branch.
2 parents d843809 + f886925 commit fec5c8f

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/bootstrap/src/core/build_steps/run.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
use std::path::PathBuf;
77

8-
use crate::Mode;
98
use crate::core::build_steps::dist::distdir;
109
use crate::core::build_steps::test;
1110
use crate::core::build_steps::tool::{self, SourceType, Tool};
@@ -14,6 +13,7 @@ use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
1413
use crate::core::config::TargetSelection;
1514
use crate::core::config::flags::get_completion;
1615
use crate::utils::exec::command;
16+
use crate::{Mode, t};
1717

1818
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
1919
pub struct BuildManifest;
@@ -253,6 +253,7 @@ impl Step for GenerateCopyright {
253253
cmd.env("SRC_DIR", &builder.src);
254254
cmd.env("VENDOR_DIR", &vendored_sources);
255255
cmd.env("CARGO", &builder.initial_cargo);
256+
cmd.env("CARGO_HOME", t!(home::cargo_home()));
256257
// it is important that generate-copyright runs from the root of the
257258
// source tree, because it uses relative paths
258259
cmd.current_dir(&builder.src);

src/tools/generate-copyright/src/cargo_metadata.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ pub struct PackageMetadata {
4646
/// covered it already.
4747
pub fn get_metadata_and_notices(
4848
cargo: &Path,
49+
cargo_home_path: &Path,
4950
vendor_path: &Path,
5051
root_path: &Path,
5152
manifest_paths: &[PathBuf],
5253
) -> Result<BTreeMap<Package, PackageMetadata>, Error> {
53-
let mut output = get_metadata(cargo, root_path, manifest_paths)?;
54+
let mut output = get_metadata(cargo, cargo_home_path, root_path, manifest_paths)?;
5455

5556
// Now for each dependency we found, go and grab any important looking files
5657
for (package, metadata) in output.iter_mut() {
@@ -66,6 +67,7 @@ pub fn get_metadata_and_notices(
6667
/// assume `reuse` has covered it already.
6768
pub fn get_metadata(
6869
cargo: &Path,
70+
cargo_home_path: &Path,
6971
root_path: &Path,
7072
manifest_paths: &[PathBuf],
7173
) -> Result<BTreeMap<Package, PackageMetadata>, Error> {
@@ -81,8 +83,11 @@ pub fn get_metadata(
8183
.manifest_path(manifest_path)
8284
.exec()?;
8385
for package in metadata.packages {
84-
let manifest_path = package.manifest_path.as_path();
85-
if manifest_path.starts_with(root_path) {
86+
let package_manifest_path = package.manifest_path.as_path();
87+
88+
if package_manifest_path.starts_with(root_path)
89+
&& !package_manifest_path.starts_with(cargo_home_path)
90+
{
8691
// it's an in-tree dependency and reuse covers it
8792
continue;
8893
}

src/tools/generate-copyright/src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ mod cargo_metadata;
1515
///
1616
/// Run `x.py run generate-copyright`
1717
fn main() -> Result<(), Error> {
18+
let cargo_home = env_path("CARGO_HOME")?;
1819
let dest_file = env_path("DEST")?;
1920
let libstd_dest_file = env_path("DEST_LIBSTD")?;
2021
let src_dir = env_path("SRC_DIR")?;
@@ -39,11 +40,17 @@ fn main() -> Result<(), Error> {
3940
.collect::<Vec<_>>();
4041

4142
// Scan Cargo dependencies
42-
let mut collected_cargo_metadata =
43-
cargo_metadata::get_metadata_and_notices(&cargo, &vendor_dir, &src_dir, &cargo_manifests)?;
43+
let mut collected_cargo_metadata = cargo_metadata::get_metadata_and_notices(
44+
&cargo,
45+
&cargo_home,
46+
&vendor_dir,
47+
&src_dir,
48+
&cargo_manifests,
49+
)?;
4450

4551
let library_collected_cargo_metadata = cargo_metadata::get_metadata_and_notices(
4652
&cargo,
53+
&cargo_home,
4754
&vendor_dir,
4855
&src_dir,
4956
&library_manifests,

0 commit comments

Comments
 (0)