void RefreshMapsForGroupChildren(string projectPath, string realPath, PBXSourceTree realPathTree, PBXGroupData parent) { var children = new List <string>(parent.children); foreach (string guid in children) { PBXFileReferenceData fileRef = fileRefs[guid]; string pPath; string rPath; PBXSourceTree rTree; if (fileRef != null) { pPath = PBXPath.Combine(projectPath, fileRef.name); PBXPath.Combine(realPath, realPathTree, fileRef.path, fileRef.tree, out rPath, out rTree); if (!m_ProjectPathToFileRefMap.ContainsKey(pPath)) { m_ProjectPathToFileRefMap.Add(pPath, fileRef); } if (!m_FileRefGuidToProjectPathMap.ContainsKey(fileRef.guid)) { m_FileRefGuidToProjectPathMap.Add(fileRef.guid, pPath); } if (!m_RealPathToFileRefMap[rTree].ContainsKey(rPath)) { m_RealPathToFileRefMap[rTree].Add(rPath, fileRef); } if (!m_GuidToParentGroupMap.ContainsKey(guid)) { m_GuidToParentGroupMap.Add(guid, parent); } continue; } PBXGroupData gr = groups[guid]; if (gr != null) { pPath = PBXPath.Combine(projectPath, gr.name); PBXPath.Combine(realPath, realPathTree, gr.path, gr.tree, out rPath, out rTree); if (!m_ProjectPathToGroupMap.ContainsKey(pPath)) { m_ProjectPathToGroupMap.Add(pPath, gr); } if (!m_GroupGuidToProjectPathMap.ContainsKey(gr.guid)) { m_GroupGuidToProjectPathMap.Add(gr.guid, pPath); } if (!m_GuidToParentGroupMap.ContainsKey(guid)) { m_GuidToParentGroupMap.Add(guid, parent); } RefreshMapsForGroupChildren(pPath, rPath, rTree, gr); } } }
// Creates a directory structure with "provides namespace" attribute. // First, retrieves or creates the directory at relativeBasePath, creating parent // directories if needed. Effectively calls OpenFolder(relativeBasePath). // Then, relative to this directory, creates namespacePath directories with "provides // namespace" attribute set. Fails if the attribute can't be set. public AssetFolder OpenNamespacedFolder(string relativeBasePath, string namespacePath) { var folder = OpenFolder(relativeBasePath); var pathItems = PBXPath.Split(namespacePath); foreach (var pathItem in pathItems) { folder = folder.OpenFolder(pathItem); folder.providesNamespace = true; } return(folder); }
/// <summary> /// Writes the modifications to the project file, entitlements file and /// the Info.plist file. Any external changes to these files after /// the ProjectCapabilityManager instance has been created and before /// the call to WriteToFile() will be overwritten. /// </summary> public void WriteToFile() { File.WriteAllText(m_PBXProjectPath, project.WriteToString()); if (m_Entitlements != null) { m_Entitlements.WriteToFile(PBXPath.Combine(m_BuildPath, m_EntitlementFilePath)); } if (m_InfoPlist != null) { m_InfoPlist.WriteToFile(PBXPath.Combine(m_BuildPath, "Info.plist")); } }
AssetFolder OpenFolderForResource(string relativePath) { var pathItems = PBXPath.Split(relativePath).ToList(); // remove path filename pathItems.RemoveAt(pathItems.Count - 1); AssetFolder folder = root; foreach (var pathItem in pathItems) { folder = folder.OpenFolder(pathItem); } return(folder); }
public XCModFile(string inputString) { isWeak = false; if (inputString.Contains(":")) { string[] parts = inputString.Split(':'); filePath = PBXPath.FixSlashes(parts[0]); isWeak = string.Equals(parts[1], "weak", StringComparison.OrdinalIgnoreCase); } else { filePath = inputString; } }
private PlistDocument GetOrCreateEntitlementDoc() { if (m_Entitlements == null) { m_Entitlements = new PlistDocument(); if (File.Exists(PBXPath.Combine(m_BuildPath, m_EntitlementFilePath))) { m_Entitlements.ReadFromFile(PBXPath.Combine(m_BuildPath, m_EntitlementFilePath)); } else { m_Entitlements.Create(); } } return(m_Entitlements); }
internal static void AddExternalLibraryDependency(this PBXProject proj, string targetGuid, string filename, string remoteFileGuid, string projectPath, string remoteInfo) { PBXNativeTargetData target = proj.nativeTargets[targetGuid]; filename = PBXPath.FixSlashes(filename); projectPath = PBXPath.FixSlashes(projectPath); string fileGuidByRealPath = proj.FindFileGuidByRealPath(projectPath); if (fileGuidByRealPath == null) { throw new Exception("No such project"); } string guid = (string)null; foreach (ProjectReference projectReference in proj.project.project.projectReferences) { if (projectReference.projectRef == fileGuidByRealPath) { guid = projectReference.group; break; } } if (guid == null) { throw new Exception("Malformed project: no project in project references"); } PBXGroupData pbxGroupData = proj.GroupsGet(guid); string extension = Path.GetExtension(filename); if (!FileTypeUtils.IsBuildableFile(extension)) { throw new Exception("Wrong file extension"); } PBXContainerItemProxyData containerItemProxyData = PBXContainerItemProxyData.Create(fileGuidByRealPath, "2", remoteFileGuid, remoteInfo); proj.containerItems.AddEntry(containerItemProxyData); string typeName = FileTypeUtils.GetTypeName(extension); PBXReferenceProxyData referenceProxyData = PBXReferenceProxyData.Create(filename, typeName, containerItemProxyData.guid, "BUILT_PRODUCTS_DIR"); proj.references.AddEntry(referenceProxyData); PBXBuildFileData fromFile = PBXBuildFileData.CreateFromFile(referenceProxyData.guid, false, (string)null); proj.BuildFilesAdd(targetGuid, fromFile); proj.BuildSectionAny(target, extension, false).files.AddGUID(fromFile.guid); pbxGroupData.children.AddGUID(referenceProxyData.guid); }
internal static void AddExternalProjectDependency(this PBXProject proj, string path, string projectPath, PBXSourceTree sourceTree) { if (sourceTree == PBXSourceTree.Group) { throw new Exception("sourceTree must not be PBXSourceTree.Group"); } path = PBXPath.FixSlashes(path); projectPath = PBXPath.FixSlashes(projectPath); PBXGroupData relative = PBXGroupData.CreateRelative("Products"); proj.GroupsAddDuplicate(relative); PBXFileReferenceData fromFile = PBXFileReferenceData.CreateFromFile(path, Path.GetFileName(projectPath), sourceTree); proj.FileRefsAdd(path, projectPath, (PBXGroupData)null, fromFile); proj.CreateSourceGroup(PBXPath.GetDirectory(projectPath)).children.AddGUID(fromFile.guid); proj.project.project.AddReference(relative.guid, fromFile.guid); }
// Checks if a folder with given path exists and returns it if it does. // Otherwise, creates a new folder. Parent folders are created if needed. public AssetFolder OpenFolder(string relativePath) { if (relativePath == null) { return(root); } var pathItems = PBXPath.Split(relativePath); if (pathItems.Length == 0) { return(root); } AssetFolder folder = root; foreach (var pathItem in pathItems) { folder = folder.OpenFolder(pathItem); } return(folder); }
/// <summary> /// Adds an external project dependency to the project. /// </summary> /// <param name="path">The path to the external Xcode project (the .xcodeproj file).</param> /// <param name="projectPath">The project path to the new project.</param> /// <param name="sourceTree">The source tree the path is relative to. The [[PBXSourceTree.Group]] tree is not supported.</param> internal static void AddExternalProjectDependency(this PBXProject proj, string path, string projectPath, PBXSourceTree sourceTree) { if (sourceTree == PBXSourceTree.Group) { throw new Exception("sourceTree must not be PBXSourceTree.Group"); } path = PBXPath.FixSlashes(path); projectPath = PBXPath.FixSlashes(projectPath); // note: we are duplicating products group for the project reference. Otherwise Xcode crashes. PBXGroupData productGroup = PBXGroupData.CreateRelative("Products"); proj.GroupsAddDuplicate(productGroup); // don't use GroupsAdd here PBXFileReferenceData fileRef = PBXFileReferenceData.CreateFromFile(path, Path.GetFileName(projectPath), sourceTree); proj.FileRefsAdd(path, projectPath, null, fileRef); proj.CreateSourceGroup(PBXPath.GetDirectory(projectPath)).children.AddGUID(fileRef.guid); proj.project.project.AddReference(productGroup.guid, fileRef.guid); }
/** This function must be called only after the project the library is in has * been added as a dependency via AddExternalProjectDependency. projectPath must be * the same as the 'path' parameter passed to the AddExternalProjectDependency. * remoteFileGuid must be the guid of the referenced file as specified in * PBXFileReference section of the external project * * TODO: what. is remoteInfo entry in PBXContainerItemProxy? Is in referenced project name or * referenced library name without extension? */ internal static void AddExternalLibraryDependency(this PBXProject proj, string targetGuid, string filename, string remoteFileGuid, string projectPath, string remoteInfo) { PBXNativeTargetData target = proj.nativeTargets[targetGuid]; filename = PBXPath.FixSlashes(filename); projectPath = PBXPath.FixSlashes(projectPath); // find the products group to put the new library in string projectGuid = proj.FindFileGuidByRealPath(projectPath); if (projectGuid == null) { throw new Exception("No such project"); } string productsGroupGuid = null; foreach (var projRef in proj.project.project.projectReferences) { if (projRef.projectRef == projectGuid) { productsGroupGuid = projRef.group; break; } } if (productsGroupGuid == null) { throw new Exception("Malformed project: no project in project references"); } PBXGroupData productGroup = proj.GroupsGet(productsGroupGuid); // verify file extension string ext = Path.GetExtension(filename); if (!FileTypeUtils.IsBuildableFile(ext)) { throw new Exception("Wrong file extension"); } // create ContainerItemProxy object var container = PBXContainerItemProxyData.Create(projectGuid, "2", remoteFileGuid, remoteInfo); proj.containerItems.AddEntry(container); // create a reference and build file for the library string typeName = FileTypeUtils.GetTypeName(ext); var libRef = PBXReferenceProxyData.Create(filename, typeName, container.guid, "BUILT_PRODUCTS_DIR"); proj.references.AddEntry(libRef); PBXBuildFileData libBuildFile = PBXBuildFileData.CreateFromFile(libRef.guid, false, null); proj.BuildFilesAdd(targetGuid, libBuildFile); proj.BuildSectionAny(target, ext, false).files.AddGUID(libBuildFile.guid); // add to products folder productGroup.children.AddGUID(libRef.guid); }