Esempio n. 1
0
        public Core.Project Extract(Core.ILogger logger, Core.Paths paths, string filePath, Dictionary <string, string> filters, Dictionary <Core.Project, List <string> > dependencies, Dictionary <string, string> mapping)
        {
            var sourceDirec = paths.Value("SolutionDir");
            var proj        = this;

            var project = new Core.Cpp();

            project.IncludeDirectories.AddRange(proj.Includes());
            project.CompileDefinitions.AddRange(proj.CompileDefinitions());
            if (project.CompileDefinitions.Contains("_CONSOLE"))
            {
                project.CompileDefinitions.Remove("_CONSOLE");
                project.IsExe = true;
            }

            dependencies[project] = proj.Dependencies();

            foreach (var type in new string[] { "ClInclude", "ClCompile" })
            {
                foreach (var pair2 in proj.Files(false, type, sourceDirec))
                {
                    var fullName = pair2.Key;
                    var filter   = pair2.Value;

                    logger.Info("Appended \"{0}\"", fullName);
                    project.FilePaths.Add(fullName);
                    filters.Add(fullName, filter);
                }
            }

            mapping[filePath] = proj.Name;

            return(project);
        }
Esempio n. 2
0
        public static void Extract(Core.ILogger logger, Core.Paths paths, List <string> filePaths, Dictionary <string, Core.Project> projects, Dictionary <string, string> filters, string configPlatform = "Debug|AnyCPU")
        {
            var skipped = new List <string>();

            foreach (var filePath in filePaths)
            {
                var ext = System.IO.Path.GetExtension(filePath);
                if (ext == ".sln")
                {
                    Extract(logger, paths, filePath, projects, filters, configPlatform);
                    continue;
                }

                skipped.Add(filePath);
            }

            filePaths.Clear();
            filePaths.AddRange(skipped);


            if (filePaths.Count > 0)
            {
                SetSolutionDir(paths, filePaths[0], string.Empty);
            }

            ExtractProjects(logger, paths, filePaths, projects, filters, configPlatform);
            paths.Remove("$(ProjectDir)");
        }
Esempio n. 3
0
        private static void ExtractProjects(Core.ILogger logger, Core.Paths paths, List <string> filePaths, Dictionary <string, Core.Project> projects, Dictionary <string, string> filters, string configPlatform)
        {
            var dependencies = new Dictionary <Core.Project, List <string> >();
            var mapping      = new Dictionary <string, string>();

            foreach (var proj in ExtractProjects(logger, paths, filePaths, configPlatform))
            {
                if (proj.Value is VCProj vcProj)
                {
                    projects[proj.Value.Name] = vcProj.Extract(logger, paths, proj.Key, filters, dependencies, mapping);
                }
                else if (proj.Value is NetProj netProj)
                {
                    projects[proj.Value.Name] = netProj.Extract(logger, paths, proj.Key, dependencies, mapping);
                }
            }

            foreach (var dep in dependencies)
            {
                var proj = dep.Key;
                foreach (var filePath in dep.Value)
                {
                    if (mapping.ContainsKey(filePath))
                    {
                        proj.Dependencies.Add(mapping[filePath]);
                    }
                }
            }
        }
Esempio n. 4
0
        static private void Files(Core.ILogger logger, Core.Paths paths, string fileName, string direc, List <KeyValuePair <string, string> > fileNames, List <string> extensions, List <string> projectExts)
        {
            var ext = System.IO.Path.GetExtension(fileName);

            if (projectExts.Contains(ext))
            {
                logger.Info("Appended for reading \"{0}\"", fileName);
                if (!extensions.Contains(ext))
                {
                    extensions.Add(ext);
                }

                fileNames.Add(new KeyValuePair <string, string>(fileName, direc));
                SetSolutionDir(paths, fileName, direc);
            }
            else if (ext == ".sln")
            {
                logger.Info("Reading projects from \"{0}\"", fileName);
                direc = System.IO.Path.GetDirectoryName(fileName);
                foreach (var name in ReadVisualStudioSolution(logger, fileName))
                {
                    Files(logger, paths, name, direc, fileNames, extensions, projectExts);
                }

                SetSolutionDir(paths, fileName, direc);
            }
        }
