void RegisterSystemAssemblies(string prefix, string version, ClrVersion ver) { SystemPackage package = new SystemPackage(); List <string> list = new List <string>(); string dir = Path.Combine(prefix, version); if (!Directory.Exists(dir)) { return; } foreach (string assembly in Directory.GetFiles(dir, "*.dll")) { AddAssembly(assembly, package); list.Add(assembly); } package.Initialize("mono", version, "The Mono runtime", list.ToArray(), ver, false); packages.Add(package); }
private void AddAssembly(string assemblyfile, SystemPackage package) { if (!File.Exists(assemblyfile)) { return; } try { System.Reflection.AssemblyName an = System.Reflection.AssemblyName.GetAssemblyName(assemblyfile); assemblyFullNameToPath[NormalizeAsmName(an.FullName)] = assemblyfile; assemblyPathToPackage[assemblyfile] = package; } catch { } }
void RegisterSystemAssemblies(string prefix, string version, ClrVersion ver) { SystemPackage package = new SystemPackage(); List<string> list = new List<string>(); string dir = Path.Combine(prefix, version); if (!Directory.Exists(dir)) { return; } foreach (string assembly in Directory.GetFiles(dir, "*.dll")) { AddAssembly(assembly, package); list.Add(assembly); } package.Initialize("mono", version, "The Mono runtime", list.ToArray(), ver, false); packages.Add(package); }
private void ParsePCFile(string pcfile) { // Don't register the package twice string pname = Path.GetFileNameWithoutExtension(pcfile); if (packagesHash.ContainsKey(pname)) return; List<string> fullassemblies = null; string version = ""; string desc = ""; SystemPackage package = new SystemPackage(); using (StreamReader reader = new StreamReader(pcfile)) { string line; while ((line = reader.ReadLine()) != null) { string lowerLine = line.ToLower(); if (lowerLine.StartsWith("libs:") && lowerLine.IndexOf(".dll") != -1) { string choppedLine = line.Substring(5).Trim(); if (choppedLine.IndexOf("-lib:") != -1 || choppedLine.IndexOf("/lib:") != -1) { fullassemblies = GetAssembliesWithLibInfo(choppedLine, pcfile); } else { fullassemblies = GetAssembliesWithoutLibInfo(choppedLine, pcfile); } } else if (lowerLine.StartsWith("version:")) { // "version:".Length == 8 version = line.Substring(8).Trim(); } else if (lowerLine.StartsWith("description:")) { // "description:".Length == 12 desc = line.Substring(12).Trim(); } } } if (fullassemblies == null) return; foreach (string assembly in fullassemblies) { AddAssembly(assembly, package); } package.Initialize(pname, version, desc, fullassemblies.ToArray(), ClrVersion.Default, false); packages.Add(package); packagesHash[pname] = package; }
private void AddAssembly(string assemblyfile, SystemPackage package) { if (!File.Exists(assemblyfile)) return; try { System.Reflection.AssemblyName an = System.Reflection.AssemblyName.GetAssemblyName(assemblyfile); assemblyFullNameToPath[NormalizeAsmName(an.FullName)] = assemblyfile; assemblyPathToPackage[assemblyfile] = package; } catch { } }
private void WriteProject(SolutionNode solution, ProjectNode project) { string solutionDir = Path.Combine(solution.FullPath, Path.Combine("autotools", solution.Name)); string projectDir = Path.Combine(solutionDir, project.Name); string projectVersion = project.Version; bool hasAssemblyConfig = false; chkMkDir(projectDir); List <string> compiledFiles = new List <string>(), contentFiles = new List <string>(), embeddedFiles = new List <string>(), binaryLibs = new List <string>(), pkgLibs = new List <string>(), systemLibs = new List <string>(), runtimeLibs = new List <string>(), extraDistFiles = new List <string>(), localCopyTargets = new List <string>(); // If there exists a .config file for this assembly, copy // it to the project folder // TODO: Support copying .config.osx files // TODO: support processing the .config file for native library deps string projectAssemblyName = project.Name; if (project.AssemblyName != null) { projectAssemblyName = project.AssemblyName; } if (File.Exists(Path.Combine(project.FullPath, projectAssemblyName) + ".dll.config")) { hasAssemblyConfig = true; System.IO.File.Copy(Path.Combine(project.FullPath, projectAssemblyName + ".dll.config"), Path.Combine(projectDir, projectAssemblyName + ".dll.config"), true); extraDistFiles.Add(project.AssemblyName + ".dll.config"); } foreach (ConfigurationNode conf in project.Configurations) { if (conf.Options.KeyFile != string.Empty) { // Copy snk file into the project's directory // Use the snk from the project directory directly string source = Path.Combine(project.FullPath, conf.Options.KeyFile); string keyFile = conf.Options.KeyFile; Regex re = new Regex(".*/"); keyFile = re.Replace(keyFile, ""); string dest = Path.Combine(projectDir, keyFile); // Tell the user if there's a problem copying the file try { mkdirDashP(System.IO.Path.GetDirectoryName(dest)); System.IO.File.Copy(source, dest, true); } catch (System.IO.IOException e) { Console.WriteLine(e.Message); } } } // Copy compiled, embedded and content files into the project's directory foreach (string filename in project.Files) { string source = Path.Combine(project.FullPath, filename); string dest = Path.Combine(projectDir, filename); if (filename.Contains("AssemblyInfo.cs")) { // If we've got an AssemblyInfo.cs, pull the version number from it string[] sources = { source }; string[] args = { "" }; Microsoft.CSharp.CSharpCodeProvider cscp = new Microsoft.CSharp.CSharpCodeProvider(); string tempAssemblyFile = Path.Combine(Path.GetTempPath(), project.Name + "-temp.dll"); System.CodeDom.Compiler.CompilerParameters cparam = new System.CodeDom.Compiler.CompilerParameters(args, tempAssemblyFile); System.CodeDom.Compiler.CompilerResults cr = cscp.CompileAssemblyFromFile(cparam, sources); foreach (System.CodeDom.Compiler.CompilerError error in cr.Errors) { Console.WriteLine("Error! '{0}'", error.ErrorText); } try { string projectFullName = cr.CompiledAssembly.FullName; Regex verRegex = new Regex("Version=([\\d\\.]+)"); Match verMatch = verRegex.Match(projectFullName); if (verMatch.Success) { projectVersion = verMatch.Groups[1].Value; } }catch { Console.WriteLine("Couldn't compile AssemblyInfo.cs"); } // Clean up the temp file try { if (File.Exists(tempAssemblyFile)) { File.Delete(tempAssemblyFile); } } catch { Console.WriteLine("Error! '{0}'", e); } } // Tell the user if there's a problem copying the file try { mkdirDashP(System.IO.Path.GetDirectoryName(dest)); System.IO.File.Copy(source, dest, true); } catch (System.IO.IOException e) { Console.WriteLine(e.Message); } switch (project.Files.GetBuildAction(filename)) { case BuildAction.Compile: compiledFiles.Add(filename); break; case BuildAction.Content: contentFiles.Add(filename); extraDistFiles.Add(filename); break; case BuildAction.EmbeddedResource: embeddedFiles.Add(filename); break; } } // Set up references for (int refNum = 0; refNum < project.References.Count; refNum++) { ReferenceNode refr = project.References[refNum]; Assembly refAssembly = Assembly.LoadWithPartialName(refr.Name); /* Determine which pkg-config (.pc) file refers to * this assembly */ SystemPackage package = null; if (packagesHash.ContainsKey(refr.Name)) { package = packagesHash[refr.Name]; } else { string assemblyFullName = string.Empty; if (refAssembly != null) { assemblyFullName = refAssembly.FullName; } string assemblyFileName = string.Empty; if (assemblyFullName != string.Empty && assemblyFullNameToPath.ContainsKey(assemblyFullName) ) { assemblyFileName = assemblyFullNameToPath[assemblyFullName]; } if (assemblyFileName != string.Empty && assemblyPathToPackage.ContainsKey(assemblyFileName) ) { package = assemblyPathToPackage[assemblyFileName]; } } /* If we know the .pc file and it is not "mono" * (already in the path), add a -pkg: argument */ if (package != null && package.Name != "mono" && !pkgLibs.Contains(package.Name) ) { pkgLibs.Add(package.Name); } string fileRef = FindFileReference(refr.Name, (ProjectNode)refr.Parent); if (refr.LocalCopy || solution.ProjectsTable.ContainsKey(refr.Name) || fileRef != null || refr.Path != null ) { /* Attempt to copy the referenced lib to the * project's directory */ string filename = refr.Name + ".dll"; string source = filename; if (refr.Path != null) { source = Path.Combine(refr.Path, source); } source = Path.Combine(project.FullPath, source); string dest = Path.Combine(projectDir, filename); /* Since we depend on this binary dll to build, we * will add a compile- time dependency on the * copied dll, and add the dll to the list of * files distributed with this package */ binaryLibs.Add(refr.Name + ".dll"); extraDistFiles.Add(refr.Name + ".dll"); // TODO: Support copying .config.osx files // TODO: Support for determining native dependencies if (File.Exists(source + ".config")) { System.IO.File.Copy(source + ".config", Path.GetDirectoryName(dest), true); extraDistFiles.Add(refr.Name + ".dll.config"); } try { System.IO.File.Copy(source, dest, true); } catch (System.IO.IOException) { if (solution.ProjectsTable.ContainsKey(refr.Name)) { /* If an assembly is referenced, marked for * local copy, in the list of projects for * this solution, but does not exist, put a * target into the Makefile.am to build the * assembly and copy it to this project's * directory */ ProjectNode sourcePrj = ((solution.ProjectsTable[refr.Name])); string target = String.Format("{0}:\n" + "\t$(MAKE) -C ../{1}\n" + "\tln ../{2}/$@ $@\n", filename, sourcePrj.Name, sourcePrj.Name); localCopyTargets.Add(target); } } } else if (!pkgLibs.Contains(refr.Name)) { // Else, let's assume it's in the GAC or the lib path string assemName = string.Empty; int index = refr.Name.IndexOf(","); if (index > 0) { assemName = refr.Name.Substring(0, index); } else { assemName = refr.Name; } m_Kernel.Log.Write(String.Format( "Warning: Couldn't find an appropriate assembly " + "for reference:\n'{0}'", refr.Name )); systemLibs.Add(assemName); } } const string lineSep = " \\\n\t"; string compiledFilesString = string.Empty; if (compiledFiles.Count > 0) { compiledFilesString = lineSep + string.Join(lineSep, compiledFiles.ToArray()); } string embeddedFilesString = ""; if (embeddedFiles.Count > 0) { embeddedFilesString = lineSep + string.Join(lineSep, embeddedFiles.ToArray()); } string contentFilesString = ""; if (contentFiles.Count > 0) { contentFilesString = lineSep + string.Join(lineSep, contentFiles.ToArray()); } string extraDistFilesString = ""; if (extraDistFiles.Count > 0) { extraDistFilesString = lineSep + string.Join(lineSep, extraDistFiles.ToArray()); } string pkgLibsString = ""; if (pkgLibs.Count > 0) { pkgLibsString = lineSep + string.Join(lineSep, pkgLibs.ToArray()); } string binaryLibsString = ""; if (binaryLibs.Count > 0) { binaryLibsString = lineSep + string.Join(lineSep, binaryLibs.ToArray()); } string systemLibsString = ""; if (systemLibs.Count > 0) { systemLibsString = lineSep + string.Join(lineSep, systemLibs.ToArray()); } string localCopyTargetsString = ""; if (localCopyTargets.Count > 0) { localCopyTargetsString = string.Join("\n", localCopyTargets.ToArray()); } string monoPath = ""; foreach (string runtimeLib in runtimeLibs) { monoPath += ":`pkg-config --variable=libdir " + runtimeLib + "`"; } // Add the project name to the list of transformation // parameters XsltArgumentList argList = new XsltArgumentList(); argList.AddParam("projectName", "", project.Name); argList.AddParam("solutionName", "", solution.Name); argList.AddParam("assemblyName", "", projectAssemblyName); argList.AddParam("compiledFiles", "", compiledFilesString); argList.AddParam("embeddedFiles", "", embeddedFilesString); argList.AddParam("contentFiles", "", contentFilesString); argList.AddParam("extraDistFiles", "", extraDistFilesString); argList.AddParam("pkgLibs", "", pkgLibsString); argList.AddParam("binaryLibs", "", binaryLibsString); argList.AddParam("systemLibs", "", systemLibsString); argList.AddParam("monoPath", "", monoPath); argList.AddParam("localCopyTargets", "", localCopyTargetsString); argList.AddParam("projectVersion", "", projectVersion); argList.AddParam("hasAssemblyConfig", "", hasAssemblyConfig ? "true" : ""); // Transform the templates transformToFile(Path.Combine(projectDir, "configure.ac"), argList, "/Autotools/ProjectConfigureAc"); transformToFile(Path.Combine(projectDir, "Makefile.am"), argList, "/Autotools/ProjectMakefileAm"); transformToFile(Path.Combine(projectDir, "autogen.sh"), argList, "/Autotools/ProjectAutogenSh"); if (project.Type == Core.Nodes.ProjectType.Library) { transformToFile(Path.Combine(projectDir, project.Name + ".pc.in"), argList, "/Autotools/ProjectPcIn"); } if (project.Type == Core.Nodes.ProjectType.Exe || project.Type == Core.Nodes.ProjectType.WinExe) { transformToFile(Path.Combine(projectDir, project.Name.ToLower() + ".in"), argList, "/Autotools/ProjectWrapperScriptIn"); } }
private void ParsePCFile(string pcfile) { // Don't register the package twice string pname = Path.GetFileNameWithoutExtension(pcfile); if (packagesHash.ContainsKey(pname)) { return; } List <string> fullassemblies = null; string version = ""; string desc = ""; SystemPackage package = new SystemPackage(); using (StreamReader reader = new StreamReader(pcfile)) { string line; while ((line = reader.ReadLine()) != null) { string lowerLine = line.ToLower(); if (lowerLine.StartsWith("libs:") && lowerLine.IndexOf(".dll") != -1) { string choppedLine = line.Substring(5).Trim(); if (choppedLine.IndexOf("-lib:") != -1 || choppedLine.IndexOf("/lib:") != -1) { fullassemblies = GetAssembliesWithLibInfo(choppedLine, pcfile); } else { fullassemblies = GetAssembliesWithoutLibInfo(choppedLine, pcfile); } } else if (lowerLine.StartsWith("version:")) { // "version:".Length == 8 version = line.Substring(8).Trim(); } else if (lowerLine.StartsWith("description:")) { // "description:".Length == 12 desc = line.Substring(12).Trim(); } } } if (fullassemblies == null) { return; } foreach (string assembly in fullassemblies) { AddAssembly(assembly, package); } package.Initialize(pname, version, desc, fullassemblies.ToArray(), ClrVersion.Default, false); packages.Add(package); packagesHash[pname] = package; }