@@ -813,12 +813,22 @@ def _build(self, install_dirs, reconfigure):
813
813
814
814
class CargoBuilder (BuilderBase ):
815
815
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 ,
817
826
):
818
827
super (CargoBuilder , self ).__init__ (
819
828
build_opts , ctx , manifest , src_dir , build_dir , inst_dir
820
829
)
821
830
self .build_doc = build_doc
831
+ self .ws_dir = workspace_dir
822
832
self .loader = loader
823
833
824
834
def run_cargo (self , install_dirs , operation , args = None ):
@@ -832,11 +842,14 @@ def run_cargo(self, install_dirs, operation, args=None):
832
842
"--workspace" ,
833
843
"-j%s" % self .build_opts .num_jobs ,
834
844
] + args
835
- self ._run_cmd (cmd , cwd = self .build_source_dir (), env = env )
845
+ self ._run_cmd (cmd , cwd = self .workspace_dir (), env = env )
836
846
837
847
def build_source_dir (self ):
838
848
return os .path .join (self .build_dir , "source" )
839
849
850
+ def workspace_dir (self ):
851
+ return os .path .join (self .build_source_dir (), self .ws_dir )
852
+
840
853
def recreate_dir (self , src , dst ):
841
854
if os .path .isdir (dst ):
842
855
shutil .rmtree (dst )
@@ -862,7 +875,7 @@ def _build(self, install_dirs, reconfigure):
862
875
)
863
876
)
864
877
865
- self ._patchup_workspace (build_source_dir )
878
+ self ._patchup_workspace ()
866
879
867
880
try :
868
881
from getdeps .facebook .rust import vendored_crates
@@ -881,15 +894,14 @@ def run_tests(self, install_dirs, schedule_type, owner):
881
894
if self .build_doc :
882
895
self .run_cargo (install_dirs , "doc" , ["--no-deps" ])
883
896
884
- def _patchup_workspace (self , build_source_dir ):
897
+ def _patchup_workspace (self ):
885
898
"""
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
890
902
using _extract_crates function. It is using a heuristic so check its
891
903
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
893
905
dependency's install dir using _resolve_crate_to_path function
894
906
which again is using a heuristic.
895
907
@@ -902,9 +914,10 @@ def _patchup_workspace(self, build_source_dir):
902
914
Exception. There migh be more cases where the code will silently pass
903
915
producing bad results.
904
916
"""
905
- config = self ._resolve_config (build_source_dir )
917
+ workspace_dir = self .workspace_dir ()
918
+ config = self ._resolve_config ()
906
919
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 :
908
921
# A fake manifest has to be crated to change the virtual
909
922
# manifest into a non-virtual. The virtual manifests are limited
910
923
# in many ways and the inability to define patches on them is
@@ -923,15 +936,15 @@ def _patchup_workspace(self, build_source_dir):
923
936
)
924
937
f .write (config )
925
938
926
- def _resolve_config (self , build_source_dir ):
939
+ def _resolve_config (self ):
927
940
"""
928
941
Returns a configuration to be put inside root Cargo.toml file which
929
942
patches the dependencies git code with local getdeps versions.
930
943
See https://doc.rust-lang.org/cargo/reference/manifest.html#the-patch-section
931
944
"""
932
945
dep_to_git = self ._resolve_dep_to_git ()
933
946
dep_to_crates = CargoBuilder ._resolve_dep_to_crates (
934
- build_source_dir , dep_to_git
947
+ self . build_source_dir () , dep_to_git
935
948
)
936
949
937
950
config = []
@@ -960,7 +973,7 @@ def _resolve_dep_to_git(self):
960
973
"""
961
974
For each direct dependency of the currently build manifest check if it
962
975
is also cargo-builded and if yes then extract it's git configs and
963
- install dir
976
+ install dir
964
977
"""
965
978
dependencies = self .manifest .get_section_as_dict ("dependencies" , ctx = self .ctx )
966
979
if not dependencies :
0 commit comments