From 826a113bcb8951525e0b01c62825a58b6aea4921 Mon Sep 17 00:00:00 2001 From: Alex Hornby Date: Tue, 16 Jul 2024 06:20:01 -0700 Subject: [PATCH] allow repeat runs of cargo build Summary: The cargo config was being unconditionally added, resutling in "duplicate key `crates-io` in table `source`" error check if snippet is present before writing Reviewed By: mzr Differential Revision: D59803494 fbshipit-source-id: 701773d604c91fd6724069b0451b212cf0018251 --- build/fbcode_builder/getdeps/cargo.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/build/fbcode_builder/getdeps/cargo.py b/build/fbcode_builder/getdeps/cargo.py index dde73ba8..cae8bf54 100644 --- a/build/fbcode_builder/getdeps/cargo.py +++ b/build/fbcode_builder/getdeps/cargo.py @@ -126,6 +126,19 @@ def _create_cargo_config(self): if override not in cargo_content: new_content += override + if self.build_opts.fbsource_dir: + # Point to vendored crates.io if possible + try: + from .facebook.rust import vendored_crates + + new_content = vendored_crates( + self.build_opts.fbsource_dir, new_content + ) + except ImportError: + # This FB internal module isn't shippped to github, + # so just rely on cargo downloading crates on it's own + pass + if new_content != cargo_content: with open(cargo_config_file, "w") as f: print( @@ -133,17 +146,6 @@ def _create_cargo_config(self): ) f.write(new_content) - if self.build_opts.fbsource_dir: - # Point to vendored crates.io if possible - try: - from .facebook.rust import vendored_crates - - vendored_crates(self.build_opts.fbsource_dir, cargo_config_file) - except ImportError: - # This FB internal module isn't shippped to github, - # so just rely on cargo downloading crates on it's own - pass - return dep_to_git def _prepare(self, reconfigure) -> None: