MCPcopy Create free account
hub / github.com/SolaWing/xcode-build-server / new_file

Method new_file

compile_database.py:233–296  ·  view source on GitHub ↗
(self, filename)

Source from the content-addressed store, hash-verified

231 # hack new file into current compile file
232 # return: set of filekey for match for file. or None if new_file can't be infered
233 def new_file(self, filename):
234 # Currently only processing swift files
235 if not filename.endswith(".swift"):
236 return
237
238 filename = os.path.realpath(filename)
239 filename_key = filename.lower()
240 if filename_key in self.file_info:
241 return {filename_key} # already handled
242
243 dir = os.path.dirname(filename_key)
244
245 # 1. First look for existing swift files in the current directory
246 similar_compiled_file = next(
247 (v for v in self.groupby_dir().get(
248 dir, ()) if v.endswith(".swift")), None
249 )
250
251 # 2. If not found in current directory, search upward through parent directories until project root
252 if not similar_compiled_file:
253 current_dir = dir
254 while current_dir and current_dir != "/":
255 parent_dir = os.path.dirname(current_dir)
256
257 # Look for swift files in parent directory
258 similar_compiled_file = next(
259 (v for v in self.groupby_dir().get(
260 parent_dir, ()) if v.endswith(".swift")), None
261 )
262 if similar_compiled_file:
263 break
264
265 # If reached project root, stop searching
266 if isProjectRoot(parent_dir):
267 break
268
269 current_dir = parent_dir
270
271 if not similar_compiled_file:
272 return
273
274 logging.info(
275 f"Found new file: {filename} with similar_compiled_file: {similar_compiled_file}")
276
277 command = self.file_info[similar_compiled_file]
278
279 cmd_match = next(cmd_split_pattern.finditer(command), None)
280 if not cmd_match:
281 return
282 assert self.cmd_info # init in groupby_dir
283 module_files = self.cmd_info.pop(command)
284 index = cmd_match.end()
285 from shlex import quote
286
287 command = "".join(
288 (command[:index], " ", quote(filename), command[index:]))
289
290 # update command info

Callers 2

compileFileInfoFromStoreFunction · 0.95
newfileForCompileFileFunction · 0.45

Calls 3

groupby_dirMethod · 0.95
isProjectRootFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected