Skip to content

Commit 1070be2

Browse files
committed
Expose all profiles in the workspace.
Implement a new method Profiles::all that returns all profiles in the workspace, including the root and predefined profiles. This new method follows Cargo resolution rules to resolve profile inheritance and ordering. Signed-off-by: David Calavera <david.calavera@gmail.com>
1 parent 30af6de commit 1070be2

File tree

8 files changed

+661
-292
lines changed

8 files changed

+661
-292
lines changed

src/cargo/core/profiles.rs

Lines changed: 250 additions & 181 deletions
Large diffs are not rendered by default.

src/cargo/ops/cargo_output_metadata.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ use crate::core::compiler::artifact::match_artifacts_kind_with_targets;
22
use crate::core::compiler::{CompileKind, RustcTargetData};
33
use crate::core::dependency::DepKind;
44
use crate::core::package::SerializedPackage;
5+
use crate::core::profiles::{Profile, Profiles};
56
use crate::core::resolver::{features::CliFeatures, HasDevUnits, Resolve};
67
use crate::core::{Package, PackageId, Workspace};
78
use crate::ops::{self, Packages};
89
use crate::util::interning::InternedString;
9-
use crate::util::toml::TomlProfiles;
1010
use crate::util::CargoResult;
1111
use cargo_platform::Platform;
1212
use serde::Serialize;
13-
use std::collections::BTreeMap;
13+
use std::collections::{BTreeMap, HashMap};
1414
use std::path::PathBuf;
1515

1616
const VERSION: u32 = 1;
@@ -50,7 +50,7 @@ pub fn output_metadata(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> Cargo
5050
version: VERSION,
5151
workspace_root: ws.root().to_path_buf(),
5252
metadata: ws.custom_metadata().cloned(),
53-
profiles: ws.profiles().cloned(),
53+
profiles: Profiles::all(ws)?,
5454
})
5555
}
5656

@@ -67,8 +67,7 @@ pub struct ExportInfo {
6767
version: u32,
6868
workspace_root: PathBuf,
6969
metadata: Option<toml::Value>,
70-
#[serde(skip_serializing_if = "Option::is_none")]
71-
profiles: Option<TomlProfiles>,
70+
profiles: HashMap<InternedString, Profile>,
7271
}
7372

7473
#[derive(Serialize)]

tests/testsuite/alt_registry.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use cargo_test_support::registry::{self, Package, RegistryBuilder};
66
use cargo_test_support::{basic_manifest, paths, project};
77
use std::fs;
88

9+
use crate::metadata::DEFAULT_PROFILES;
10+
911
#[cargo_test]
1012
fn depend_on_alt_registry() {
1113
registry::alt_init();
@@ -844,7 +846,7 @@ fn alt_reg_metadata() {
844846
// iodep -> altdep2: alternative-registry
845847
p.cargo("metadata --format-version=1 --no-deps")
846848
.with_json(
847-
r#"
849+
&r#"
848850
{
849851
"packages": [
850852
{
@@ -909,15 +911,17 @@ fn alt_reg_metadata() {
909911
"target_directory": "[..]/foo/target",
910912
"version": 1,
911913
"workspace_root": "[..]/foo",
912-
"metadata": null
913-
}"#,
914+
"metadata": null,
915+
"profiles": $PROFILES
916+
}"#
917+
.replace("$PROFILES", DEFAULT_PROFILES),
914918
)
915919
.run();
916920

917921
// --no-deps uses a different code path, make sure both work.
918922
p.cargo("metadata --format-version=1")
919923
.with_json(
920-
r#"
924+
&r#"
921925
{
922926
"packages": [
923927
{
@@ -1112,8 +1116,10 @@ fn alt_reg_metadata() {
11121116
"target_directory": "[..]/foo/target",
11131117
"version": 1,
11141118
"workspace_root": "[..]/foo",
1115-
"metadata": null
1116-
}"#,
1119+
"metadata": null,
1120+
"profiles": $PROFILES
1121+
}"#
1122+
.replace("$PROFILES", DEFAULT_PROFILES),
11171123
)
11181124
.run();
11191125
}
@@ -1160,7 +1166,7 @@ fn unknown_registry() {
11601166
// bar -> baz registry = alternate
11611167
p.cargo("metadata --format-version=1")
11621168
.with_json(
1163-
r#"
1169+
&r#"
11641170
{
11651171
"packages": [
11661172
{
@@ -1278,9 +1284,11 @@ fn unknown_registry() {
12781284
"target_directory": "[..]/foo/target",
12791285
"version": 1,
12801286
"workspace_root": "[..]/foo",
1281-
"metadata": null
1287+
"metadata": null,
1288+
"profiles": $PROFILES
12821289
}
1283-
"#,
1290+
"#
1291+
.replace("$PROFILES", DEFAULT_PROFILES),
12841292
)
12851293
.run();
12861294
}

tests/testsuite/features_namespaced.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Tests for namespaced features.
22
3+
use crate::metadata::DEFAULT_PROFILES;
4+
35
use super::features2::switch_to_resolver_2;
46
use cargo_test_support::registry::{Dependency, Package, RegistryBuilder};
57
use cargo_test_support::{project, publish};
@@ -576,7 +578,7 @@ fn json_exposed() {
576578

577579
p.cargo("metadata --no-deps")
578580
.with_json(
579-
r#"
581+
&r#"
580582
{
581583
"packages": [
582584
{
@@ -614,9 +616,11 @@ fn json_exposed() {
614616
"target_directory": "[..]foo/target",
615617
"version": 1,
616618
"workspace_root": "[..]foo",
617-
"metadata": null
619+
"metadata": null,
620+
"profiles": $PROFILES
618621
}
619-
"#,
622+
"#
623+
.replace("$PROFILES", DEFAULT_PROFILES),
620624
)
621625
.run();
622626
}

tests/testsuite/git.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use cargo_test_support::registry::Package;
1515
use cargo_test_support::{basic_lib_manifest, basic_manifest, git, main_file, path2url, project};
1616
use cargo_test_support::{sleep_ms, t, Project};
1717

18+
use crate::metadata::DEFAULT_PROFILES;
19+
1820
#[cargo_test]
1921
fn cargo_compile_simple_git_dep() {
2022
let project = project();
@@ -3370,11 +3372,13 @@ fn metadata_master_consistency() {
33703372
"target_directory": "[..]",
33713373
"version": 1,
33723374
"workspace_root": "[..]",
3373-
"metadata": null
3375+
"metadata": null,
3376+
"profiles": $PROFILES
33743377
}
33753378
"#
33763379
.replace("__BAR_SOURCE__", bar_source)
33773380
.replace("__BAR_HASH__", &bar_hash)
3381+
.replace("$PROFILES", DEFAULT_PROFILES)
33783382
};
33793383

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

0 commit comments

Comments
 (0)