/// <summary> /// Attempts to find the signing key for the specific assembly. /// </summary> /// <param name="inputAssemblyPath"></param> /// <param name="rp"></param> /// <param name="logger"></param> /// <returns></returns> private string GetSigningKeyPath(string inputAssemblyPath, ReaderParameters rp, Core.ILogger logger) { if (KeyFilePath != null) { var path = Path.GetFullPath(KeyFilePath); // only use, if the file exists if (File.Exists(path)) { logger.Info("Using signing key provided by msbuild: '{0}'", path); return(path); } } // fallback as per: https://github.com/Fody/Fody/blob/master/FodyIsolated/StrongNameKeyFinder.cs using (var md = ModuleDefinition.ReadModule(inputAssemblyPath, rp)) { var name = nameof(AssemblyKeyFileAttribute); var keyFileAttr = md.Assembly.CustomAttributes.FirstOrDefault(x => x.AttributeType.Name == name); if (keyFileAttr != null) { var suffix = (string)keyFileAttr.ConstructorArguments.First().Value; var path = Path.Combine(IntermediateDirectory, suffix); logger.Info("Using signing key path from attribute: {0}", path); return(path); } } logger.Warning("No signing key found"); return(null); }
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); } }
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"); }
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); }
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"); }
public static List <string> ReadVisualStudioSolution(Core.ILogger logger, string slnfilename) { List <string> projects = new List <string>(); var direc = System.IO.Path.GetDirectoryName(slnfilename); foreach (var line in System.IO.File.ReadAllLines(slnfilename)) { if (line.Length <= 10) { continue; } if (line.Substring(0, 10) != "Project(\"{") { continue; } var bits = line.Split(','); var filename = bits[1].Trim().Substring(1); filename = filename.Substring(0, filename.Length - 1); var ext = System.IO.Path.GetExtension(filename); if (ext == ".csproj" || ext == ".shproj" || ext == ".vbproj" || ext == ".vcxproj") { projects.Add(System.IO.Path.GetFullPath(System.IO.Path.Combine(direc, filename))); logger.Info("Appended for reading \"{0}\"", filename); } } return(projects); }
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); }
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); }
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); }
public void Add(string command, string name, CMakeParser.State state, IEnumerable <string> filePaths) { foreach (var filePath in filePaths) { if (System.IO.File.Exists(filePath)) { _logger.Info(string.Format("[{0}] Adding {1} to {2}", state.Variables["${CMAKE_CURRENT_SOURCE_DIR}"], filePath, name)); } else { _logger.Warn(string.Format("[{0}] Not adding {1} to {2}", state.Variables["${CMAKE_CURRENT_SOURCE_DIR}"], filePath, name)); } } }
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]); }
public void Info(string message) { _logger.Info(string.Format("[{0}] {1}", Variables["${CMAKE_CURRENT_SOURCE_DIR}"], message)); }
public void AddFile(string filePath, string filter) { _logger.Info(string.Format("Setting {0} to filter {1}", filePath, filter)); }
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]); }