Ejemplo n.º 1
0
        public void ApplyMod(XCMod mod)
        {
            PBXGroup modGroup = this.GetGroup(mod.group);

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

            foreach (XCModFile libRef in mod.libs)
            {
                string completeLibPath = System.IO.Path.Combine("/usr/lib", libRef.filePath);
                //Debug.LogError ("Adding library " + completeLibPath);
                this.AddFile(completeLibPath, frameworkGroup, "SDKROOT", true, libRef.isWeak);
                //this.AddFile( completeLibPath, frameworkGroup, "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]);
                //Debug.LogError ("Adding framework " + completePath);
                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);
                this.AddFile(absoluteFilePath, modGroup);
            }

            Debug.Log("Adding embed binaries...");
            if (mod.embed_binaries != null)
            {
                //1. Add LD_RUNPATH_SEARCH_PATHS for embed framework
                this.overwriteBuildSetting("LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks", "Release");
                this.overwriteBuildSetting("LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks", "Debug");

                foreach (string binary in mod.embed_binaries)
                {
                    //string absoluteFilePath = System.IO.Path.Combine( mod.path, binary );
                    this.AddEmbedFramework(binary);
                }
            }

            Debug.Log("Adding folders...");
            foreach (string folderPath in mod.folders)
            {
                // zhiyuan.peng :
                // change "foler" root dir "Application.dataPath" to  "mod.path"
                // delet:
                //string absoluteFolderPath = System.IO.Path.Combine( Application.dataPath, folderPath );
                // add:
                string absoluteFolderPath = mod.path + "/" + folderPath;
                // end

                Debug.Log("Adding folder " + absoluteFolderPath);
                this.AddFolder(absoluteFolderPath, modGroup, (string[])mod.excludes.ToArray(typeof(string)));
            }

            Debug.Log("Adding headerpaths...");
            foreach (string headerpath in mod.headerpaths)
            {
                if (headerpath.Contains("$(inherited)"))
                {
                    Debug.Log("not prepending a path to " + headerpath);
                    this.AddHeaderSearchPaths(headerpath);
                }
                else
                {
                    string absoluteHeaderPath = System.IO.Path.Combine(mod.path, headerpath);
                    this.AddHeaderSearchPaths(absoluteHeaderPath);
                }
            }

            Debug.Log("Adding compiler flags...");
            foreach (string flag in mod.compiler_flags)
            {
                this.AddOtherCFlags(flag);
            }

            Debug.Log("Adding linker flags...");
            foreach (string flag in mod.linker_flags)
            {
                this.AddOtherLinkerFlags(flag);
            }

            Debug.Log("Adding plist items...");
            string  plistPath = this.projectRootPath + "/Info.plist";
            XCPlist plist     = new XCPlist(plistPath);

            plist.Process(mod.plist);

            this.Consolidate();
        }
Ejemplo n.º 2
0
        // We support neither recursing into nor bundles contained inside loc folders
        public bool AddLocFolder(string folderPath, PBXGroup parent = null, string[] exclude = null, bool createBuildFile = true)
        {
            DirectoryInfo sourceDirectoryInfo = new DirectoryInfo(folderPath);

            if (exclude == null)
            {
                exclude = new string[] {}
            }
            ;

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

            // Create group as needed



            // zhiyuan.peng:
            // delet:
            //System.Uri projectFolderURI = new System.Uri( projectFileInfo.DirectoryName );
            //System.Uri locFolderURI = new System.Uri( folderPath );
            //var relativePath = projectFolderURI.MakeRelativeUri( locFolderURI ).ToString();
            //PBXGroup newGroup = GetGroup( sourceDirectoryInfo.Name, relativePath, parent );
            // add:
            PBXGroup newGroup = parent;
            // end

            // Add loc region to project
            string nom    = sourceDirectoryInfo.Name;
            string region = nom.Substring(0, nom.Length - ".lproj".Length);

            project.AddRegion(region);

            // Adding files.
            string regexExclude = string.Format(@"{0}", string.Join("|", exclude));

            foreach (string file in Directory.GetFiles(folderPath))
            {
                if (Regex.IsMatch(file, regexExclude))
                {
                    continue;
                }

                // zhiyuan.peng :
                // holy shit!!!
                // these code below which used to add .lpro file is not work on xCode6 totaly,
                // I fix it!!!!
                // WHAT A GENIUS I AM !

                // I DELET :

                /*
                 * // Add a variant group for the language as well
                 * var variant = new PBXVariantGroup(System.IO.Path.GetFileName( file ), null, "GROUP");
                 * variantGroups.Add(variant);
                 *
                 * // The group gets a reference to the variant, not to the file itself
                 * newGroup.AddChild(variant);
                 *
                 * AddFile( file, variant, "GROUP", createBuildFile );
                 */

                // I ADD :
                var variantName = System.IO.Path.GetFileName(file);
                var variant     = (PBXVariantGroup)this.GetExistVariantGroup(variantName, null, newGroup);
                if (variant == null)
                {
                    variant = new PBXVariantGroup(System.IO.Path.GetFileName(file), null, "GROUP");
                    variantGroups.Add(variant);
                    // The group gets a reference to the variant, not to the file itself
                    newGroup.AddChild(variant);
                }
                AddFile(file, variant, "SOURCE_ROOT", createBuildFile);
                //END
            }

            modified = true;
            return(modified);
        }
Ejemplo n.º 3
0
        public XCProject(string filePath) : this()
        {
            // zhiyuan.peng:
            this.native_builder = new Properties(filePath + "/native_builder.properties");
            this.path           = filePath;

            // zhiyuan.peng:
            // fix bug:
            // if filePath cantains "." or ".." will lead wrong fileReference path
            // ADD:
            filePath = Path.GetFullPath(filePath);
            // END

            if (!System.IO.Directory.Exists(filePath))
            {
                Debug.LogWarning("XCode project path does not exist: " + filePath);
                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;
                //if the path is relative to the project, we need to make it absolute
                if (!System.IO.Path.IsPathRooted(projectRootPath))
                {
                    projectRootPath = Application.dataPath.Replace("Assets", "") + projectRootPath;
                }
                //Debug.Log ("projectRootPath adjusted to " + projectRootPath);
                this.filePath = projects[0];
            }

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

            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;
            }
        }
Ejemplo n.º 4
0
        public bool AddFolder(string folderPath, PBXGroup parent = null, string[] exclude = null, bool recursive = true, bool createBuildFile = true)
        {
            Debug.Log("Folder PATH: " + folderPath);
            if (!Directory.Exists(folderPath))
            {
                Debug.Log("Directory doesn't exist?");
                return(false);
            }

            if (folderPath.EndsWith(".lproj"))
            {
                Debug.Log("Ended with .lproj");
                return(AddLocFolder(folderPath, parent, exclude, createBuildFile));
            }

            DirectoryInfo sourceDirectoryInfo = new DirectoryInfo(folderPath);

            if (exclude == null)
            {
                Debug.Log("Exclude was null");
                exclude = new string[] {};
            }

            if (parent == null)
            {
                Debug.Log("Parent was null");
                parent = rootGroup;
            }

            // Create group
            PBXGroup newGroup = GetGroup(sourceDirectoryInfo.Name, null /*relative path*/, parent);

            Debug.Log("New Group created");

            foreach (string directory in Directory.GetDirectories(folderPath))
            {
                Debug.Log("DIR: " + directory);

                // zhiyuan.peng:
                // do not add folder referance in xcode project and create a xCode group instead Usually
                // bug some speacial floder need add referance to xCode
                // ".bundle", ".framework"
                // DELETE :
//				if( directory.EndsWith( ".bundle")) {
                // ADD :
                if (directory.EndsWith(".bundle") || directory.EndsWith(".framework"))
                {
                    // Treat it like a file and copy even if not recursive
                    // TODO also for .xcdatamodeld?
                    Debug.LogWarning("This is a special folder: " + directory);
                    AddFile(directory, newGroup, "SOURCE_ROOT", createBuildFile);
                    continue;
                }

                if (recursive)
                {
                    Debug.Log("recursive");
                    AddFolder(directory, newGroup, exclude, recursive, createBuildFile);
                }
            }


            // Adding files.

            string regexExclude = string.Format(@"{0}", string.Join("|", exclude));

            foreach (string file in Directory.GetFiles(folderPath))
            {
                // zhiyuan.peng
                // Another F*****g BUG
                // This bug leader to exclude any file
                // DELETE:
//				if(Regex.IsMatch( file, regexExclude ))
//				{
//					Debug.Log(regexExclude + "\n" + file);
//					continue;
//				}
                // ADD:
                if (exclude.Length != 0 && Regex.IsMatch(file, regexExclude))
                {
                    Debug.Log(regexExclude + "\n" + file);
                    continue;
                }
                //end

                Debug.Log("Adding Files for Folder");
                AddFile(file, newGroup, "SOURCE_ROOT", createBuildFile);
            }


            modified = true;
            return(modified);
        }