Esempio n. 5
0
        public static void MainFunc(string[] args, Core.ILogger logger)
        {
            logger.Info("Visual Studio solution command line application for creating CMake files");
            logger.Info("Copyright (c) 2020 Zebedee Mason");

            bool printUsage = false;

            if (args.Length == 2 || args.Length == 3)
            {
                if (!System.IO.File.Exists(args[0]))
                {
                    logger.Info("First argument is not an existing file");
                    printUsage = true;
                }
                else if (System.IO.Path.GetExtension(args[0]) != ".sln")
                {
                    logger.Info("First argument is not an sln file");
                    printUsage = true;
                }

                if (args.Length == 3 && !System.IO.Directory.Exists(args[2]))
                {
                    logger.Info("Third argument is not an existing directory");
                    printUsage = true;
                }
            }
            else
            {
                printUsage = true;
            }

            if (printUsage)
            {
                logger.Info("Create CMakeLists.txt files");
                logger.Info("Usage:");
                logger.Info("  ProjectIO.VisualStudioToCMake.exe <Visual Studio solution> <configuration|platform> [root directory if different from sln file path]");
                return;
            }

            var filePaths = new List <string> {
                args[0]
            };
            var projects = new Dictionary <string, Core.Project>();
            var filters  = new Dictionary <string, string>();
            var paths    = new Core.Paths();

            VisualStudio.Solution.Extract(logger, paths, filePaths, projects, filters, args[1]);

            var rootDirec = System.IO.Path.GetDirectoryName(args[0]);

            if (args.Length == 3)
            {
                rootDirec = args[2];
            }

            string name = System.IO.Path.GetFileNameWithoutExtension(args[0]);

            CMakeProject.Assemble(rootDirec, name, projects);
        }
Esempio n. 6
0
 public Proj(Core.ILogger logger, string path, Core.Paths paths, string configPlatform)
 {
     _logger         = logger;
     _filePath       = path;
     _paths          = paths;
     _configPlatform = configPlatform;
     _xml            = new XMLUtils(path);
     _paths.Add("ProjectDir", System.IO.Path.GetDirectoryName(_filePath));
 }
Esempio n. 7
0
        private static void Extract(Core.ILogger logger, Core.Paths paths, string solutionPath, Dictionary <string, Core.Project> projects, Dictionary <string, string> filters, string configPlatform)
        {
            logger.Info("Reading projects from \"{0}\"", solutionPath);
            var direc = System.IO.Path.GetDirectoryName(solutionPath);

            SetSolutionDir(paths, solutionPath, direc);
            var filePaths = ReadVisualStudioSolution(logger, solutionPath);

            ExtractProjects(logger, paths, filePaths, projects, filters, configPlatform);
        }
Esempio n. 8
0
 public State(State state)
 {
     Variables          = state.Variables.ToDictionary(entry => entry.Key, entry => entry.Value);
     Properties         = state.Properties.ToDictionary(entry => entry.Key, entry => entry.Value);
     Switches           = state.Switches.ToDictionary(entry => entry.Key, entry => entry.Value);
     IncludeDirectories = state.IncludeDirectories.ToList();
     CompileDefinitions = state.CompileDefinitions.ToList();
     _logger            = state._logger;
     _paths             = state._paths;
 }
Esempio n. 9
0
        public static string Extract(Core.ILogger logger, Core.Paths paths, List <string> filePaths, Dictionary <string, Core.Project> projects, Dictionary <string, string> filters)
        {
            string lists = string.Empty;
            string cache = string.Empty;

            foreach (var filePath in filePaths)
            {
                if (lists.Length == 0 && System.IO.Path.GetFileName(filePath) == "CMakeLists.txt")
                {
                    lists = filePath;
                }

                if (cache.Length == 0 && System.IO.Path.GetFileName(filePath) == "CMakeCache.txt")
                {
                    cache = filePath;
                }
            }

            if (lists.Length == 0)
            {
                return("solution");
            }

            logger.Info("Appended for reading \"{0}\"", lists);

            var sourceDirec = System.IO.Path.GetDirectoryName(lists);

            paths.Add("PROJECT_SOURCE_DIR", sourceDirec);
            filePaths.Remove(lists);

            var binaryDirec = string.Empty;

            if (cache.Length != 0)
            {
                binaryDirec = System.IO.Path.GetDirectoryName(cache);
                paths.Add("PROJECT_BINARY_DIR", binaryDirec);
                filePaths.Remove(cache);
            }

            logger.Info("Reading CMake");
            var state = new State(logger, sourceDirec, binaryDirec, paths);

            state.ReadCache(cache);

            var builder = Instance(state, projects, filters, logger);

            builder.Read();

            if (state.Variables.ContainsKey("${CMAKE_PROJECT_NAME}"))
            {
                return(state.Variables["${CMAKE_PROJECT_NAME}"]);
            }

            return("solution");
        }
Esempio n. 10
0
        static public void SetSolutionDir(Core.Paths paths, string fileName, string direc)
        {
            if (paths.ContainsAlias("SolutionDir"))
            {
                return;
            }

            var path = direc.Length == 0 ? System.IO.Path.GetDirectoryName(fileName) : direc;
            var info = new System.IO.DirectoryInfo(path);

            paths.Add("SolutionDir", info.FullName);
        }
Esempio n. 11
0
        public override Core.Project Extract(Core.ILogger logger, Core.Paths paths, string filePath, Dictionary <Core.Project, List <string> > dependencies, Dictionary <string, string> mapping)
        {
            var proj = this;

            var project = new Core.VBasic();

            dependencies[project] = proj.Dependencies();
            proj.Compiles(project.FilePaths, logger, paths);
            mapping[filePath] = proj.Name;

            return(project);
        }
Esempio n. 12
0
        public State(Core.ILogger logger, string sourceDirec, string binaryDirec, Core.Paths paths)
        {
            Variables["${PROJECT_SOURCE_DIR}"]       = sourceDirec;
            Variables["${PROJECT_BINARY_DIR}"]       = binaryDirec;
            Variables["${CMAKE_CURRENT_LIST_DIR}"]   = "${PROJECT_SOURCE_DIR}";
            Variables["${CMAKE_CURRENT_SOURCE_DIR}"] = "${PROJECT_SOURCE_DIR}";
            Variables["${CMAKE_CURRENT_BINARY_DIR}"] = "${PROJECT_BINARY_DIR}";

            Switches["WIN32"] = true;
            Switches["UNIX"]  = false;

            _logger = logger;
            _paths  = paths;
        }
Esempio n. 13
0
        public static Dictionary <string, Proj> ExtractProjects(Core.ILogger logger, Core.Paths paths, List <string> filePaths, string configPlatform = "Debug|AnyCPU")
        {
            var projects = new Dictionary <string, Proj>();
            var skipped  = new List <string>();

            foreach (var filePath in filePaths)
            {
                var ext = System.IO.Path.GetExtension(filePath);

                if (ext == ".vcxproj")
                {
                    logger.Info("Appended for reading \"{0}\"", filePath);
                    logger.Info("Reading Visual C++");
                    var proj = new VCProj(logger, filePath, paths, configPlatform);
                    projects[filePath] = proj;
                    continue;
                }

                if (ext == ".csproj")
                {
                    var proj = new CSProj(logger, filePath, paths, configPlatform);
                    projects[filePath] = proj;
                    continue;
                }

                if (ext == ".shproj")
                {
                    var proj = new SHProj(logger, filePath, paths, configPlatform);
                    projects[filePath] = proj;
                    continue;
                }

                if (ext == ".vbproj")
                {
                    var proj = new VBProj(logger, filePath, paths, configPlatform);
                    projects[filePath] = proj;
                    continue;
                }

                skipped.Add(filePath);
            }

            filePaths.Clear();
            filePaths.AddRange(skipped);

            return(projects);
        }
Esempio n. 14
0
        public static void Extract(Core.ILogger logger, Core.Paths paths, string filePath, Dictionary <string, Core.Project> projects, Dictionary <Core.Project, List <string> > dependencies, Dictionary <string, string> mapping, string configPlatform)
        {
            var proj = new VBProj(logger, filePath, paths, configPlatform);

            projects[proj.Name] = proj.Extract(logger, paths, filePath, dependencies, mapping);
        }
Esempio n. 15
0
 public VBProj(Core.ILogger logger, string path, Core.Paths paths, string configPlatform)
     : base(logger, path, paths, configPlatform)
 {
 }
Esempio n. 16
0
        public override void Compiles(List <string> files, Core.ILogger logger, Core.Paths filePath)
        {
            var xml2 = new XMLUtils(FilePath);

            xml2.DotNetCompiles(this, files, logger, filePath);
        }
Esempio n. 17
0
 public abstract Core.Project Extract(Core.ILogger logger, Core.Paths paths, string filePath,
                                      Dictionary <Core.Project, List <string> > dependencies, Dictionary <string, string> mapping);
Esempio n. 18
0
 public virtual void Compiles(List <string> files, Core.ILogger logger, Core.Paths filePath)
 {
     _xml.DotNetCompiles(this, files, logger, filePath);
 }
Esempio n. 19
0
        public void DotNetCompiles(Proj project, List <string> files, Core.ILogger logger, Core.Paths filePath)
        {
            var list  = Compiles("Compile");
            var direc = System.IO.Path.GetDirectoryName(project.FilePath);

            filePath.Add("ProjectDir", direc);
            foreach (var link in list)
            {
                var trimmed = link;
                trimmed = trimmed.Replace("$(MSBuildThisFileDirectory)", direc + "\\");
                var file = filePath.RemoveAliases(trimmed);

                if (!System.IO.Path.IsPathRooted(file))
                {
                    file = System.IO.Path.Combine(direc, trimmed);
                }

                if (file.Contains("*"))
                {
                    var directory = System.IO.Path.GetDirectoryName(file);
                    var pattern   = System.IO.Path.GetFileName(file);
                    try
                    {
                        foreach (var name in System.IO.Directory.GetFiles(directory, pattern))
                        {
                            logger.Info("Appended \"{0}\"", name);
                            files.Add(name);
                        }
                    }
                    catch
                    {
                    }
                }
                else if (file.Length > 0)
                {
                    if (!System.IO.File.Exists(file))
                    {
                        logger.Warn("Cannot find \"{0}\"", file);
                        continue;
                    }

                    logger.Info("Appended \"{0}\"", file);
                    files.Add(file);
                }
            }

            filePath.Remove("ProjectDir");
        }
Esempio n. 20
0
        private static void MainFunc(string[] args, Core.ILogger logger)
        {
            logger.Info("VStoVS command line application for creating a Visual Studio solution from a Visual Studio solution!");
            logger.Info("Copyright (c) 2020 Zebedee Mason");

            bool printUsage = false;

            if (args.Length > 3)
            {
                if (!System.IO.Directory.Exists(args[0]))
                {
                    logger.Info("First argument is not an output directory");
                    printUsage = true;
                }
                else if (!System.IO.Directory.Exists(args[1]))
                {
                    logger.Info("Second argument is not a template directory");
                    printUsage = true;
                }
                else if (System.IO.Path.GetExtension(args[2]) != ".sln" && System.IO.File.Exists(args[2]))
                {
                    logger.Info("Third argument is not an existing sln file");
                    printUsage = true;
                }
                else
                {
                    foreach (var fileName in VisualStudio.Writer.Templates)
                    {
                        if (!System.IO.File.Exists(System.IO.Path.Combine(args[1], fileName)))
                        {
                            logger.Info(string.Format("Second argument is not a directory containing {0}", fileName));
                            printUsage = true;
                        }
                    }
                }
            }
            else
            {
                printUsage = true;
            }

            if (printUsage)
            {
                logger.Info("Create a Visual Studio solution");
                logger.Info("Usage:");
                logger.Info("  ProjectIO.VStoVS.exe <output directory> <template directory> <Visual Studio solution> <configuration|platform>");
                return;
            }

            var filePaths = new List <string> {
                args[2]
            };
            var projects = new Dictionary <string, Core.Project>();
            var filters  = new Dictionary <string, string>();
            var paths    = new Core.Paths();

            VisualStudio.Solution.Extract(logger, paths, filePaths, projects, filters, args[3]);

            var solutionName = System.IO.Path.GetFileNameWithoutExtension(args[2]);
            var solution     = new VisualStudio.Writer(projects, filters);

            solution.Write(solutionName, args[0], args[1]);
        }
Esempio n. 21
0
        public static void MainFunc(string[] args, Core.ILogger logger)
        {
            logger.Info("CMakeParser command line application for creating a Visual Studio solution");
            logger.Info("Copyright (c) 2020 Zebedee Mason");

            bool printUsage = false;

            if (args.Length > 2)
            {
                if (!System.IO.Directory.Exists(args[0]))
                {
                    logger.Info("First argument is not an output directory");
                    printUsage = true;
                }
                else if (!System.IO.Directory.Exists(args[1]))
                {
                    logger.Info("Second argument is not a template directory");
                    printUsage = true;
                }
                else if (System.IO.Path.GetFileName(args[2]) != "CMakeLists.txt" && System.IO.File.Exists(args[2]))
                {
                    logger.Info("Third argument is not an existing CMakeLists.txt");
                    printUsage = true;
                }
                else
                {
                    foreach (var fileName in VisualStudio.Writer.Templates)
                    {
                        if (!System.IO.File.Exists(System.IO.Path.Combine(args[1], fileName)))
                        {
                            logger.Info(string.Format("Second argument is not a directory containing {0}", fileName));
                            printUsage = true;
                        }
                    }
                }
            }
            else
            {
                printUsage = true;
            }

            if (args.Length > 3 && System.IO.Path.GetFileName(args[3]) != "CMakeCache.txt" && System.IO.File.Exists(args[3]))
            {
                logger.Info("Fourth argument is not an existing CMakeCache.txt");
                printUsage = true;
            }

            if (printUsage)
            {
                logger.Info("Create a Visual Studio solution");
                logger.Info("Usage:");
                logger.Info("  ProjectIO.CMakeToVisualStudio.exe <output directory> <template directory> <CMakeLists.txt> [CMakeCache.txt]");
                return;
            }

            var filePaths = new List <string> {
                args[2]
            };

            if (args.Length > 3)
            {
                filePaths.Add(args[3]);
            }

            var projects     = new Dictionary <string, Core.Project>();
            var filters      = new Dictionary <string, string>();
            var paths        = new Core.Paths();
            var solutionName = CMakeParser.Builder.Extract(logger, paths, filePaths, projects, filters);

            var solution = new VisualStudio.Writer(projects, filters);

            solution.Write(solutionName, args[0], args[1]);
        }