Skip to content
Merged
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
9 changes: 9 additions & 0 deletions prdoc/pr_7928.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: Fix pallet-revive-fixtures build.rs
doc:
- audience: Runtime Dev
description: |-
Fix pallet-revive-uapi resolution when building pallet-revive-fixtures
contracts
crates:
- name: pallet-revive-fixtures
bump: patch
29 changes: 20 additions & 9 deletions substrate/frame/revive/fixtures/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,30 @@ fn create_cargo_toml<'a>(
let mut cargo_toml: toml::Value = toml::from_str(include_str!("./build/_Cargo.toml"))?;
let uapi_dep = cargo_toml["dependencies"]["uapi"].as_table_mut().unwrap();

let metadata = MetadataCommand::new()
.manifest_path(fixtures_dir.join("Cargo.toml"))
.exec()
.expect("Failed to fetch cargo metadata");
let manifest_path = fixtures_dir.join("Cargo.toml");
let metadata = MetadataCommand::new().manifest_path(&manifest_path).exec().unwrap();
let dependency_graph = metadata.resolve.unwrap();

let mut uapi_pkgs: Vec<_> = metadata
// Resolve the pallet-revive-fixtures package id
let fixtures_pkg_id = metadata
.packages
.iter()
.filter(|pkg| pkg.name == "pallet-revive-uapi")
.collect();
.find(|pkg| pkg.manifest_path.as_std_path() == manifest_path)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are still just picking the first package we find here. Why is the manifest path unique but the name is not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They look like that

      "manifest_path": "/home/pg/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/pallet-contracts-uapi-12.0.0/Cargo.toml",
      "manifest_path": "/home/pg/github/polkadot-sdk/substrate/frame/contracts/uapi/Cargo.toml",
      "manifest_path": "/home/pg/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/pallet-revive-uapi-0.1.1/Cargo.toml",

so we can pick the right one knowing the path to the manifest

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there might be a better approach but that seem to work ...

.map(|pkg| pkg.id.clone())
.unwrap();
let fixtures_pkg_node =
dependency_graph.nodes.iter().find(|node| node.id == fixtures_pkg_id).unwrap();

// Get the pallet-revive-uapi package id
let uapi_pkg_id = fixtures_pkg_node
.deps
.iter()
.find(|dep| dep.name == "pallet_revive_uapi")
.map(|dep| dep.pkg.clone())
.expect("pallet-revive-uapi is a build dependency of pallet-revive-fixtures; qed");

uapi_pkgs.sort_by(|a, b| b.version.cmp(&a.version));
let uapi_pkg = uapi_pkgs.first().unwrap();
// Get pallet-revive-uapi package
let uapi_pkg = metadata.packages.iter().find(|pkg| pkg.id == uapi_pkg_id).unwrap();

if uapi_pkg.source.is_none() {
uapi_dep.insert(
Expand Down
Loading