generate-copyright: pass the list of manifests from bootstrap
(cherry picked from commit 08b4f6d2c6)
This commit is contained in:
parent
f8f8aeaef1
commit
27380b90c7
3 changed files with 46 additions and 10 deletions
|
|
@ -9,6 +9,7 @@ use crate::Mode;
|
|||
use crate::core::build_steps::dist::distdir;
|
||||
use crate::core::build_steps::test;
|
||||
use crate::core::build_steps::tool::{self, SourceType, Tool};
|
||||
use crate::core::build_steps::vendor::default_paths_to_vendor;
|
||||
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
|
||||
use crate::core::config::TargetSelection;
|
||||
use crate::core::config::flags::get_completion;
|
||||
|
|
@ -212,7 +213,21 @@ impl Step for GenerateCopyright {
|
|||
let dest = builder.out.join("COPYRIGHT.html");
|
||||
let dest_libstd = builder.out.join("COPYRIGHT-library.html");
|
||||
|
||||
let paths_to_vendor = default_paths_to_vendor(builder);
|
||||
for (_, submodules) in &paths_to_vendor {
|
||||
for submodule in submodules {
|
||||
builder.build.require_submodule(submodule, None);
|
||||
}
|
||||
}
|
||||
let cargo_manifests = paths_to_vendor
|
||||
.into_iter()
|
||||
.map(|(path, _submodules)| path.to_str().unwrap().to_string())
|
||||
.inspect(|path| assert!(!path.contains(','), "{path} contains a comma in its name"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(",");
|
||||
|
||||
let mut cmd = builder.tool_cmd(Tool::GenerateCopyright);
|
||||
cmd.env("CARGO_MANIFESTS", &cargo_manifests);
|
||||
cmd.env("LICENSE_METADATA", &license_metadata);
|
||||
cmd.env("DEST", &dest);
|
||||
cmd.env("DEST_LIBSTD", &dest_libstd);
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ pub fn get_metadata_and_notices(
|
|||
cargo: &Path,
|
||||
vendor_path: &Path,
|
||||
root_path: &Path,
|
||||
manifest_paths: &[&Path],
|
||||
manifest_paths: &[PathBuf],
|
||||
) -> Result<BTreeMap<Package, PackageMetadata>, Error> {
|
||||
let mut output = get_metadata(cargo, root_path, manifest_paths)?;
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ pub fn get_metadata_and_notices(
|
|||
pub fn get_metadata(
|
||||
cargo: &Path,
|
||||
root_path: &Path,
|
||||
manifest_paths: &[&Path],
|
||||
manifest_paths: &[PathBuf],
|
||||
) -> Result<BTreeMap<Package, PackageMetadata>, Error> {
|
||||
let mut output = BTreeMap::new();
|
||||
// Look at the metadata for each manifest
|
||||
|
|
@ -114,7 +114,7 @@ pub fn get_metadata(
|
|||
}
|
||||
|
||||
/// Run cargo-vendor, fetching into the given dir
|
||||
fn run_cargo_vendor(cargo: &Path, dest: &Path, manifest_paths: &[&Path]) -> Result<(), Error> {
|
||||
fn run_cargo_vendor(cargo: &Path, dest: &Path, manifest_paths: &[PathBuf]) -> Result<(), Error> {
|
||||
let mut vendor_command = std::process::Command::new(cargo);
|
||||
vendor_command.env("RUSTC_BOOTSTRAP", "1");
|
||||
vendor_command.arg("vendor");
|
||||
|
|
|
|||
|
|
@ -22,25 +22,35 @@ fn main() -> Result<(), Error> {
|
|||
let cargo = env_path("CARGO")?;
|
||||
let license_metadata = env_path("LICENSE_METADATA")?;
|
||||
|
||||
let root_path = std::path::absolute(".")?;
|
||||
let cargo_manifests = env_string("CARGO_MANIFESTS")?
|
||||
.split(",")
|
||||
.map(|manifest| manifest.into())
|
||||
.collect::<Vec<PathBuf>>();
|
||||
let library_manifests = cargo_manifests
|
||||
.iter()
|
||||
.filter(|path| {
|
||||
if let Ok(stripped) = path.strip_prefix(&src_dir) {
|
||||
stripped.starts_with("library")
|
||||
} else {
|
||||
panic!("manifest {path:?} not relative to source dir {src_dir:?}");
|
||||
}
|
||||
})
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Scan Cargo dependencies
|
||||
let mut collected_cargo_metadata = cargo_metadata::get_metadata_and_notices(
|
||||
&cargo,
|
||||
&out_dir.join("vendor"),
|
||||
&src_dir,
|
||||
&[
|
||||
Path::new("./Cargo.toml"),
|
||||
Path::new("./src/tools/cargo/Cargo.toml"),
|
||||
Path::new("./library/Cargo.toml"),
|
||||
],
|
||||
&cargo_manifests,
|
||||
)?;
|
||||
|
||||
let library_collected_cargo_metadata = cargo_metadata::get_metadata_and_notices(
|
||||
&cargo,
|
||||
&out_dir.join("library-vendor"),
|
||||
&src_dir,
|
||||
&[Path::new("./library/Cargo.toml")],
|
||||
&library_manifests,
|
||||
)?;
|
||||
|
||||
for (key, value) in collected_cargo_metadata.iter_mut() {
|
||||
|
|
@ -194,6 +204,17 @@ struct License {
|
|||
copyright: Vec<String>,
|
||||
}
|
||||
|
||||
/// Grab an environment variable as string, or fail nicely.
|
||||
fn env_string(var: &str) -> Result<String, Error> {
|
||||
match std::env::var(var) {
|
||||
Ok(var) => Ok(var),
|
||||
Err(std::env::VarError::NotUnicode(_)) => {
|
||||
anyhow::bail!("environment variable {var} is not utf-8")
|
||||
}
|
||||
Err(std::env::VarError::NotPresent) => anyhow::bail!("missing environment variable {var}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Grab an environment variable as a PathBuf, or fail nicely.
|
||||
fn env_path(var: &str) -> Result<PathBuf, Error> {
|
||||
if let Some(var) = std::env::var_os(var) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue