Пример #1
0
 private void filterSources(Folder folder, List<string> sourceExcludes)
 {
     folder.files = folder.files.Where((file) => { return !sourceExcludes.Contains(file); }).ToList();
     foreach(var subfolder in folder.folders)
     {
         filterSources(subfolder, sourceExcludes);
     }
 }
Пример #2
0
        public Addon(string ofRoot, string nameOrPath, string projectPath)
        {
            // check if the addon is in addons or is local
            DirectoryInfo di = new DirectoryInfo(nameOrPath);
            if (di.Exists)
            {
                addonName = di.FullName;
                addonPath = nameOrPath;
            }
            else
            {
                addonName = nameOrPath;
                addonPath = Path.Combine(ofRoot, "addons", nameOrPath);
            }

            // find all sources and headers
            String[] srcFilters = { "*.h", "*.hpp", "*.cpp", "*.c", "*.s", "*.S", "*.cc", "*.cxx", "*.c++" };
            srcFolder = new Folder(Path.Combine(addonPath, "src"), srcFilters, projectPath);
            libsFolder = new Folder(Path.Combine(addonPath, "libs"), srcFilters, projectPath);

            // find binary libs
            di = new DirectoryInfo(Path.Combine(addonPath, "libs"));
            String[] libsFilters = { "*.lib", "*.dll" };
            if (di.Exists) {
                foreach (var dir in di.GetDirectories("*", SearchOption.TopDirectoryOnly))
                {
                    var vsLibsPath = Path.Combine(addonPath, "libs", dir.FullName, "lib", "vs");
                    var libFolder = new DirectoryInfo(vsLibsPath);
                    if (libFolder.Exists) {
                        var libsWin32 = new DirectoryInfo(Path.Combine(vsLibsPath, "Win32"));
                        if (libsWin32.Exists)
                        {
                            var libsWin32Debug = new DirectoryInfo(Path.Combine(libsWin32.FullName, "Debug"));
                            if (libsWin32Debug.Exists)
                            {
                                AddLibs(libsWin32Debug, libs32Debug, libsFilters);
                            }

                            var libsWin32Release = new DirectoryInfo(Path.Combine(libsWin32.FullName, "Release"));
                            if (libsWin32Release.Exists)
                            {
                                AddLibs(libsWin32Release, libs32Release, libsFilters);
                            }

                            AddLibs(libsWin32, libs32Debug, libsFilters);
                            AddLibs(libsWin32, libs32Release, libsFilters);
                        }

                        var libsWin64 = new DirectoryInfo(Path.Combine(vsLibsPath, "x64"));
                        if (libsWin64.Exists)
                        {
                            var libsWin64Debug = new DirectoryInfo(Path.Combine(libsWin64.FullName, "Debug"));
                            if (libsWin64Debug.Exists)
                            {
                                AddLibs(libsWin64Debug, libs64Debug, libsFilters);
                            }

                            var libsWin64Release = new DirectoryInfo(Path.Combine(libsWin64.FullName, "Release"));
                            if (libsWin64Release.Exists)
                            {
                                AddLibs(libsWin64Release, libs64Release, libsFilters);
                            }

                            AddLibs(libsWin64, libs64Debug, libsFilters);
                            AddLibs(libsWin64, libs64Release, libsFilters);
                        }
                    }

                    AddLibs(libFolder, libs32Debug, libsFilters);
                    AddLibs(libFolder, libs32Release, libsFilters);
                }
            }

            // find include search paths:
            //
            // - add src recursively as search path
            // - if libs has folders, for each
            //   · if theres include folder add recursively
            //   . else add all the folder recursively
            // - else if has files add libs to search path
            //
            includePaths.AddRange(srcFolder.getRecursiveFoldersPaths());
            if (libsFolder.folders.Count > 0)
            {
                foreach (var libfolder in libsFolder.folders)
                {
                    var includeFolder = libfolder.folders.Find((folder) => { return folder.name == "include"; });
                    if (includeFolder != null)
                    {
                        includePaths.AddRange(includeFolder.getRecursiveFoldersPaths());
                    }
                    else
                    {
                        var srcFolder = libfolder.folders.Find((folder) => { return folder.name == "src"; });
                        if (srcFolder != null)
                        {

                            includePaths.AddRange(srcFolder.getRecursiveFoldersPaths());
                        }
                        else
                        {
                            includePaths.AddRange(libfolder.getRecursiveFoldersPaths());
                        }
                    }
                }
            }
            else
            {
                if (libsFolder.files.Count>0)
                {
                    includePaths.Add(libsFolder.path);
                }
            }

            // Parse addons_config if it exists:
            var addonConfigPath = Path.Combine(addonPath, "addon_config.mk");
            if (File.Exists(addonConfigPath))
            {
                var totalLibsExclude = new List<string>();
                var totalSourcesExclude = new List<string>();
                var totalIncludesExclude = new List<string>();
                var section = "meta";
                var addonConfig = File.OpenText(addonConfigPath);
                while (!addonConfig.EndOfStream) {
                    var line = addonConfig.ReadLine().Trim();
                    if (line.Count() == 0)
                    {
                        continue;
                    }
                    if(line.First() == '#')
                    {
                        continue;
                    }
                    if(line.Last() == ':')
                    {
                        section = line.Substring(0,line.Count()-1);
                        continue;
                    }
                    if (section == "common" || section == "vs")
                    {
                        string variable="";
                        string value="";
                        bool add = false;
                        if (line.Contains("+="))
                        {
                            String[] sep = { "+=" };
                            var varValue = line.Split(sep, StringSplitOptions.RemoveEmptyEntries);
                            if (varValue.Count() == 2)
                            {
                                variable = varValue[0].Trim();
                                value = varValue[1].Trim();
                                add = true;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else if (line.Contains("="))
                        {
                            var varValue = line.Split('=');
                            if (varValue.Count() == 2)
                            {
                                variable = varValue[0].Trim();
                                value = varValue[1].Trim();
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }

                        char[] splitChar = { ' ' };
                        switch (variable)
                        {
                            case "ADDON_INCLUDES":
                                var includes = value.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
                                if (!add)
                                {
                                    includePaths.Clear();
                                }
                                includePaths.AddRange(includes);
                                break;
                            case "ADDON_LIBS":
                                // TODO: there should be a way to specify architecture and target
                                var libs = value.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
                                if (!add)
                                {
                                    libs32Release.Clear();
                                    libs32Debug.Clear();
                                }
                                libs32Debug.AddRange(libs);
                                libs32Release.AddRange(libs);
                                break;
                            case "ADDON_CFLAGS":
                                var flags = value.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
                                if (!add)
                                {
                                    cflags.Clear();
                                }
                                cflags.AddRange(flags);
                                break;
                            case "ADDON_LDFLAGS":
                                flags = value.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
                                if (!add)
                                {
                                    ldflags.Clear();
                                }
                                cflags.AddRange(flags);
                                break;
                            case "ADDON_SOURCES":
                                break;
                            case "ADDON_LIBS_EXCLUDE":
                                var libsExclude = value.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
                                if (!add)
                                {
                                    totalLibsExclude.Clear();
                                }
                                totalLibsExclude.AddRange(libsExclude.Select((libExclude)=> { return Path.Combine(addonPath, libExclude); }));
                                break;
                            case "ADDON_INCLUDES_EXCLUDE":
                                var includesExclude = value.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
                                if (!add)
                                {
                                    totalIncludesExclude.Clear();
                                }
                                totalIncludesExclude.AddRange(includesExclude.Select((includeExclude) => { return Path.Combine(addonPath, includeExclude); }));
                                break;
                            case "ADDON_SOURCES_EXCLUDE":
                                var sourcesExclude = value.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
                                if (!add)
                                {
                                    totalSourcesExclude.Clear();
                                }
                                totalSourcesExclude.AddRange(sourcesExclude.Select((sourceExclude) => { return Path.Combine(addonPath, sourceExclude); }));
                                break;
                        }
                    }
                }

                libs32Debug = libs32Debug.Where((lib) => { return !totalLibsExclude.Contains(lib); }).ToList();
                libs32Release = libs32Release.Where((lib) => { return !totalLibsExclude.Contains(lib); }).ToList();
                libs64Debug = libs64Debug.Where((lib) => { return !totalLibsExclude.Contains(lib); }).ToList();
                libs64Release = libs64Release.Where((lib) => { return !totalLibsExclude.Contains(lib); }).ToList();
                includePaths = includePaths.Where((include) => { return !totalIncludesExclude.Contains(include); }).ToList();
                filterSources(srcFolder,totalSourcesExclude);
                filterSources(libsFolder, totalSourcesExclude);
            }
        }