def _resolve_config()

in build/fbcode_builder/getdeps/cargo.py [0:0]


    def _resolve_config(self, dep_to_git) -> str:
        """
        Returns a configuration to be put inside root Cargo.toml file which
        patches the dependencies git code with local getdeps versions.
        See https://doc.rust-lang.org/cargo/reference/manifest.html#the-patch-section
        """
        dep_to_crates = self._resolve_dep_to_crates(self.build_source_dir(), dep_to_git)

        config = []

        git_url_to_crates_and_paths = {}
        for dep_name in sorted(dep_to_git.keys()):
            git_conf = dep_to_git[dep_name]
            req_crates = sorted(dep_to_crates.get(dep_name, []))
            if not req_crates:
                continue  # nothing to patch, move along

            git_url = git_conf.get("repo_url", None)
            crate_source_map = git_conf["crate_source_map"]
            if git_url and crate_source_map:
                crates_to_patch_path = git_url_to_crates_and_paths.get(git_url, {})
                for c in req_crates:
                    if c in crate_source_map and c not in crates_to_patch_path:
                        crates_to_patch_path[c] = crate_source_map[c]
                        print(
                            f"{self.manifest.name}: Patching crate {c} via virtual manifest in {self.workspace_dir()}"
                        )
                if crates_to_patch_path:
                    git_url_to_crates_and_paths[git_url] = crates_to_patch_path

        for git_url, crates_to_patch_path in git_url_to_crates_and_paths.items():
            crates_patches = [
                '{} = {{ path = "{}" }}'.format(
                    crate,
                    crates_to_patch_path[crate].replace("\\", "\\\\"),
                )
                for crate in sorted(crates_to_patch_path.keys())
            ]
            config.append(f'\n[patch."{git_url}"]\n' + "\n".join(crates_patches))

        return "\n".join(config)