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

feat(metadata): Add profiles information to cargo metadata #12449

Closed
wants to merge 5 commits into from
Closed
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
431 changes: 250 additions & 181 deletions src/cargo/core/profiles.rs

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/cargo/ops/cargo_output_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ use crate::core::compiler::artifact::match_artifacts_kind_with_targets;
use crate::core::compiler::{CompileKind, RustcTargetData};
use crate::core::dependency::DepKind;
use crate::core::package::SerializedPackage;
use crate::core::profiles::{Profile, Profiles};
use crate::core::resolver::{features::CliFeatures, HasDevUnits, Resolve};
use crate::core::{Package, PackageId, Workspace};
use crate::ops::{self, Packages};
use crate::util::interning::InternedString;
use crate::util::CargoResult;
use cargo_platform::Platform;
use serde::Serialize;
use std::collections::BTreeMap;
use std::collections::{BTreeMap, HashMap};
use std::path::PathBuf;

const VERSION: u32 = 1;
Expand Down Expand Up @@ -49,6 +50,7 @@ pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> Cargo
version: VERSION,
workspace_root: ws.root().to_path_buf(),
metadata: ws.custom_metadata().cloned(),
profiles: Profiles::all(ws)?,
})
}

Expand All @@ -65,6 +67,7 @@ pub struct ExportInfo {
version: u32,
workspace_root: PathBuf,
metadata: Option<toml::Value>,
profiles: HashMap<InternedString, Profile>,
}

#[derive(Serialize)]
Expand Down
26 changes: 17 additions & 9 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use cargo_test_support::registry::{self, Package, RegistryBuilder};
use cargo_test_support::{basic_manifest, paths, project};
use std::fs;

use crate::metadata::DEFAULT_PROFILES;

#[cargo_test]
fn depend_on_alt_registry() {
registry::alt_init();
Expand Down Expand Up @@ -844,7 +846,7 @@ fn alt_reg_metadata() {
// iodep -> altdep2: alternative-registry
p.cargo("metadata --format-version=1 --no-deps")
.with_json(
r#"
&r#"
{
"packages": [
{
Expand Down Expand Up @@ -909,15 +911,17 @@ fn alt_reg_metadata() {
"target_directory": "[..]/foo/target",
"version": 1,
"workspace_root": "[..]/foo",
"metadata": null
}"#,
"metadata": null,
"profiles": $PROFILES
}"#
.replace("$PROFILES", DEFAULT_PROFILES),
)
.run();

// --no-deps uses a different code path, make sure both work.
p.cargo("metadata --format-version=1")
.with_json(
r#"
&r#"
{
"packages": [
{
Expand Down Expand Up @@ -1112,8 +1116,10 @@ fn alt_reg_metadata() {
"target_directory": "[..]/foo/target",
"version": 1,
"workspace_root": "[..]/foo",
"metadata": null
}"#,
"metadata": null,
"profiles": $PROFILES
}"#
.replace("$PROFILES", DEFAULT_PROFILES),
)
.run();
}
Expand Down Expand Up @@ -1160,7 +1166,7 @@ fn unknown_registry() {
// bar -> baz registry = alternate
p.cargo("metadata --format-version=1")
.with_json(
r#"
&r#"
{
"packages": [
{
Expand Down Expand Up @@ -1278,9 +1284,11 @@ fn unknown_registry() {
"target_directory": "[..]/foo/target",
"version": 1,
"workspace_root": "[..]/foo",
"metadata": null
"metadata": null,
"profiles": $PROFILES
}
"#,
"#
.replace("$PROFILES", DEFAULT_PROFILES),
)
.run();
}
Expand Down
10 changes: 7 additions & 3 deletions tests/testsuite/features_namespaced.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Tests for namespaced features.
use crate::metadata::DEFAULT_PROFILES;

use super::features2::switch_to_resolver_2;
use cargo_test_support::registry::{Dependency, Package, RegistryBuilder};
use cargo_test_support::{project, publish};
Expand Down Expand Up @@ -576,7 +578,7 @@ fn json_exposed() {

p.cargo("metadata --no-deps")
.with_json(
r#"
&r#"
{
"packages": [
{
Expand Down Expand Up @@ -614,9 +616,11 @@ fn json_exposed() {
"target_directory": "[..]foo/target",
"version": 1,
"workspace_root": "[..]foo",
"metadata": null
"metadata": null,
"profiles": $PROFILES
}
"#,
"#
.replace("$PROFILES", DEFAULT_PROFILES),
)
.run();
}
Expand Down
6 changes: 5 additions & 1 deletion tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use cargo_test_support::registry::Package;
use cargo_test_support::{basic_lib_manifest, basic_manifest, git, main_file, path2url, project};
use cargo_test_support::{sleep_ms, t, Project};

use crate::metadata::DEFAULT_PROFILES;

#[cargo_test]
fn cargo_compile_simple_git_dep() {
let project = project();
Expand Down Expand Up @@ -3370,11 +3372,13 @@ fn metadata_master_consistency() {
"target_directory": "[..]",
"version": 1,
"workspace_root": "[..]",
"metadata": null
"metadata": null,
"profiles": $PROFILES
}
"#
.replace("__BAR_SOURCE__", bar_source)
.replace("__BAR_HASH__", &bar_hash)
.replace("$PROFILES", DEFAULT_PROFILES)
};

let bar_source = format!("git+{}?branch=master", git_project.url());
Expand Down
Loading