@@ -89,19 +89,19 @@ def _uses_workspace_dependencies(cargo_toml_json):
8989 for spec in cargo_toml_json .get ("dependencies" , {}).values ():
9090 if type (spec ) == "dict" and spec .get ("workspace" ) == True :
9191 return True
92-
9392 for spec in cargo_toml_json .get ("build-dependencies" , {}).values ():
9493 if type (spec ) == "dict" and spec .get ("workspace" ) == True :
9594 return True
96-
97- for target in cargo_toml_json .get ("target" , {}).values ():
98- for spec in target .get ("dependencies" , {}).values ():
95+ for value in cargo_toml_json .get ("target" , {}).values ():
96+ for spec in value .get ("dependencies" , {}).values ():
97+ if type (spec ) == "dict" and spec .get ("workspace" ) == True :
98+ return True
99+ for spec in value .get ("build-dependencies" , {}).values ():
99100 if type (spec ) == "dict" and spec .get ("workspace" ) == True :
100101 return True
101-
102102 return False
103103
104- def _cargo_toml_fact (cargo_toml_json , annotation , workspace_cargo_toml_json , strip_prefix = "" ):
104+ def _cargo_toml_fact (cargo_toml_json , annotation , workspace_cargo_toml_json , strip_prefix = None ):
105105 if _uses_workspace_dependencies (cargo_toml_json ):
106106 workspace = (workspace_cargo_toml_json or {}).get ("workspace" )
107107 if not workspace and annotation .workspace_cargo_toml != "Cargo.toml" :
@@ -164,20 +164,21 @@ def _generate_hub_and_spokes(
164164 existing_facts = getattr (mctx , "facts" , {}) or {}
165165 facts = {}
166166
167- split_packages = split_lockfile_packages (
168- hub_name ,
169- cargo_metadata ,
170- workspace_cargo_toml_json ,
171- all_packages ,
167+ workspace_root = _normalize_path (cargo_metadata ["workspace_root" ])
168+ lockfile_package_info = split_lockfile_packages (
169+ hub_name = hub_name ,
170+ cargo_metadata = cargo_metadata ,
171+ all_packages = all_packages ,
172+ workspace_cargo_toml = workspace_cargo_toml_json ,
173+ repo_root = workspace_root ,
172174 )
173- packages = split_packages . packages
174- workspace_members = split_packages . workspace_members
175+ workspace_members = lockfile_package_info . workspace_members
176+ packages = lockfile_package_info . packages
175177
176178 mctx .report_progress ("Computing dependencies and features" )
177179
178180 facts_by_fq_crate = {}
179- for package_index in range (len (packages )):
180- package = packages [package_index ]
181+ for package in packages :
181182 name = package ["name" ]
182183 version = package ["version" ]
183184 source = package ["source" ]
@@ -238,7 +239,8 @@ def _generate_hub_and_spokes(
238239 mctx .watch (mctx .path (cargo_toml_path ))
239240 annotation = annotation_for (annotations , name , package ["version" ])
240241 cargo_toml_json = run_toml2json (mctx , cargo_toml_path )
241- fact = _cargo_toml_fact (cargo_toml_json , annotation , {})
242+
243+ fact = _cargo_toml_fact (cargo_toml_json , annotation , workspace_cargo_toml_json , strip_prefix = "" )
242244
243245 facts [key ] = json .encode (fact )
244246 package ["strip_prefix" ] = fact .get ("strip_prefix" , "" )
@@ -276,9 +278,9 @@ def _generate_hub_and_spokes(
276278
277279 facts_by_fq_crate [_fq_crate (name , version )] = fact
278280
279- resolved_facts = resolve_package_facts (packages , facts_by_fq_crate , platform_triples )
280- feature_resolutions_by_fq_crate = resolved_facts . feature_resolutions_by_fq_crate
281- versions_by_name = resolved_facts . versions_by_name
281+ package_fact_info = resolve_package_facts (packages , facts_by_fq_crate , platform_triples )
282+ versions_by_name = package_fact_info . versions_by_name
283+ feature_resolutions_by_fq_crate = package_fact_info . feature_resolutions_by_fq_crate
282284
283285 # Only files in the current Bazel workspace can/should be watched, so check where our manifests are located.
284286 watch_manifests = cargo_lock_path .repo_name == ""
0 commit comments