Beispiel #1
0
        public XCProject(string filePath) : this()
        {
            if (!System.IO.Directory.Exists(filePath))
            {
                Debug.LogWarning("Path does not exists.");
                return;
            }

            if (filePath.EndsWith(".xcodeproj"))
            {
                Debug.Log("Opening project " + filePath);
                this.projectRootPath = Path.GetDirectoryName(filePath);
                this.filePath        = filePath;
            }
            else
            {
                Debug.Log("Looking for xcodeproj files in " + filePath);
                string[] projects = System.IO.Directory.GetDirectories(filePath, "*.xcodeproj");
                if (projects.Length == 0)
                {
                    Debug.LogWarning("Error: missing xcodeproj file");
                    return;
                }

                this.projectRootPath = filePath;
                this.filePath        = projects[0];
            }

            // Convert to absolute
            this.projectRootPath = Path.GetFullPath(this.projectRootPath);

            projectFileInfo = new FileInfo(Path.Combine(this.filePath, "project.pbxproj"));
            StreamReader sr       = projectFileInfo.OpenText();
            string       contents = sr.ReadToEnd();

            sr.Close();

            PBXParser parser = new PBXParser();

            _datastore = parser.Decode(contents);
            if (_datastore == null)
            {
                throw new System.Exception("Project file not found at file path " + filePath);
            }

            if (!_datastore.ContainsKey("objects"))
            {
                Debug.Log("Errore " + _datastore.Count);
                return;
            }

            _objects = (PBXDictionary)_datastore["objects"];
            modified = false;

            _rootObjectKey = (string)_datastore["rootObject"];
            if (!string.IsNullOrEmpty(_rootObjectKey))
            {
                _project   = new PBXProject(_rootObjectKey, (PBXDictionary)_objects[_rootObjectKey]);
                _rootGroup = new PBXGroup(_rootObjectKey, (PBXDictionary)_objects[_project.mainGroupID]);
            }
            else
            {
                Debug.LogWarning("error: project has no root object");
                _project   = null;
                _rootGroup = null;
            }
        }
Beispiel #2
0
        public void ApplyMod(XCMod mod)
        {
            PBXGroup modGroup = this.GetGroup(mod.group);

            Debug.Log("Adding libraries...");
            foreach (XCModFile libRef in mod.libs)
            {
                string completeLibPath = System.IO.Path.Combine("usr/lib", libRef.filePath);
                this.AddFile(completeLibPath, modGroup, "SDKROOT", true, libRef.isWeak);
            }

            Debug.Log("Adding frameworks...");
            PBXGroup frameworkGroup = this.GetGroup("Frameworks");

            foreach (string framework in mod.frameworks)
            {
                string[] filename     = framework.Split(':');
                bool     isWeak       = (filename.Length > 1) ? true : false;
                string   completePath = System.IO.Path.Combine("System/Library/Frameworks", filename[0]);
                this.AddFile(completePath, frameworkGroup, "SDKROOT", true, isWeak);
            }

            Debug.Log("Adding files...");
            foreach (string filePath in mod.files)
            {
                string absoluteFilePath = System.IO.Path.Combine(mod.path, filePath);


                if (filePath.EndsWith(".framework"))
                {
                    this.AddFile(absoluteFilePath, frameworkGroup, "GROUP", true, false);
                }
                else
                {
                    this.AddFile(absoluteFilePath, modGroup);
                }
            }

            Debug.Log("Adding folders...");
            foreach (string folderPath in mod.folders)
            {
                string absoluteFolderPath = System.IO.Path.Combine(mod.path, folderPath);
                this.AddFolder(absoluteFolderPath, modGroup, (string[])mod.excludes.ToArray(typeof(string)));
            }

            Debug.Log("Adding headerpaths...");
            foreach (string headerpath in mod.headerpaths)
            {
                string absoluteHeaderPath = System.IO.Path.Combine(mod.path, headerpath);
                this.AddHeaderSearchPaths(absoluteHeaderPath);
            }

            Debug.Log("Configure build settings...");
            Hashtable buildSettings = mod.buildSettings;

            if (buildSettings.ContainsKey("OTHER_LDFLAGS"))
            {
                Debug.Log("    Adding other linker flags...");
                ArrayList otherLinkerFlags = (ArrayList)buildSettings["OTHER_LDFLAGS"];
                foreach (string linker in otherLinkerFlags)
                {
                    string _linker = linker;
                    if (!_linker.StartsWith("-"))
                    {
                        _linker = "-" + _linker;
                    }
                    this.AddOtherLDFlags(_linker);
                }
            }

            if (buildSettings.ContainsKey("GCC_ENABLE_CPP_EXCEPTIONS"))
            {
                Debug.Log("    GCC_ENABLE_CPP_EXCEPTIONS = " + buildSettings["GCC_ENABLE_CPP_EXCEPTIONS"]);
                this.GccEnableCppExceptions((string)buildSettings["GCC_ENABLE_CPP_EXCEPTIONS"]);
            }

            if (buildSettings.ContainsKey("GCC_ENABLE_OBJC_EXCEPTIONS"))
            {
                Debug.Log("    GCC_ENABLE_OBJC_EXCEPTIONS = " + buildSettings["GCC_ENABLE_OBJC_EXCEPTIONS"]);
                this.GccEnableObjCExceptions((string)buildSettings["GCC_ENABLE_OBJC_EXCEPTIONS"]);
            }

            this.Consolidate();
        }