Ejemplo n.º 5
0
        public PBXDictionary AddFile(string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false)
        {
            //Debug.Log("AddFile " + filePath + ", " + parent + ", " + tree + ", " + (createBuildFiles? "TRUE":"FALSE") + ", " + (weak? "TRUE":"FALSE") );

            PBXDictionary results = new PBXDictionary();

            if (filePath == null)
            {
                Debug.LogError("AddFile called with null filePath");
                return(results);
            }

            string absPath = string.Empty;

            if (Path.IsPathRooted(filePath))
            {
                Debug.Log("Path is Rooted");
                absPath = filePath;
            }
            else if (tree.CompareTo("SDKROOT") != 0)
            {
                // zhiyuan.peng :
                // change "foler" root dir "Application.dataPath" to  "mod.path"
                // delet:
                absPath = Path.Combine(Application.dataPath, filePath);
                // add:
                // absPath = "/Users/zhiyuan.peng/Project/XUPorterTest/pp.xupemods/" + filePath;
                // end
            }

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

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

            // zhiyuan.peng:
            // what a f*****g BUG!
            // code below used to check if the file reference is exsits, but olny check file name
            // file path should also be checked!
            // DELETE:
            //Check if there is already a file
//			PBXFileReference fileReference = GetFile( System.IO.Path.GetFileName( filePath ) );
//			if( fileReference != null) {
//				Debug.LogWarning(fileReference.path + "\n" + filePath + "\n" + tree);
//				Debug.LogWarning("File already exists: " + filePath); //not a warning, because this is normal for most builds!
//				return null;
//			}
            // ADD:
            //Check if there is already a file
            PBXFileReference fileReference = GetFile(System.IO.Path.GetFileName(filePath));

            if (fileReference != null && fileReference.path.Equals(filePath))
            {
                Debug.LogWarning(fileReference.path + "\n" + filePath + "\n" + tree);
                Debug.LogWarning("File already exists: " + filePath);                 //not a warning, because this is normal for most builds!
                return(null);
            }

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

            //Debug.LogError("fileReference.path:"+fileReference.path+"            fileReference.buildPhase:"+fileReference.buildPhase);
            //Create a build file for reference
            if (!string.IsNullOrEmpty(fileReference.buildPhase) && createBuildFiles)
            {
                switch (fileReference.buildPhase)
                {
                case "PBXFrameworksBuildPhase":
                    //Debug.LogError("absPath:"+absPath+"tree.CompareTo( \"SOURCE_ROOT\" ) :"+tree.CompareTo( "SOURCE_ROOT" ) );
                    foreach (KeyValuePair <string, PBXFrameworksBuildPhase> currentObject in frameworkBuildPhases)
                    {
                        BuildAddFile(fileReference, currentObject, weak);
                    }
                    if (!string.IsNullOrEmpty(absPath) && (tree.CompareTo("SOURCE_ROOT") == 0))
                    {
                        string libraryPath = Path.Combine("$(PROJECT_DIR)", Path.GetDirectoryName(filePath));
                        //	Debug.LogError("libraryPath:"+libraryPath);
                        if (File.Exists(absPath))
                        {
                            this.AddLibrarySearchPaths(new PBXList(libraryPath));
                        }
                        else
                        {
                            this.AddFrameworkSearchPaths(new PBXList(libraryPath));
                        }
                    }
//						if(Path.GetExtension(fileReference.path).Equals(".tdb"))
//						{
//							string libraryPath = Path.Combine( "$(SRCROOT)", Path.GetDirectoryName( filePath ) );
//							Debug.LogError("libraryPath:"+libraryPath);
//							if (File.Exists(absPath)) {
//								this.AddLibrarySearchPaths( new PBXList( libraryPath ) );
//							} else {
//								this.AddFrameworkSearchPaths( new PBXList( libraryPath ) );
//							}
//
//						}
                    break;

                case "PBXResourcesBuildPhase":
                    foreach (KeyValuePair <string, PBXResourcesBuildPhase> currentObject in resourcesBuildPhases)
                    {
                        Debug.Log("Adding Resources Build File");
                        BuildAddFile(fileReference, currentObject, weak);
                    }
                    break;

                case "PBXShellScriptBuildPhase":
                    foreach (KeyValuePair <string, PBXShellScriptBuildPhase> currentObject in shellScriptBuildPhases)
                    {
                        Debug.Log("Adding Script Build File");
                        BuildAddFile(fileReference, currentObject, weak);
                    }
                    break;

                case "PBXSourcesBuildPhase":
                    foreach (KeyValuePair <string, PBXSourcesBuildPhase> currentObject in sourcesBuildPhases)
                    {
                        Debug.Log("Adding Source Build File");
                        BuildAddFile(fileReference, currentObject, weak);
                    }
                    break;

                case "PBXCopyFilesBuildPhase":
                    foreach (KeyValuePair <string, PBXCopyFilesBuildPhase> currentObject in copyBuildPhases)
                    {
                        Debug.Log("Adding Copy Files Build Phase");
                        BuildAddFile(fileReference, currentObject, weak);
                    }
                    break;

                case null:
                    Debug.LogWarning("File Not Supported: " + filePath);
                    break;

                default:
                    Debug.LogWarning("File Not Supported.");
                    return(null);
                }
            }
            return(results);
        }