@@ -813,12 +813,22 @@ def _build(self, install_dirs, reconfigure):
813813
814814class CargoBuilder (BuilderBase ):
815815 def __init__ (
816- self , build_opts , ctx , manifest , src_dir , build_dir , inst_dir , build_doc , loader
816+ self ,
817+ build_opts ,
818+ ctx ,
819+ manifest ,
820+ src_dir ,
821+ build_dir ,
822+ inst_dir ,
823+ build_doc ,
824+ workspace_dir ,
825+ loader ,
817826 ):
818827 super (CargoBuilder , self ).__init__ (
819828 build_opts , ctx , manifest , src_dir , build_dir , inst_dir
820829 )
821830 self .build_doc = build_doc
831+ self .ws_dir = workspace_dir
822832 self .loader = loader
823833
824834 def run_cargo (self , install_dirs , operation , args = None ):
@@ -832,11 +842,14 @@ def run_cargo(self, install_dirs, operation, args=None):
832842 "--workspace" ,
833843 "-j%s" % self .build_opts .num_jobs ,
834844 ] + args
835- self ._run_cmd (cmd , cwd = self .build_source_dir (), env = env )
845+ self ._run_cmd (cmd , cwd = self .workspace_dir (), env = env )
836846
837847 def build_source_dir (self ):
838848 return os .path .join (self .build_dir , "source" )
839849
850+ def workspace_dir (self ):
851+ return os .path .join (self .build_source_dir (), self .ws_dir )
852+
840853 def recreate_dir (self , src , dst ):
841854 if os .path .isdir (dst ):
842855 shutil .rmtree (dst )
@@ -862,7 +875,7 @@ def _build(self, install_dirs, reconfigure):
862875 )
863876 )
864877
865- self ._patchup_workspace (build_source_dir )
878+ self ._patchup_workspace ()
866879
867880 try :
868881 from getdeps .facebook .rust import vendored_crates
@@ -881,15 +894,14 @@ def run_tests(self, install_dirs, schedule_type, owner):
881894 if self .build_doc :
882895 self .run_cargo (install_dirs , "doc" , ["--no-deps" ])
883896
884- def _patchup_workspace (self , build_source_dir ):
897+ def _patchup_workspace (self ):
885898 """
886- This method makes a lot of assumptions about the state of the project
887- and its cargo dependendies:
888- 1. There is a virtual manifest with workspace in the root of this project
889- 2. Crates from cargo dependencies can be extracted from Cargo.toml files
899+ This method makes some assumptions about the state of the project and
900+ its cargo dependendies:
901+ 1. Crates from cargo dependencies can be extracted from Cargo.toml files
890902 using _extract_crates function. It is using a heuristic so check its
891903 code to understand how it is done.
892- 3 . The extracted cargo dependencies crates can be found in the
904+ 2 . The extracted cargo dependencies crates can be found in the
893905 dependency's install dir using _resolve_crate_to_path function
894906 which again is using a heuristic.
895907
@@ -902,9 +914,10 @@ def _patchup_workspace(self, build_source_dir):
902914 Exception. There migh be more cases where the code will silently pass
903915 producing bad results.
904916 """
905- config = self ._resolve_config (build_source_dir )
917+ workspace_dir = self .workspace_dir ()
918+ config = self ._resolve_config ()
906919 if config :
907- with open (os .path .join (build_source_dir , "Cargo.toml" ), "a" ) as f :
920+ with open (os .path .join (workspace_dir , "Cargo.toml" ), "a" ) as f :
908921 # A fake manifest has to be crated to change the virtual
909922 # manifest into a non-virtual. The virtual manifests are limited
910923 # in many ways and the inability to define patches on them is
@@ -923,15 +936,15 @@ def _patchup_workspace(self, build_source_dir):
923936 )
924937 f .write (config )
925938
926- def _resolve_config (self , build_source_dir ):
939+ def _resolve_config (self ):
927940 """
928941 Returns a configuration to be put inside root Cargo.toml file which
929942 patches the dependencies git code with local getdeps versions.
930943 See https://doc.rust-lang.org/cargo/reference/manifest.html#the-patch-section
931944 """
932945 dep_to_git = self ._resolve_dep_to_git ()
933946 dep_to_crates = CargoBuilder ._resolve_dep_to_crates (
934- build_source_dir , dep_to_git
947+ self . build_source_dir () , dep_to_git
935948 )
936949
937950 config = []
@@ -960,7 +973,7 @@ def _resolve_dep_to_git(self):
960973 """
961974 For each direct dependency of the currently build manifest check if it
962975 is also cargo-builded and if yes then extract it's git configs and
963- install dir
976+ install dir
964977 """
965978 dependencies = self .manifest .get_section_as_dict ("dependencies" , ctx = self .ctx )
966979 if not dependencies :
0 commit comments