Beispiel #3
0
        public PBXDictionary AddFile(string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false, bool embed = false)
        {
            PBXDictionary results = new PBXDictionary();
            string        absPath = string.Empty;

            if (Path.IsPathRooted(filePath))
            {
                absPath = filePath;
            }
            else if (tree.CompareTo("SDKROOT") != 0)
            {
                absPath = Path.Combine(Application.dataPath.Replace("Assets", ""), filePath);
            }

            if (!(File.Exists(absPath) || Directory.Exists(absPath)) && tree.CompareTo("SDKROOT") != 0)
            {
                Debug.Log("Missing file: " + absPath + " > " + filePath);
                return(results);
            }
            else if (tree.CompareTo("SOURCE_ROOT") == 0 || tree.CompareTo("GROUP") == 0)
            {
                System.Uri fileURI = new System.Uri(absPath);
                System.Uri rootURI = new System.Uri((projectRootPath + "/."));
                filePath = rootURI.MakeRelativeUri(fileURI).ToString();
            }

            if (parent == null)
            {
                parent = _rootGroup;
            }

            // TODO: Aggiungere controllo se file già presente
            PBXFileReference fileReference = GetFile(System.IO.Path.GetFileName(filePath));

            if (fileReference != null)
            {
                return(null);
            }

            fileReference = new PBXFileReference(filePath, (TreeEnum)System.Enum.Parse(typeof(TreeEnum), tree));
            parent.AddChild(fileReference);
            fileReferences.Add(fileReference);
            results.Add(fileReference.guid, fileReference);

            //Create a build file for reference
            if (!string.IsNullOrEmpty(fileReference.buildPhase) && createBuildFiles)
            {
                PBXBuildFile buildFile;
                switch (fileReference.buildPhase)
                {
                case "PBXFrameworksBuildPhase":
                    foreach (KeyValuePair <string, PBXFrameworksBuildPhase> currentObject in frameworkBuildPhases)
                    {
                        buildFile = new PBXBuildFile(fileReference, weak);
                        buildFiles.Add(buildFile);
                        currentObject.Value.AddBuildFile(buildFile);
                    }

                    if (!string.IsNullOrEmpty(absPath) && File.Exists(absPath) && tree.CompareTo("SOURCE_ROOT") == 0)
                    {
                        //Debug.LogError(absPath);
                        string libraryPath = Path.Combine("$(SRCROOT)", Path.GetDirectoryName(filePath));
                        this.AddLibrarySearchPaths(new PBXList(libraryPath));
                    }
                    else if (!string.IsNullOrEmpty(absPath) && Directory.Exists(absPath) && absPath.EndsWith(".framework") && tree.CompareTo("GROUP") == 0)                                 // Annt: Add framework search path for FacebookSDK
                    {
                        string frameworkPath = Path.Combine("$(SRCROOT)", Path.GetDirectoryName(filePath));
                        this.AddFrameworkSearchPaths(new PBXList(frameworkPath));
                    }

                    if (embed)
                    {
                        string ldRuntimePath = "$(inherited) @executable_path/Frameworks";
                        this.AddLDRuntimeSearchPaths(ldRuntimePath);

                        //Create a new copyBuildPhase for the embed framework
                        foreach (KeyValuePair <string, PBXCopyFilesBuildPhase> currentObject in copyBuildPhases)
                        {
                            buildFile = new PBXBuildFile(fileReference, weak, true);
                            buildFiles.Add(buildFile);
                            currentObject.Value.data["name"]             = "Embed Frameworks";
                            currentObject.Value.data["dstSubfolderSpec"] = 10;
                            currentObject.Value.AddBuildFile(buildFile);

                            // This will add the "Code Sign On Copy" setting for the embedded framework
                            buildFile.SetEmbed(true);
                        }
                    }

                    break;

                case "PBXResourcesBuildPhase":
                    foreach (KeyValuePair <string, PBXResourcesBuildPhase> currentObject in resourcesBuildPhases)
                    {
                        buildFile = new PBXBuildFile(fileReference, weak);
                        buildFiles.Add(buildFile);
                        currentObject.Value.AddBuildFile(buildFile);
                    }
                    break;

                case "PBXShellScriptBuildPhase":
                    foreach (KeyValuePair <string, PBXShellScriptBuildPhase> currentObject in shellScriptBuildPhases)
                    {
                        buildFile = new PBXBuildFile(fileReference, weak);
                        buildFiles.Add(buildFile);
                        currentObject.Value.AddBuildFile(buildFile);
                    }
                    break;

                case "PBXSourcesBuildPhase":
                    foreach (KeyValuePair <string, PBXSourcesBuildPhase> currentObject in sourcesBuildPhases)
                    {
                        buildFile = new PBXBuildFile(fileReference, weak);
                        buildFiles.Add(buildFile);
                        currentObject.Value.AddBuildFile(buildFile);
                    }
                    break;

                case "PBXCopyFilesBuildPhase":
                    foreach (KeyValuePair <string, PBXCopyFilesBuildPhase> currentObject in copyBuildPhases)
                    {
                        buildFile = new PBXBuildFile(fileReference, weak);
                        buildFiles.Add(buildFile);
                        currentObject.Value.AddBuildFile(buildFile);
                    }
                    break;

                case null:
                    Debug.LogWarning("fase non supportata null");
                    break;

                default:
                    Debug.LogWarning("fase non supportata def");
                    return(null);
                }
            }
            return(results);
        }