MCPcopy Create free account
hub / github.com/nodejs/node / AddOrGetFileByPath

Method AddOrGetFileByPath

tools/gyp/pylib/gyp/xcodeproj_file.py:1280–1376  ·  view source on GitHub ↗

Returns an existing or new file reference corresponding to path. If hierarchical is True, this method will create or use the necessary hierarchical group structure corresponding to path. Otherwise, it will look in and create an item in the current group only. If an

(self, path, hierarchical)

Source from the content-addressed store, hash-verified

1278 return None
1279
1280 def AddOrGetFileByPath(self, path, hierarchical):
1281 """Returns an existing or new file reference corresponding to path.
1282
1283 If hierarchical is True, this method will create or use the necessary
1284 hierarchical group structure corresponding to path. Otherwise, it will
1285 look in and create an item in the current group only.
1286
1287 If an existing matching reference is found, it is returned, otherwise, a
1288 new one will be created, added to the correct group, and returned.
1289
1290 If path identifies a directory by virtue of carrying a trailing slash,
1291 this method returns a PBXFileReference of "folder" type. If path
1292 identifies a variant, by virtue of it identifying a file inside a directory
1293 with an ".lproj" extension, this method returns a PBXVariantGroup
1294 containing the variant named by path, and possibly other variants. For
1295 all other paths, a "normal" PBXFileReference will be returned.
1296 """
1297
1298 # Adding or getting a directory? Directories end with a trailing slash.
1299 is_dir = False
1300 if path.endswith("/"):
1301 is_dir = True
1302 path = posixpath.normpath(path)
1303 if is_dir:
1304 path = path + "/"
1305
1306 # Adding or getting a variant? Variants are files inside directories
1307 # with an ".lproj" extension. Xcode uses variants for localization. For
1308 # a variant path/to/Language.lproj/MainMenu.nib, put a variant group named
1309 # MainMenu.nib inside path/to, and give it a variant named Language. In
1310 # this example, grandparent would be set to path/to and parent_root would
1311 # be set to Language.
1312 variant_name = None
1313 parent = posixpath.dirname(path)
1314 grandparent = posixpath.dirname(parent)
1315 parent_basename = posixpath.basename(parent)
1316 (parent_root, parent_ext) = posixpath.splitext(parent_basename)
1317 if parent_ext == ".lproj":
1318 variant_name = parent_root
1319 if grandparent == "":
1320 grandparent = None
1321
1322 # Putting a directory inside a variant group is not currently supported.
1323 assert not is_dir or variant_name is None
1324
1325 path_split = path.split(posixpath.sep)
1326 if (
1327 len(path_split) == 1
1328 or ((is_dir or variant_name is not None) and len(path_split) == 2)
1329 or not hierarchical
1330 ):
1331 # The PBXFileReference or PBXVariantGroup will be added to or gotten from
1332 # this PBXGroup, no recursion necessary.
1333 if variant_name is None:
1334 # Add or get a PBXFileReference.
1335 file_ref = self.GetChildByPath(path)
1336 if file_ref is not None:
1337 assert file_ref.__class__ == PBXFileReference

Callers 3

GenerateOutputFunction · 0.95
AddFileMethod · 0.80

Calls 7

GetChildByPathMethod · 0.95
AppendChildMethod · 0.95
PBXFileReferenceClass · 0.85
PBXGroupClass · 0.85
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected